Merge "Remove unnecessary warn log from config subsystem"
[controller.git] / opendaylight / md-sal / sal-rest-connector / src / main / java / org / opendaylight / controller / sal / streams / listeners / Notificator.java
index b0140ec83a178f6bc9f9bbaecf5a415ff812bb24..d1cb25861ae0496c299cc9f4c67ebf5314a871e4 100644 (file)
@@ -30,10 +30,13 @@ public class Notificator {
 
     public static ListenerAdapter createListener(InstanceIdentifier path, String streamName) {
         ListenerAdapter listener = new ListenerAdapter(path, streamName);
-        lock.lock();
-        listenersByInstanceIdentifier.put(path, listener);
-        listenersByStreamName.put(streamName, listener);
-        lock.unlock();
+        try {
+            lock.lock();
+            listenersByInstanceIdentifier.put(path, listener);
+            listenersByStreamName.put(streamName, listener);
+        } finally {
+            lock.unlock();
+        }
         return listener;
     }
 
@@ -63,10 +66,13 @@ public class Notificator {
             } catch (Exception e) {
             }
         }
-        lock.lock();
-        listenersByStreamName = new ConcurrentHashMap<>();
-        listenersByInstanceIdentifier = new ConcurrentHashMap<>();
-        lock.unlock();
+        try {
+            lock.lock();
+            listenersByStreamName = new ConcurrentHashMap<>();
+            listenersByInstanceIdentifier = new ConcurrentHashMap<>();
+        } finally {
+            lock.unlock();
+        }
     }
 
     public static void removeListenerIfNoSubscriberExists(ListenerAdapter listener) {
@@ -81,10 +87,13 @@ public class Notificator {
                 listener.close();
             } catch (Exception e) {
             }
-            lock.lock();
-            listenersByInstanceIdentifier.remove(listener.getPath());
-            listenersByStreamName.remove(listener).getStreamName();
-            lock.unlock();
+            try {
+                lock.lock();
+                listenersByInstanceIdentifier.remove(listener.getPath());
+                listenersByStreamName.remove(listener.getStreamName());
+            } finally {
+                lock.unlock();
+            }
         }
     }