+ void initialSubmitWriteTransaction() {
+ enableSubmit();
+ submitWriteTransaction();
+ }
+
+ /**
+ * Method change status for TxChainManager to {@link TransactionChainManagerStatus#WORKING} and it has to make
+ * registration for this class instance as {@link TransactionChainListener} to provide possibility a make DS
+ * transactions. Call this method for MASTER role only.
+ */
+ public void activateTransactionManager() {
+ LOG.trace("activateTransactionManager for node {} transaction submit is set to {}", deviceState.getNodeId(), this.submitIsEnabled);
+ synchronized (txLock) {
+ if (TransactionChainManagerStatus.SLEEPING.equals(transactionChainManagerStatus)) {
+ LOG.debug("Transaction Factory create {}", deviceState.getNodeId());
+ Preconditions.checkState(txChainFactory == null, "TxChainFactory survive last close.");
+ Preconditions.checkState(wTx == null, "We have some unexpected WriteTransaction.");
+ this.transactionChainManagerStatus = TransactionChainManagerStatus.WORKING;
+ createTxChain();
+ } else {
+ LOG.debug("Transaction is active {}", deviceState.getNodeId());
+ }
+ }
+ }
+
+ /**
+ * Method change status for TxChainManger to {@link TransactionChainManagerStatus#SLEEPING} and it unregisters
+ * this class instance as {@link TransactionChainListener} so it broke a possibility to write something to DS.
+ * Call this method for SLAVE only.
+ * @return Future
+ */
+ public ListenableFuture<Void> deactivateTransactionManager() {
+ final ListenableFuture<Void> future;
+ synchronized (txLock) {
+ if (TransactionChainManagerStatus.WORKING.equals(transactionChainManagerStatus)) {
+ LOG.debug("Submitting all transactions if we were in status WORKING for Node", deviceState.getNodeId());
+ transactionChainManagerStatus = TransactionChainManagerStatus.SLEEPING;
+ future = txChainShuttingDown();
+ Preconditions.checkState(wTx == null, "We have some unexpected WriteTransaction.");
+ LOG.debug("Transaction Factory delete for Node {}", deviceState.getNodeId());
+ Futures.addCallback(future, new FutureCallback<Void>() {
+ @Override
+ public void onSuccess(final Void result) {
+ txChainFactory.close();
+ txChainFactory = null;
+ }
+
+ @Override
+ public void onFailure(final Throwable t) {
+ txChainFactory.close();
+ txChainFactory = null;
+ }
+ });
+ } else {
+ // TODO : ignoring redundant deactivate invocation
+ future = Futures.immediateCheckedFuture(null);
+ }