X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=netconf%2Fsal-netconf-connector%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fnetconf%2Fsal%2Fconnect%2Fnetconf%2Fsal%2Ftx%2FWriteCandidateTx.java;h=23803f575129cebf226c0f98f891ef03d695574e;hb=74f902f0d61c2077a50c57f40c5f7b040fdddc29;hp=e2cedbc2a47f3737c86f3e1c3188e592bd2e8678;hpb=82138f659ae26fc2af5dc2130ab9f640b388aac7;p=netconf.git diff --git a/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/sal/tx/WriteCandidateTx.java b/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/sal/tx/WriteCandidateTx.java index e2cedbc2a4..23803f5751 100644 --- a/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/sal/tx/WriteCandidateTx.java +++ b/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/sal/tx/WriteCandidateTx.java @@ -15,8 +15,8 @@ import com.google.common.util.concurrent.CheckedFuture; import com.google.common.util.concurrent.FutureCallback; import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ListenableFuture; +import com.google.common.util.concurrent.MoreExecutors; import javax.annotation.Nullable; -import org.opendaylight.controller.md.sal.common.api.TransactionStatus; import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException; import org.opendaylight.controller.md.sal.dom.api.DOMRpcResult; import org.opendaylight.netconf.sal.connect.netconf.util.NetconfBaseOps; @@ -31,7 +31,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * Tx implementation for netconf devices that support only candidate datastore and no writable running + * Tx implementation for netconf devices that support only candidate datastore and no writable running. * The sequence goes as: *
    *
  1. Lock candidate datastore on tx construction @@ -44,7 +44,8 @@ import org.slf4j.LoggerFactory; *
  2. *
  3. Edit-config in candidate N times * *
  4. *
  5. Commit and Unlock candidate datastore async
  6. @@ -78,8 +79,8 @@ public class WriteCandidateTx extends AbstractWriteTx { } @Override - public void onFailure(final Throwable t) { - LOG.warn("Lock candidate operation failed. {}", t); + public void onFailure(final Throwable throwable) { + LOG.warn("Lock candidate operation failed. {}", throwable); discardChanges(); } }; @@ -94,47 +95,43 @@ public class WriteCandidateTx extends AbstractWriteTx { @Override public synchronized CheckedFuture submit() { - final ListenableFuture commitFutureAsVoid = Futures.transform(commit(), new Function, Void>() { - @Override - public Void apply(final RpcResult input) { - Preconditions.checkArgument(input.isSuccessful() && input.getErrors().isEmpty(), "Submit failed with errors: %s", input.getErrors()); + final ListenableFuture commitFutureAsVoid = Futures.transform(commitConfiguration(), + (Function, Void>) input -> { + Preconditions.checkArgument(input.isSuccessful() && input.getErrors().isEmpty(), + "Submit failed with errors: %s", input.getErrors()); return null; - } - }); + }, MoreExecutors.directExecutor()); - return Futures.makeChecked(commitFutureAsVoid, new Function() { - @Override - public TransactionCommitFailedException apply(final Exception input) { - return new TransactionCommitFailedException("Submit of transaction " + getIdentifier() + " failed", input); - } - }); + return Futures.makeChecked(commitFutureAsVoid, input -> new TransactionCommitFailedException( + "Submit of transaction " + getIdentifier() + " failed", input)); } /** - * This has to be non blocking since it is called from a callback on commit and its netty threadpool that is really sensitive to blocking calls + * This has to be non blocking since it is called from a callback on commit + * and its netty threadpool that is really sensitive to blocking calls. */ private void discardChanges() { netOps.discardChanges(new NetconfRpcFutureCallback("Discarding candidate", id)); } @Override - public synchronized ListenableFuture> performCommit() { + public synchronized ListenableFuture> performCommit() { resultsFutures.add(netOps.commit(new NetconfRpcFutureCallback("Commit", id))); - final ListenableFuture> txResult = resultsToTxStatus(); + final ListenableFuture> txResult = resultsToTxStatus(); - Futures.addCallback(txResult, new FutureCallback>() { + Futures.addCallback(txResult, new FutureCallback>() { @Override - public void onSuccess(@Nullable final RpcResult result) { + public void onSuccess(@Nullable final RpcResult result) { cleanupOnSuccess(); } @Override - public void onFailure(final Throwable t) { + public void onFailure(final Throwable throwable) { // TODO If lock is cause of this failure cleanup will issue warning log // cleanup is trying to do unlock, but this will fail cleanup(); } - }); + }, MoreExecutors.directExecutor()); return txResult; } @@ -161,7 +158,8 @@ public class WriteCandidateTx extends AbstractWriteTx { } /** - * This has to be non blocking since it is called from a callback on commit and its netty threadpool that is really sensitive to blocking calls + * This has to be non blocking since it is called from a callback on commit + * and its netty threadpool that is really sensitive to blocking calls. */ private void unlock() { netOps.unlockCandidate(new NetconfRpcFutureCallback("Unlock candidate", id));