Bug 6581 - Make timeout for ask configurable
[netconf.git] / netconf / netconf-topology-singleton / src / main / java / org / opendaylight / netconf / topology / singleton / impl / tx / NetconfProxyDOMTransaction.java
index 9b2adf2efa102bbf884c388ce95f82b0a7865e77..aa05f5415d00288bb55630e13f984e7727891be9 100644 (file)
@@ -12,13 +12,13 @@ import akka.actor.ActorRef;
 import akka.actor.ActorSystem;
 import akka.dispatch.OnComplete;
 import akka.pattern.Patterns;
+import akka.util.Timeout;
 import com.google.common.base.Optional;
 import com.google.common.base.Throwables;
 import org.opendaylight.controller.config.util.xml.DocumentedException;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
 import org.opendaylight.netconf.topology.singleton.api.NetconfDOMTransaction;
-import org.opendaylight.netconf.topology.singleton.impl.utils.NetconfTopologyUtils;
 import org.opendaylight.netconf.topology.singleton.messages.NormalizedNodeMessage;
 import org.opendaylight.netconf.topology.singleton.messages.transactions.CancelRequest;
 import org.opendaylight.netconf.topology.singleton.messages.transactions.DeleteRequest;
@@ -45,13 +45,16 @@ public class NetconfProxyDOMTransaction implements NetconfDOMTransaction {
     private final RemoteDeviceId id;
     private final ActorSystem actorSystem;
     private final ActorRef masterContextRef;
+    private final Timeout actorResponseWaitTime;
 
     public NetconfProxyDOMTransaction(final RemoteDeviceId id,
                                       final ActorSystem actorSystem,
-                                      final ActorRef masterContextRef) {
+                                      final ActorRef masterContextRef,
+                                      final Timeout actorResponseWaitTime) {
         this.id = id;
         this.actorSystem = actorSystem;
         this.masterContextRef = masterContextRef;
+        this.actorResponseWaitTime = actorResponseWaitTime;
     }
 
     @Override
@@ -61,10 +64,10 @@ public class NetconfProxyDOMTransaction implements NetconfDOMTransaction {
         // node.
         LOG.debug("{}: Requesting leader {} to open new transaction", id, masterContextRef);
         final Future<Object> openTxFuture =
-                Patterns.ask(masterContextRef, new OpenTransaction(), NetconfTopologyUtils.TIMEOUT);
+                Patterns.ask(masterContextRef, new OpenTransaction(), actorResponseWaitTime);
         try {
             // we have to wait here so we can see if tx can be opened
-            Await.result(openTxFuture, NetconfTopologyUtils.TIMEOUT.duration());
+            Await.result(openTxFuture, actorResponseWaitTime.duration());
             LOG.debug("{}: New transaction opened successfully", id);
         } catch (final Exception e) {
             LOG.error("{}: Failed to open new transaction", id, e);
@@ -77,7 +80,7 @@ public class NetconfProxyDOMTransaction implements NetconfDOMTransaction {
                                                         final YangInstanceIdentifier path) {
 
         final Future<Object> readScalaFuture =
-                Patterns.ask(masterContextRef, new ReadRequest(store, path), NetconfTopologyUtils.TIMEOUT);
+                Patterns.ask(masterContextRef, new ReadRequest(store, path), actorResponseWaitTime);
 
         LOG.trace("{}: Read {} via NETCONF: {}", id, store, path);
 
@@ -111,7 +114,7 @@ public class NetconfProxyDOMTransaction implements NetconfDOMTransaction {
     @Override
     public Future<Boolean> exists(final LogicalDatastoreType store, final YangInstanceIdentifier path) {
         final Future<Object> existsScalaFuture =
-                Patterns.ask(masterContextRef, new ExistsRequest(store, path), NetconfTopologyUtils.TIMEOUT);
+                Patterns.ask(masterContextRef, new ExistsRequest(store, path), actorResponseWaitTime);
 
         LOG.trace("{}: Exists {} via NETCONF: {}", id, store, path);
 
@@ -161,13 +164,13 @@ public class NetconfProxyDOMTransaction implements NetconfDOMTransaction {
     @Override
     public boolean cancel() {
         final Future<Object> cancelScalaFuture =
-                Patterns.ask(masterContextRef, new CancelRequest(), NetconfTopologyUtils.TIMEOUT);
+                Patterns.ask(masterContextRef, new CancelRequest(), actorResponseWaitTime);
 
         LOG.trace("{}: Cancel {} via NETCONF", id);
 
         try {
             // here must be Await because AsyncWriteTransaction do not return future
-            return (boolean) Await.result(cancelScalaFuture, NetconfTopologyUtils.TIMEOUT.duration());
+            return (boolean) Await.result(cancelScalaFuture, actorResponseWaitTime.duration());
         } catch (Exception e) {
             return false;
         }
@@ -176,7 +179,7 @@ public class NetconfProxyDOMTransaction implements NetconfDOMTransaction {
     @Override
     public Future<Void> submit() {
         final Future<Object> submitScalaFuture =
-                Patterns.ask(masterContextRef, new SubmitRequest(), NetconfTopologyUtils.TIMEOUT);
+                Patterns.ask(masterContextRef, new SubmitRequest(), actorResponseWaitTime);
 
         LOG.trace("{}: Submit {} via NETCONF", id);