Bump upstreams
[netconf.git] / apps / netconf-topology-singleton / src / main / java / org / opendaylight / netconf / topology / singleton / impl / tx / ActorProxyTransactionFacade.java
index d393a7121e0df5b1ca2d96d957f9f23e4e3e331f..50660b443fc0ec15b2bdedd2ce7d9fc66db843fd 100644 (file)
@@ -16,6 +16,7 @@ import com.google.common.util.concurrent.FluentFuture;
 import com.google.common.util.concurrent.SettableFuture;
 import java.util.Objects;
 import java.util.Optional;
+import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.mdsal.common.api.CommitInfo;
 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
 import org.opendaylight.mdsal.common.api.ReadFailedException;
@@ -36,7 +37,6 @@ import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import scala.concurrent.ExecutionContext;
-import scala.concurrent.Future;
 
 /**
  * ProxyTransactionFacade implementation that interfaces with an actor.
@@ -46,6 +46,8 @@ import scala.concurrent.Future;
 class ActorProxyTransactionFacade implements ProxyTransactionFacade {
     private static final Logger LOG = LoggerFactory.getLogger(ActorProxyTransactionFacade.class);
 
+    private final SettableFuture<CommitInfo> settableFuture = SettableFuture.create();
+    private final @NonNull FluentFuture<CommitInfo> fluentFuture = FluentFuture.from(settableFuture);
     private final ActorRef masterTxActor;
     private final RemoteDeviceId id;
     private final ExecutionContext executionContext;
@@ -64,13 +66,16 @@ class ActorProxyTransactionFacade implements ProxyTransactionFacade {
         return id;
     }
 
+    @Override
+    public FluentFuture<?> completionFuture() {
+        return fluentFuture;
+    }
+
     @Override
     public boolean cancel() {
         LOG.debug("{}: Cancel via actor {}", id, masterTxActor);
 
-        final Future<Object> future = Patterns.ask(masterTxActor, new CancelRequest(), askTimeout);
-
-        future.onComplete(new OnComplete<>() {
+        Patterns.ask(masterTxActor, new CancelRequest(), askTimeout).onComplete(new OnComplete<>() {
             @Override
             public void onComplete(final Throwable failure, final Object response) {
                 if (failure != null) {
@@ -90,10 +95,8 @@ class ActorProxyTransactionFacade implements ProxyTransactionFacade {
             final YangInstanceIdentifier path) {
         LOG.debug("{}: Read {} {} via actor {}", id, store, path, masterTxActor);
 
-        final Future<Object> future = Patterns.ask(masterTxActor, new ReadRequest(store, path), askTimeout);
-
-        final SettableFuture<Optional<NormalizedNode>> settableFuture = SettableFuture.create();
-        future.onComplete(new OnComplete<>() {
+        final var future = SettableFuture.<Optional<NormalizedNode>>create();
+        Patterns.ask(masterTxActor, new ReadRequest(store, path), askTimeout).onComplete(new OnComplete<>() {
             @Override
             public void onComplete(final Throwable failure, final Object response) {
                 if (failure != null) {
@@ -101,9 +104,9 @@ class ActorProxyTransactionFacade implements ProxyTransactionFacade {
 
                     final Throwable processedFailure = processFailure(failure);
                     if (processedFailure instanceof ReadFailedException) {
-                        settableFuture.setException(processedFailure);
+                        future.setException(processedFailure);
                     } else {
-                        settableFuture.setException(new ReadFailedException("Read of store " + store + " path " + path
+                        future.setException(new ReadFailedException("Read of store " + store + " path " + path
                             + " failed", processedFailure));
                     }
                     return;
@@ -112,27 +115,26 @@ class ActorProxyTransactionFacade implements ProxyTransactionFacade {
                 LOG.debug("{}: Read {} {} succeeded: {}", id, store, path, response);
 
                 if (response instanceof EmptyReadResponse) {
-                    settableFuture.set(Optional.empty());
+                    future.set(Optional.empty());
                     return;
                 }
 
                 if (response instanceof NormalizedNodeMessage data) {
-                    settableFuture.set(Optional.of(data.getNode()));
+                    future.set(Optional.of(data.getNode()));
                 }
             }
         }, executionContext);
 
-        return FluentFuture.from(settableFuture);
+        return FluentFuture.from(future);
     }
 
     @Override
     public FluentFuture<Boolean> exists(final LogicalDatastoreType store, final YangInstanceIdentifier path) {
         LOG.debug("{}: Exists {} {} via actor {}", id, store, path, masterTxActor);
 
-        final Future<Object> future = Patterns.ask(masterTxActor, new ExistsRequest(store, path), askTimeout);
+        final var future = SettableFuture.<Boolean>create();
 
-        final SettableFuture<Boolean> settableFuture = SettableFuture.create();
-        future.onComplete(new OnComplete<>() {
+        Patterns.ask(masterTxActor, new ExistsRequest(store, path), askTimeout).onComplete(new OnComplete<>() {
             @Override
             public void onComplete(final Throwable failure, final Object response) {
                 if (failure != null) {
@@ -140,9 +142,9 @@ class ActorProxyTransactionFacade implements ProxyTransactionFacade {
 
                     final Throwable processedFailure = processFailure(failure);
                     if (processedFailure instanceof ReadFailedException) {
-                        settableFuture.setException(processedFailure);
+                        future.setException(processedFailure);
                     } else {
-                        settableFuture.setException(new ReadFailedException("Exists of store " + store + " path " + path
+                        future.setException(new ReadFailedException("Exists of store " + store + " path " + path
                             + " failed", processedFailure));
                     }
                     return;
@@ -150,11 +152,11 @@ class ActorProxyTransactionFacade implements ProxyTransactionFacade {
 
                 LOG.debug("{}: Exists {} {} succeeded: {}", id, store, path, response);
 
-                settableFuture.set((Boolean) response);
+                future.set((Boolean) response);
             }
         }, executionContext);
 
-        return FluentFuture.from(settableFuture);
+        return FluentFuture.from(future);
     }
 
     @Override
@@ -179,10 +181,7 @@ class ActorProxyTransactionFacade implements ProxyTransactionFacade {
     public FluentFuture<? extends CommitInfo> commit() {
         LOG.debug("{}: Commit via actor {}", id, masterTxActor);
 
-        final Future<Object> future = Patterns.ask(masterTxActor, new SubmitRequest(), askTimeout);
-
-        final SettableFuture<CommitInfo> settableFuture = SettableFuture.create();
-        future.onComplete(new OnComplete<>() {
+        Patterns.ask(masterTxActor, new SubmitRequest(), askTimeout).onComplete(new OnComplete<>() {
             @Override
             public void onComplete(final Throwable failure, final Object response) {
                 if (failure != null) {