BUG-5280: add ExplicitAsk utility class
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / databroker / actors / dds / DistributedDataStoreClientActor.java
index b0c518d..de2c195 100644 (file)
@@ -9,7 +9,6 @@ package org.opendaylight.controller.cluster.databroker.actors.dds;
 
 import akka.actor.ActorRef;
 import akka.actor.Props;
-import akka.pattern.ExplicitAskSupport;
 import akka.util.Timeout;
 import com.google.common.base.Preconditions;
 import com.google.common.base.Throwables;
@@ -20,11 +19,11 @@ import org.opendaylight.controller.cluster.access.client.ClientActorContext;
 import org.opendaylight.controller.cluster.access.concepts.FrontendIdentifier;
 import org.opendaylight.controller.cluster.access.concepts.FrontendType;
 import org.opendaylight.controller.cluster.access.concepts.MemberName;
+import org.opendaylight.controller.cluster.common.actor.ExplicitAsk;
 import org.opendaylight.controller.cluster.datastore.utils.ActorContext;
 import scala.Function1;
 import scala.concurrent.Await;
 import scala.concurrent.duration.Duration;
-import scala.runtime.AbstractFunction1;
 
 /**
  * A {@link AbstractClientActor} which acts as the point of contact for DistributedDataStore.
@@ -32,16 +31,7 @@ import scala.runtime.AbstractFunction1;
  * @author Robert Varga
  */
 public final class DistributedDataStoreClientActor extends AbstractClientActor {
-    // Unfortunately Akka's explicit ask pattern does not work with its Java API, as it fails to invoke passed message.
-    // In order to make this work for now, we tap directly into ExplicitAskSupport and use a Scala function instead
-    // of akka.japi.Function.
-    private static final ExplicitAskSupport ASK_SUPPORT = akka.pattern.extended.package$.MODULE$;
-    private static final Function1<ActorRef, Object> GET_CLIENT_FACTORY = new AbstractFunction1<ActorRef, Object>() {
-        @Override
-        public Object apply(final ActorRef askSender) {
-            return new GetClientRequest(askSender);
-        }
-    };
+    private static final Function1<ActorRef, ?> GET_CLIENT_FACTORY = ExplicitAsk.toScala(t -> new GetClientRequest(t));
 
     private final ActorContext actorContext;
 
@@ -65,7 +55,7 @@ public final class DistributedDataStoreClientActor extends AbstractClientActor {
     public static DistributedDataStoreClient getDistributedDataStoreClient(final @Nonnull ActorRef actor,
             final long timeout, final TimeUnit unit) {
         try {
-            return (DistributedDataStoreClient) Await.result(ASK_SUPPORT.ask(actor, GET_CLIENT_FACTORY,
+            return (DistributedDataStoreClient) Await.result(ExplicitAsk.ask(actor, GET_CLIENT_FACTORY,
                 Timeout.apply(timeout, unit)), Duration.Inf());
         } catch (Exception e) {
             throw Throwables.propagate(e);