Mark config substystem NotificationManager 45/26145/6
authorJMorvay <jmorvay@cisco.com>
Wed, 26 Aug 2015 10:59:52 +0000 (12:59 +0200)
committerJMorvay <jmorvay@cisco.com>
Wed, 23 Sep 2015 08:00:50 +0000 (10:00 +0200)
Mark NotificationManager, that is auto wired netconf endpoint for config
subsystem

Change-Id: I51ec53ba122aa0a3dd79e4d71e07422fac1b8ffc
Signed-off-by: JMorvay <jmorvay@cisco.com>
opendaylight/netconf/netconf-api/src/main/java/org/opendaylight/netconf/api/util/NetconfConstants.java
opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/netconf/impl/osgi/NetconfImplActivator.java
opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/netconf/impl/osgi/NetconfOperationServiceFactoryTracker.java
opendaylight/netconf/netconf-notifications-impl/src/main/java/org/opendaylight/netconf/notifications/impl/osgi/Activator.java

index 326b513be8d2fbe118a600e9cb0254ed25379163..36b1b128eb397bbbcc0c99084d56fef9b22ab4e9 100644 (file)
@@ -8,6 +8,9 @@
 
 package org.opendaylight.netconf.api.util;
 
+import com.google.common.collect.Sets;
+import java.util.Set;
+
 /**
  * These constants mark operation service factories that are auto wired with netconf endpoint
  * for config subsystem
@@ -20,4 +23,7 @@ public final class NetconfConstants {
     public static final String SERVICE_NAME = "name";
     public static final String CONFIG_NETCONF_CONNECTOR = "config-netconf-connector";
     public static final String NETCONF_MONITORING = "ietf-netconf-monitoring";
+    public static final String NETCONF_NOTIFICATION = "ietf-netconf-notifications";
+
+    public static final Set<String> CONFIG_SERVICE_MARKERS = Sets.newHashSet(SERVICE_NAME, CONFIG_NETCONF_CONNECTOR, NETCONF_MONITORING, NETCONF_NOTIFICATION);
 }
index 104926a99c442a8120a1a283ec1a36df4928a762..e62089601b0ffc15026c3d17facb3a8ebafbb1f2 100644 (file)
@@ -7,6 +7,7 @@
  */
 package org.opendaylight.netconf.impl.osgi;
 
+import com.google.common.base.Preconditions;
 import io.netty.channel.local.LocalAddress;
 import io.netty.channel.nio.NioEventLoopGroup;
 import io.netty.util.HashedWheelTimer;
@@ -71,6 +72,7 @@ public class NetconfImplActivator implements BundleActivator {
                     new ServiceTracker<>(context, NetconfNotificationCollector.class, new ServiceTrackerCustomizer<NetconfNotificationCollector, NetconfNotificationCollector>() {
                         @Override
                         public NetconfNotificationCollector addingService(ServiceReference<NetconfNotificationCollector> reference) {
+                            Preconditions.checkState(listenerReg != null, "Notification collector service was already added");
                             listenerReg = context.getService(reference).registerBaseNotificationPublisher();
                             monitoringService.setNotificationPublisher(listenerReg);
                             return null;
index a72c3a2aa3cfdb8ae72fe8711a93bab8221d5026..2f9d63f4688540ec50597a89601fafbaec38cd40 100644 (file)
@@ -27,9 +27,7 @@ class NetconfOperationServiceFactoryTracker extends
     @Override
     public NetconfOperationServiceFactory addingService(ServiceReference<NetconfOperationServiceFactory> reference) {
         Object property = reference.getProperty(NetconfConstants.SERVICE_NAME);
-        if (property != null
-                && (property.equals(NetconfConstants.CONFIG_NETCONF_CONNECTOR)
-                || property.equals(NetconfConstants.NETCONF_MONITORING))) {
+        if (property != null && isMarkedForConfig(property)) {
             NetconfOperationServiceFactory netconfOperationServiceFactory = super.addingService(reference);
             factoriesListener.onAddNetconfOperationServiceFactory(netconfOperationServiceFactory);
             return netconfOperationServiceFactory;
@@ -46,4 +44,8 @@ class NetconfOperationServiceFactoryTracker extends
         }
     }
 
+    private boolean isMarkedForConfig(Object property) {
+        return NetconfConstants.CONFIG_SERVICE_MARKERS.contains(property);
+    }
+
 }
index b024481955c206d5be1ad24fcddaf4fdcab0d624..89aee08e87f22476577928136c5f628647e9c3b1 100644 (file)
@@ -42,6 +42,9 @@ public class Activator implements BundleActivator {
     @Override
     public void start(final BundleContext context) throws Exception {
         netconfNotificationManager = new NetconfNotificationManager();
+        // Add properties to autowire with netconf-impl instance for cfg subsystem
+        final Dictionary<String, String> props = new Hashtable<>();
+        props.put(NetconfConstants.SERVICE_NAME, NetconfConstants.NETCONF_NOTIFICATION);
         netconfNotificationCollectorServiceRegistration = context.registerService(NetconfNotificationCollector.class, netconfNotificationManager, new Hashtable<String, Object>());
 
         final NetconfOperationServiceFactory netconfOperationServiceFactory = new NetconfOperationServiceFactory() {