Remove netconf from commons/opendaylight pom
[controller.git] / opendaylight / netconf / netconf-notifications-impl / src / main / java / org / opendaylight / controller / netconf / notifications / impl / osgi / Activator.java
index ef950f8a788d768509749e3138afd3d3120e6a93..bd2d5d6b7985bf4724e0f8da453cedb51867ac2e 100644 (file)
@@ -8,13 +8,15 @@
 
 package org.opendaylight.controller.netconf.notifications.impl.osgi;
 
-import com.google.common.base.Optional;
 import com.google.common.collect.Sets;
-import java.util.Collection;
 import java.util.Collections;
+import java.util.Dictionary;
 import java.util.Hashtable;
 import java.util.Set;
-import org.opendaylight.controller.netconf.mapping.api.Capability;
+import org.opendaylight.controller.config.util.capability.BasicCapability;
+import org.opendaylight.controller.config.util.capability.Capability;
+import org.opendaylight.controller.netconf.api.monitoring.CapabilityListener;
+import org.opendaylight.controller.netconf.api.util.NetconfConstants;
 import org.opendaylight.controller.netconf.mapping.api.NetconfOperation;
 import org.opendaylight.controller.netconf.mapping.api.NetconfOperationService;
 import org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceFactory;
@@ -26,9 +28,13 @@ import org.opendaylight.controller.netconf.notifications.impl.ops.Get;
 import org.osgi.framework.BundleActivator;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceRegistration;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class Activator implements BundleActivator {
 
+    private static final Logger LOG = LoggerFactory.getLogger(Activator.class);
+
     private ServiceRegistration<NetconfNotificationCollector> netconfNotificationCollectorServiceRegistration;
     private ServiceRegistration<NetconfOperationServiceFactory> operationaServiceRegistration;
     private NetconfNotificationManager netconfNotificationManager;
@@ -40,17 +46,30 @@ public class Activator implements BundleActivator {
 
         final NetconfOperationServiceFactory netconfOperationServiceFactory = new NetconfOperationServiceFactory() {
 
+            private final Set<Capability> capabilities = Collections.<Capability>singleton(new BasicCapability(NetconfNotification.NOTIFICATION_NAMESPACE));
+
+            @Override
+            public Set<Capability> getCapabilities() {
+                return capabilities;
+            }
+
+            @Override
+            public AutoCloseable registerCapabilityListener(final CapabilityListener listener) {
+                listener.onCapabilitiesChanged(capabilities, Collections.<Capability>emptySet());
+                return new AutoCloseable() {
+                    @Override
+                    public void close() {
+                        listener.onCapabilitiesChanged(Collections.<Capability>emptySet(), capabilities);
+                    }
+                };
+            }
+
             @Override
             public NetconfOperationService createService(final String netconfSessionIdForReporting) {
                 return new NetconfOperationService() {
 
                     private final CreateSubscription createSubscription = new CreateSubscription(netconfSessionIdForReporting, netconfNotificationManager);
 
-                    @Override
-                    public Set<Capability> getCapabilities() {
-                        return Collections.<Capability>singleton(new NotificationsCapability());
-                    }
-
                     @Override
                     public Set<NetconfOperation> getNetconfOperations() {
                         return Sets.<NetconfOperation>newHashSet(
@@ -66,8 +85,9 @@ public class Activator implements BundleActivator {
             }
         };
 
-        operationaServiceRegistration = context.registerService(NetconfOperationServiceFactory.class, netconfOperationServiceFactory, new Hashtable<String, Object>());
-
+        final Dictionary<String, String> properties = new Hashtable<>();
+        properties.put(NetconfConstants.SERVICE_NAME, NetconfConstants.NETCONF_MONITORING);
+        operationaServiceRegistration = context.registerService(NetconfOperationServiceFactory.class, netconfOperationServiceFactory, properties);
     }
 
     @Override
@@ -84,36 +104,4 @@ public class Activator implements BundleActivator {
             operationaServiceRegistration = null;
         }
     }
-
-    private class NotificationsCapability implements Capability {
-        @Override
-        public String getCapabilityUri() {
-            return NetconfNotification.NOTIFICATION_NAMESPACE;
-        }
-
-        @Override
-        public Optional<String> getModuleNamespace() {
-            return Optional.absent();
-        }
-
-        @Override
-        public Optional<String> getModuleName() {
-            return Optional.absent();
-        }
-
-        @Override
-        public Optional<String> getRevision() {
-            return Optional.absent();
-        }
-
-        @Override
-        public Optional<String> getCapabilitySchema() {
-            return Optional.absent();
-        }
-
-        @Override
-        public Collection<String> getLocation() {
-            return Collections.emptyList();
-        }
-    }
 }