Update MRI projects for Aluminium
[netconf.git] / netconf / mdsal-netconf-notification / src / main / java / org / opendaylight / netconf / mdsal / notification / impl / NetconfNotificationManager.java
index e45af56b50d2d7ffe1b12fc2e4afc064d1941781..f746ad057dfaff44a34ea55698fe1c4f2dcd4bd4 100644 (file)
@@ -13,7 +13,7 @@ import static java.util.Objects.requireNonNull;
 
 import com.google.common.collect.HashMultimap;
 import com.google.common.collect.HashMultiset;
-import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
 import com.google.common.collect.Multimap;
 import com.google.common.collect.Multiset;
 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
@@ -21,6 +21,8 @@ import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
+import javax.inject.Inject;
+import javax.inject.Singleton;
 import org.checkerframework.checker.lock.qual.GuardedBy;
 import org.opendaylight.netconf.mdsal.notification.impl.ops.NotificationsTransformUtil;
 import org.opendaylight.netconf.notifications.BaseNotificationPublisherRegistration;
@@ -50,20 +52,17 @@ import org.slf4j.LoggerFactory;
 /**
  *  A thread-safe implementation NetconfNotificationRegistry.
  */
+@Singleton
 public class NetconfNotificationManager implements NetconfNotificationCollector, NetconfNotificationRegistry,
         NetconfNotificationListener, AutoCloseable {
 
     public static final StreamNameType BASE_STREAM_NAME = new StreamNameType("NETCONF");
-    public static final Stream BASE_NETCONF_STREAM;
-
-    static {
-        BASE_NETCONF_STREAM = new StreamBuilder()
+    public static final Stream BASE_NETCONF_STREAM = new StreamBuilder()
                 .setName(BASE_STREAM_NAME)
                 .withKey(new StreamKey(BASE_STREAM_NAME))
                 .setReplaySupport(false)
                 .setDescription("Default Event Stream")
                 .build();
-    }
 
     private static final Logger LOG = LoggerFactory.getLogger(NetconfNotificationManager.class);
 
@@ -87,6 +86,12 @@ public class NetconfNotificationManager implements NetconfNotificationCollector,
 
     @GuardedBy("this")
     private final Set<GenericNotificationPublisherReg> notificationPublishers = new HashSet<>();
+    private final NotificationsTransformUtil transformUtil;
+
+    @Inject
+    public NetconfNotificationManager(final NotificationsTransformUtil transformUtil) {
+        this.transformUtil = requireNonNull(transformUtil);
+    }
 
     @Override
     public synchronized void onNotification(final StreamNameType stream, final NetconfNotification notification) {
@@ -126,7 +131,7 @@ public class NetconfNotificationManager implements NetconfNotificationCollector,
 
     @Override
     public synchronized Streams getNotificationPublishers() {
-        return new StreamsBuilder().setStream(Lists.newArrayList(streamMetadata.values())).build();
+        return new StreamsBuilder().setStream(Maps.uniqueIndex(streamMetadata.values(), Stream::key)).build();
     }
 
     @Override
@@ -237,14 +242,14 @@ public class NetconfNotificationManager implements NetconfNotificationCollector,
     public BaseNotificationPublisherRegistration registerBaseNotificationPublisher() {
         final NotificationPublisherRegistration notificationPublisherRegistration =
                 registerNotificationPublisher(BASE_NETCONF_STREAM);
-        return new BaseNotificationPublisherReg(notificationPublisherRegistration);
+        return new BaseNotificationPublisherReg(transformUtil, notificationPublisherRegistration);
     }
 
     @Override
     public YangLibraryPublisherRegistration registerYangLibraryPublisher() {
         final NotificationPublisherRegistration notificationPublisherRegistration =
                 registerNotificationPublisher(BASE_NETCONF_STREAM);
-        return new YangLibraryPublisherReg(notificationPublisherRegistration);
+        return new YangLibraryPublisherReg(transformUtil, notificationPublisherRegistration);
     }
 
     private static class GenericNotificationPublisherReg implements NotificationPublisherRegistration {
@@ -278,8 +283,11 @@ public class NetconfNotificationManager implements NetconfNotificationCollector,
         static final SchemaPath SESSION_END_PATH = SchemaPath.create(true, NetconfSessionEnd.QNAME);
 
         private final NotificationPublisherRegistration baseRegistration;
+        private final NotificationsTransformUtil transformUtil;
 
-        BaseNotificationPublisherReg(final NotificationPublisherRegistration baseRegistration) {
+        BaseNotificationPublisherReg(final NotificationsTransformUtil transformUtil,
+                final NotificationPublisherRegistration baseRegistration) {
+            this.transformUtil = requireNonNull(transformUtil);
             this.baseRegistration = baseRegistration;
         }
 
@@ -288,9 +296,8 @@ public class NetconfNotificationManager implements NetconfNotificationCollector,
             baseRegistration.close();
         }
 
-        private static NetconfNotification serializeNotification(final Notification notification,
-                final SchemaPath path) {
-            return NotificationsTransformUtil.transform(notification, path);
+        private NetconfNotification serializeNotification(final Notification notification, final SchemaPath path) {
+            return transformUtil.transform(notification, path);
         }
 
         @Override
@@ -314,15 +321,18 @@ public class NetconfNotificationManager implements NetconfNotificationCollector,
         static final SchemaPath YANG_LIBRARY_CHANGE_PATH = SchemaPath.create(true, YangLibraryChange.QNAME);
 
         private final NotificationPublisherRegistration baseRegistration;
+        private final NotificationsTransformUtil transformUtil;
 
-        YangLibraryPublisherReg(final NotificationPublisherRegistration baseRegistration) {
+        YangLibraryPublisherReg(final NotificationsTransformUtil transformUtil,
+                final NotificationPublisherRegistration baseRegistration) {
+            this.transformUtil = requireNonNull(transformUtil);
             this.baseRegistration = baseRegistration;
         }
 
         @Override
-        public void onYangLibraryChange(YangLibraryChange yangLibraryChange) {
-            baseRegistration.onNotification(BASE_STREAM_NAME, NotificationsTransformUtil
-                    .transform(yangLibraryChange, YANG_LIBRARY_CHANGE_PATH));
+        public void onYangLibraryChange(final YangLibraryChange yangLibraryChange) {
+            baseRegistration.onNotification(BASE_STREAM_NAME,
+                transformUtil.transform(yangLibraryChange, YANG_LIBRARY_CHANGE_PATH));
         }
 
         @Override