Update Patterns.ask() interactions 76/103676/2
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 14 Dec 2022 22:34:19 +0000 (23:34 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 14 Dec 2022 22:45:20 +0000 (23:45 +0100)
User a direct OnComplete callback instead of declaring a local variable.
Makes for cleaner code.

Change-Id: I0b147a660d4e54c68eec3f7471251bfe40b989ab
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/NetconfNodeManager.java
netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/ProxyYangTextSourceProvider.java

index d6ee3c53bbce1ac7a95e712244ab779e7d646c6e..f1836b3cb77fc941667d5b42e27cecc0fb8ac250 100644 (file)
@@ -40,7 +40,6 @@ import org.opendaylight.yangtools.concepts.ListenerRegistration;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import scala.concurrent.Future;
 
 /**
  * Managing and reacting on data tree changes in specific netconf node when master writes status to the operational
@@ -176,8 +175,7 @@ class NetconfNodeManager
     @Holding("this")
     private void sendAskForMasterMountPointWithRetries(final AskForMasterMountPoint askForMasterMountPoint,
             final ActorSelection masterActor, final int tries, final int updateCount) {
-        final Future<Object> future = Patterns.ask(masterActor, askForMasterMountPoint, actorResponseWaitTime);
-        future.onComplete(new OnComplete<Object>() {
+        Patterns.ask(masterActor, askForMasterMountPoint, actorResponseWaitTime).onComplete(new OnComplete<>() {
             @Override
             public void onComplete(final Throwable failure, final Object response) {
                 synchronized (this) {
@@ -191,10 +189,10 @@ class NetconfNodeManager
                             LOG.warn("{}: Failed to send message to {} - retrying...", id, masterActor, failure);
                         }
                         sendAskForMasterMountPointWithRetries(askForMasterMountPoint, masterActor, tries + 1,
-                                updateCount);
+                            updateCount);
                     } else if (failure != null) {
                         LOG.error("{}: Failed to send message {} to {}. Slave mount point could not be created",
-                                id, askForMasterMountPoint, masterActor, failure);
+                            id, askForMasterMountPoint, masterActor, failure);
                     } else {
                         LOG.debug("{}: {} message to {} succeeded", id, askForMasterMountPoint, masterActor);
                     }
@@ -210,8 +208,7 @@ class NetconfNodeManager
                     mountPointService));
             LOG.debug("{}: Slave actor created with name {}", id, slaveActorRef);
         } else {
-            slaveActorRef
-                    .tell(new RefreshSlaveActor(setup, id, actorResponseWaitTime), ActorRef.noSender());
+            slaveActorRef.tell(new RefreshSlaveActor(setup, id, actorResponseWaitTime), ActorRef.noSender());
         }
     }
 
index c0d1aa4545ebe64443e8b990a22c5dfe4a59f4a9..4bb45457a84d9843663f3a561361c3ee337af16a 100644 (file)
@@ -12,7 +12,6 @@ import akka.dispatch.Futures;
 import akka.dispatch.OnComplete;
 import akka.pattern.Patterns;
 import akka.util.Timeout;
-import java.util.Collections;
 import java.util.Set;
 import org.opendaylight.controller.cluster.schema.provider.RemoteYangTextSourceProvider;
 import org.opendaylight.controller.cluster.schema.provider.impl.YangTextSchemaSourceSerializationProxy;
@@ -20,7 +19,6 @@ import org.opendaylight.netconf.topology.singleton.messages.YangTextSchemaSource
 import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
 import scala.concurrent.ExecutionContext;
 import scala.concurrent.Future;
-import scala.concurrent.impl.Promise;
 
 public class ProxyYangTextSourceProvider implements RemoteYangTextSourceProvider {
 
@@ -38,30 +36,24 @@ public class ProxyYangTextSourceProvider implements RemoteYangTextSourceProvider
     @Override
     public Future<Set<SourceIdentifier>> getProvidedSources() {
         // NOOP
-        return Futures.successful(Collections.emptySet());
+        return Futures.successful(Set.of());
     }
 
     @Override
     public Future<YangTextSchemaSourceSerializationProxy> getYangTextSchemaSource(
             final SourceIdentifier sourceIdentifier) {
-
-        final Future<Object> scalaFuture = Patterns.ask(masterRef,
-                new YangTextSchemaSourceRequest(sourceIdentifier), actorResponseWaitTime);
-
-        final Promise.DefaultPromise<YangTextSchemaSourceSerializationProxy> promise = new Promise.DefaultPromise<>();
-
-        scalaFuture.onComplete(new OnComplete<Object>() {
-            @Override
-            public void onComplete(final Throwable failure, final Object success) {
-                if (failure != null) {
-                    promise.failure(failure);
-                    return;
+        final var promise = Futures.<YangTextSchemaSourceSerializationProxy>promise();
+        Patterns.ask(masterRef, new YangTextSchemaSourceRequest(sourceIdentifier), actorResponseWaitTime).onComplete(
+            new OnComplete<>() {
+                @Override
+                public void onComplete(final Throwable failure, final Object success) {
+                    if (failure == null) {
+                        promise.success((YangTextSchemaSourceSerializationProxy) success);
+                    } else {
+                        promise.failure(failure);
+                    }
                 }
-
-                promise.success((YangTextSchemaSourceSerializationProxy) success);
-            }
-        }, executionContext);
-
+            }, executionContext);
         return promise.future();
     }
 }