import org.opendaylight.controller.md.sal.common.api.data.TransactionChain;
import org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener;
import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
-import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
-import org.opendaylight.openflowplugin.impl.util.DeviceStateUtil;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
import org.opendaylight.yangtools.concepts.Registration;
* and submitTransaction method (wrapped {@link WriteTransaction#submit()})
*
* @author <a href="mailto:vdemcak@cisco.com">Vaclav Demcak</a>
- * <p/>
+ * </p>
* Created: Apr 2, 2015
*/
class TransactionChainManager implements TransactionChainListener, AutoCloseable {
private WriteTransaction wTx;
private BindingTransactionChain txChainFactory;
private boolean submitIsEnabled;
+
+ public TransactionChainManagerStatus getTransactionChainManagerStatus() {
+ return transactionChainManagerStatus;
+ }
+
private TransactionChainManagerStatus transactionChainManagerStatus;
private ReadyForNewTransactionChainHandler readyForNewTransactionChainHandler;
private final KeyedInstanceIdentifier<Node, NodeKey> nodeII;
- private final ConnectionContext connectionContext;
private Registration managerRegistration;
TransactionChainManager(@Nonnull final DataBroker dataBroker,
- @Nonnull final ConnectionContext connectionContext,
+ @Nonnull final KeyedInstanceIdentifier<Node, NodeKey> nodeII,
@Nonnull final Registration managerRegistration) {
this.dataBroker = Preconditions.checkNotNull(dataBroker);
- this.nodeII = Preconditions.checkNotNull(DeviceStateUtil.createNodeInstanceIdentifier(connectionContext.getNodeId()));
- this.connectionContext = Preconditions.checkNotNull(connectionContext);
+ this.nodeII = Preconditions.checkNotNull(nodeII);
this.managerRegistration = Preconditions.checkNotNull(managerRegistration);
+ this.transactionChainManagerStatus = TransactionChainManagerStatus.WORKING;
createTxChain(dataBroker);
LOG.debug("created txChainManager");
}
private void createTxChain(final DataBroker dataBroker) {
txChainFactory = dataBroker.createTransactionChain(TransactionChainManager.this);
- this.transactionChainManagerStatus = TransactionChainManagerStatus.WORKING;
}
void initialSubmitWriteTransaction() {
submitWriteTransaction();
}
- public boolean attemptToRegisterHandler(final ReadyForNewTransactionChainHandler readyForNewTransactionChainHandler) {
- if (null == this.readyForNewTransactionChainHandler) {
- synchronized (this) {
- Preconditions.checkState(null != this.managerRegistration);
- this.readyForNewTransactionChainHandler = readyForNewTransactionChainHandler;
+ public synchronized boolean attemptToRegisterHandler(final ReadyForNewTransactionChainHandler readyForNewTransactionChainHandler) {
+ if (TransactionChainManagerStatus.SHUTTING_DOWN.equals(this.transactionChainManagerStatus)
+ && null == this.readyForNewTransactionChainHandler) {
+ this.readyForNewTransactionChainHandler = readyForNewTransactionChainHandler;
+ if (managerRegistration == null) {
+ this.readyForNewTransactionChainHandler.onReadyForNewTransactionChain();
}
return true;
} else {
LOG.trace("transaction not committed - submit block issued");
return false;
}
-
- if (wTx == null) {
- LOG.trace("nothing to commit - submit returns true");
- return true;
- }
synchronized (txLock) {
if (wTx == null) {
LOG.trace("nothing to commit - submit returns true");
return true;
}
- wTx.submit();
+ final CheckedFuture<Void, TransactionCommitFailedException> submitFuture = wTx.submit();
+ Futures.addCallback(submitFuture, new FutureCallback<Void>() {
+ @Override
+ public void onSuccess(Void result) {
+ //no action required
+ }
+
+ @Override
+ public void onFailure(Throwable t) {
+ if (t instanceof TransactionCommitFailedException) {
+ LOG.error("Transaction commit failed. {}", t);
+ } else {
+ LOG.error("Exception during transaction submitting. {}", t);
+ }
+ }
+ });
wTx = null;
}
return true;
final WriteTransaction writeTx = getTransactionSafely();
this.transactionChainManagerStatus = TransactionChainManagerStatus.SHUTTING_DOWN;
writeTx.delete(LogicalDatastoreType.OPERATIONAL, nodeII);
+ LOG.debug("Delete node {} from operational DS put to write transaction.", nodeII);
CheckedFuture<Void, TransactionCommitFailedException> submitsFuture = writeTx.submit();
+ LOG.debug("Delete node {} from operational DS write transaction submitted.", nodeII);
Futures.addCallback(submitsFuture, new FutureCallback<Void>() {
@Override
public void onSuccess(final Void aVoid) {
+ LOG.debug("Removing node {} from operational DS successful .", nodeII);
notifyReadyForNewTransactionChainAndCloseFactory();
}
private void notifyReadyForNewTransactionChainAndCloseFactory() {
synchronized (this) {
- if (null != readyForNewTransactionChainHandler) {
- readyForNewTransactionChainHandler.onReadyForNewTransactionChain(connectionContext);
- }
try {
+ LOG.debug("Closing registration in manager.");
managerRegistration.close();
} catch (Exception e) {
LOG.warn("Failed to close transaction chain manager's registration.", e);
}
managerRegistration = null;
+ if (null != readyForNewTransactionChainHandler) {
+ readyForNewTransactionChainHandler.onReadyForNewTransactionChain();
+ }
}
txChainFactory.close();
+ LOG.debug("Transaction chain factory closed.");
}
- private enum TransactionChainManagerStatus {
+ public enum TransactionChainManagerStatus {
WORKING, SHUTTING_DOWN;
}