Merge "Remove use of ThreadPools in sal-netconf-connector"
authorJakub Morvay <jakub.morvay@gmail.com>
Mon, 1 Oct 2018 22:14:57 +0000 (22:14 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Mon, 1 Oct 2018 22:14:57 +0000 (22:14 +0000)
netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/rpc/SimulatedCreateSubscription.java
restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/streams/listeners/AbstractCommonSubscriber.java

index 8a42baa7a29e6d263ffcc6c15416ff7f93642333..fc7e99a31d3cf0b72cb56b05e872a3b20f79b882 100644 (file)
@@ -14,6 +14,7 @@ import com.google.common.collect.Maps;
 import java.io.File;
 import java.io.IOException;
 import java.text.SimpleDateFormat;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.Date;
 import java.util.List;
@@ -45,7 +46,7 @@ public class SimulatedCreateSubscription extends AbstractLastNetconfOperation im
     public SimulatedCreateSubscription(final String id, final Optional<File> notificationsFile) {
         super(id);
 
-        Optional<Notifications> notifs;
+        final Optional<Notifications> notifs;
 
         if (notificationsFile.isPresent()) {
             notifs = Optional.of(loadNotifications(notificationsFile.get()));
@@ -55,9 +56,9 @@ public class SimulatedCreateSubscription extends AbstractLastNetconfOperation im
         }
 
         if (notifs.isPresent()) {
-            Map<Notification, NetconfMessage> preparedMessages = Maps.newHashMapWithExpectedSize(
-                notifs.get().getNotificationList().size());
-            for (final Notification notification : notifs.get().getNotificationList()) {
+            final Collection<Notification> toCopy = notifs.get().getNotificationList();
+            final Map<Notification, NetconfMessage> preparedMessages = Maps.newHashMapWithExpectedSize(toCopy.size());
+            for (final Notification notification : toCopy) {
                 final NetconfMessage parsedNotification = parseNetconfNotification(notification.getContent());
                 preparedMessages.put(notification, parsedNotification);
             }
@@ -65,7 +66,6 @@ public class SimulatedCreateSubscription extends AbstractLastNetconfOperation im
         } else {
             this.notifications = Collections.emptyMap();
         }
-
     }
 
     private static Notifications loadNotifications(final File file) {
index 41503253bc61bb2f75fe07f0ea0ae10b6dfbc94d..2a7ba619c59a543fcedd6815912b458977396941 100644 (file)
@@ -51,8 +51,11 @@ abstract class AbstractCommonSubscriber extends AbstractQueryParams implements B
 
     @Override
     public final void close() {
-        this.registration.close();
-        this.registration = null;
+        if (registration != null) {
+            this.registration.close();
+            this.registration = null;
+        }
+
         unregister();
     }