![JAR search and dependency download from the Maven repository](/logo.png)
org.csc.phynixx.connection.PhynixxRecovery Maven / Gradle / Ivy
The newest version!
package org.csc.phynixx.connection;
/*
* #%L
* phynixx-connection
* %%
* Copyright (C) 2014 Christoph Schmidt-Casdorff
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
import org.csc.phynixx.common.cast.ImplementorUtils;
import org.csc.phynixx.connection.loggersystem.IPhynixxLoggerSystemStrategy;
import org.csc.phynixx.loggersystem.logrecord.IXADataRecorder;
import java.util.List;
/**
* Created by Christoph Schmidt-Casdorff on 26.02.14.
*/
public class PhynixxRecovery implements IPhynixxRecovery {
private final PhynixxManagedConnectionFactory managedConnectionFactory;
private IPhynixxLoggerSystemStrategy loggerSystemStrategy = null;
public PhynixxRecovery(IPhynixxConnectionFactory connectionFactory) {
managedConnectionFactory = new PhynixxManagedConnectionFactory(connectionFactory);
}
public IPhynixxLoggerSystemStrategy getLoggerSystemStrategy() {
return loggerSystemStrategy;
}
public void setLoggerSystemStrategy(IPhynixxLoggerSystemStrategy loggerSystemStrategy) {
this.loggerSystemStrategy = loggerSystemStrategy;
// Es werden alle Logger geschlossen
this.loggerSystemStrategy.close();
}
private IPhynixxManagedConnection getManagedConnection() {
return this.managedConnectionFactory.getManagedConnection();
}
public List> getConnectionProxyDecorators() {
return this.managedConnectionFactory.getManagedConnectionDecorators();
}
public void addConnectionProxyDecorator(
IPhynixxConnectionProxyDecorator connectionProxyDecorator) {
this.managedConnectionFactory.addManagedConnectionDecorator(connectionProxyDecorator);
}
@Override
public void recover(IPhynixxRecovery.IRecoveredManagedConnection recoveredManagedConnectionCallback) {
if (this.loggerSystemStrategy == null) {
throw new IllegalStateException("LoggerSystem must be reset to recover from this System");
}
this.loggerSystemStrategy.close();
try {
// get all recoverable transaction data
List messageLoggers = this.loggerSystemStrategy.readIncompleteTransactions();
IPhynixxManagedConnection con = null;
for (int i = 0; i < messageLoggers.size(); i++) {
try {
IXADataRecorder msgLogger = messageLoggers.get(i);
con = this.getManagedConnection();
if (!ImplementorUtils.isImplementationOf(con, IXADataRecorderAware.class)) {
throw new IllegalStateException("Connection does not support " + IXADataRecorderAware.class + " and can't be recovered");
} else {
// Falls Connection zugeordneten DataLogger hat, so wird dieser freigegeben
IXADataRecorderAware xaDataRecorderAware = ImplementorUtils.cast(con, IXADataRecorderAware.class);
IXADataRecorder dataRecorder = xaDataRecorderAware.getXADataRecorder();
if (dataRecorder != null) {
dataRecorder.destroy();
}
xaDataRecorderAware.setXADataRecorder(msgLogger);
}
con.recover();
if (recoveredManagedConnectionCallback != null) {
recoveredManagedConnectionCallback.managedConnectionRecovered(con.toConnection());
}
} finally {
if (con != null) {
con.close();
}
}
}
} finally {
if (this.loggerSystemStrategy != null) {
this.loggerSystemStrategy.close();
}
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy