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%2FKeepaliveSalFacade.java;h=3b255ed009125becf3eb1abd571df92f2c0e3690;hb=32198feec954f869a760c69bf5a4ccf6f116c7bd;hp=59ce05edca3198cfe39b067dbe202e36cc4ac796;hpb=0468948a87e4de87e54b0f308f1deb06d98426c4;p=netconf.git diff --git a/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/sal/KeepaliveSalFacade.java b/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/sal/KeepaliveSalFacade.java index 59ce05edca..3b255ed009 100644 --- a/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/sal/KeepaliveSalFacade.java +++ b/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/sal/KeepaliveSalFacade.java @@ -139,7 +139,8 @@ public final class KeepaliveSalFacade implements RemoteDeviceHandler schedule; + + public void initScheduler(final Runnable runnable) { + if (currentKeepalive != null) { + currentKeepalive.cancel(true); + } else { + LOG.trace("Keepalive does not exist."); + } + scheduleKeepalives(); + //Listening on the result should be done before the keepalive rpc will be send + final long delay = (keepaliveDelaySeconds * 1000) - 500; + schedule = executor.schedule(runnable, delay, TimeUnit.MILLISECONDS); + } + + public void stopScheduler() { + if (schedule != null) { + schedule.cancel(true); + } else { + LOG.trace("Scheduler does not exist."); + } + } + } + + private static final class ResponseWaiting implements Runnable { + + private final FluentFuture rpcResultFuture; + private final ResponseWaitingScheduler responseWaitingScheduler; + + ResponseWaiting(final ResponseWaitingScheduler responseWaitingScheduler, + final FluentFuture rpcResultFuture) { + this.responseWaitingScheduler = responseWaitingScheduler; + this.rpcResultFuture = rpcResultFuture; + } + + public void start() { + LOG.trace("Start to waiting for result."); + responseWaitingScheduler.initScheduler(this); + } + + public void stop() { + LOG.info("Stop to waiting for result."); + responseWaitingScheduler.stopScheduler(); + } + + @Override + public void run() { + if (!rpcResultFuture.isCancelled() && !rpcResultFuture.isDone()) { + LOG.trace("Waiting for result"); + responseWaitingScheduler.initScheduler(this); + } else { + LOG.trace("Result has been cancelled or done."); + } + } + } + /* * Request timeout task is called once the defaultRequestTimeoutMillis is * reached. At this moment, if the request is not yet finished, we cancel @@ -265,9 +323,11 @@ public final class KeepaliveSalFacade implements RemoteDeviceHandler rpcResultFuture; + private final ResponseWaiting responseWaiting; - RequestTimeoutTask(final FluentFuture rpcResultFuture) { + RequestTimeoutTask(final FluentFuture rpcResultFuture, final ResponseWaiting responseWaiting) { this.rpcResultFuture = rpcResultFuture; + this.responseWaiting = responseWaiting; } @Override @@ -275,6 +335,9 @@ public final class KeepaliveSalFacade implements RemoteDeviceHandler invokeRpc(@Nonnull final SchemaPath type, final NormalizedNode input) { final FluentFuture rpcResultFuture = deviceRpc.invokeRpc(type, input); - Futures.addCallback(rpcResultFuture, resetKeepaliveTask, MoreExecutors.directExecutor()); + final ResponseWaiting responseWaiting = new ResponseWaiting(responseWaitingScheduler, rpcResultFuture); + responseWaiting.start(); + rpcResultFuture.addCallback(resetKeepaliveTask, MoreExecutors.directExecutor()); - final RequestTimeoutTask timeoutTask = new RequestTimeoutTask(rpcResultFuture); + final RequestTimeoutTask timeoutTask = new RequestTimeoutTask(rpcResultFuture, responseWaiting); executor.schedule(timeoutTask, defaultRequestTimeoutMillis, TimeUnit.MILLISECONDS); return rpcResultFuture;