Cancel ongoing SMR futures on new event 98/57798/2
authorLorand Jakab <lojakab@cisco.com>
Thu, 25 May 2017 05:32:39 +0000 (08:32 +0300)
committerLorand Jakab <lojakab@cisco.com>
Thu, 25 May 2017 08:04:47 +0000 (11:04 +0300)
The SMR scheduler keeps retrying the sending of SMRs a few (configurable
number) of times with a given spacing between the retries until an
SMR-invoked Map-Request is received for the particular EID. When that
happens, the retrying is cancelled for the subscriber that sent it.

However, up until now, when a new set of SMRs was scheduled for a given
EID, the old set, if still retrying, was left untouched. This patch
fixes that, and starts with a clean slate for the given EID.

Change-Id: Ic64ce0980b39d780433ac2c4e96608af12302392
Signed-off-by: Lorand Jakab <lojakab@cisco.com>
mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/lisp/MapServer.java

index 2663c292de2caeb5540903233025d58580680aff..eb6d666159213fcc3a46063a4d9ad089a21c79f3 100644 (file)
@@ -351,6 +351,8 @@ public class MapServer implements IMapServerAsync, OdlMappingserviceListener, IS
 
         void scheduleSmrs(MapRequestBuilder mrb, Iterator<Subscriber> subscribers) {
             final Eid srcEid = mrb.getSourceEid().getEid();
+            cancelExistingFuturesForEid(srcEid);
+
             final Map<Subscriber, ScheduledFuture<?>> subscriberFutureMap = Maps.newConcurrentMap();
 
             // Using Iterator ensures that we don't get a ConcurrentModificationException when removing a Subscriber
@@ -395,6 +397,21 @@ public class MapServer implements IMapServerAsync, OdlMappingserviceListener, IS
             }
         }
 
+        private void cancelExistingFuturesForEid(Eid eid) {
+            synchronized (eidFutureMap) {
+                if (eidFutureMap.containsKey(eid)) {
+                    final Map<Subscriber, ScheduledFuture<?>> subscriberFutureMap = eidFutureMap.get(eid);
+                    Iterator<Subscriber> oldSubscribers = subscriberFutureMap.keySet().iterator();
+                    while (oldSubscribers.hasNext()) {
+                        Subscriber subscriber = oldSubscribers.next();
+                        ScheduledFuture<?> subscriberFuture = subscriberFutureMap.get(subscriber);
+                        subscriberFuture.cancel(true);
+                    }
+                    eidFutureMap.remove(eid);
+                }
+            }
+        }
+
         private final class CancellableRunnable implements Runnable {
             private MapRequestBuilder mrb;
             private Subscriber subscriber;