Synchronize stop and reschedule keepalive methods 21/91721/2
authorAnna Bencurova <Anna.Bencurova@pantheon.tech>
Tue, 28 Jul 2020 12:19:45 +0000 (14:19 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 3 Aug 2020 07:52:02 +0000 (09:52 +0200)
Synchronize to avoid stucked scheduled keepalive task. This is not
a perfect solution, but should work for now.

JIRA: NETCONF-715
Change-Id: I130507f3e6472c8b15eb027e40ab41c972f075ec
Signed-off-by: Anna Bencurova <Anna.Bencurova@pantheon.tech>
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/sal/KeepaliveSalFacade.java

index 755745650ae2375d4bda7863094abb478561cee4..b9d4e349b53e90a6c874c06bfafe6d485bc5047f 100644 (file)
@@ -93,16 +93,18 @@ public final class KeepaliveSalFacade implements RemoteDeviceHandler<NetconfSess
     }
 
     /**
-     * Just cancel current keepalive task.
+     * Just cancel current keepalive task if exists.
      * If its already started, let it finish ... not such a big deal.
      *
      * <p>
      * Then schedule next keepalive.
      */
-    void resetKeepalive() {
+    synchronized void resetKeepalive() {
         LOG.trace("{}: Resetting netconf keepalive timer", id);
         if (currentKeepalive != null) {
             currentKeepalive.cancel(false);
+        } else {
+            LOG.trace("{}: Keepalive does not exist", id);
         }
         scheduleKeepalives();
     }
@@ -110,7 +112,7 @@ public final class KeepaliveSalFacade implements RemoteDeviceHandler<NetconfSess
     /**
      * Cancel current keepalive and also reset current deviceRpc.
      */
-    private void stopKeepalives() {
+    private synchronized void stopKeepalives() {
         if (currentKeepalive != null) {
             currentKeepalive.cancel(false);
         }
@@ -142,7 +144,7 @@ public final class KeepaliveSalFacade implements RemoteDeviceHandler<NetconfSess
         salFacade.onDeviceConnected(remoteSchemaContext, netconfSessionPreferences, deviceRpc1, deviceAction);
 
         LOG.debug("{}: Netconf session initiated, starting keepalives", id);
-        scheduleKeepalives();
+        resetKeepalive();
     }
 
     private void scheduleKeepalives() {
@@ -266,12 +268,7 @@ public final class KeepaliveSalFacade implements RemoteDeviceHandler<NetconfSess
         private ScheduledFuture<?> schedule;
 
         public void initScheduler(final Runnable runnable) {
-            if (currentKeepalive != null) {
-                currentKeepalive.cancel(true);
-            } else {
-                LOG.trace("Keepalive does not exist.");
-            }
-            scheduleKeepalives();
+            resetKeepalive();
             //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);