Convert mdsal-netconf-notification to OSGi DS
[netconf.git] / netconf / mdsal-netconf-notification / src / main / java / org / opendaylight / netconf / mdsal / notification / impl / NetconfNotificationOperationServiceFactory.java
index 1f37ccf5c36288e0fbe078c312fc8b344112040f..1c554d76e6e36d8306d4b8115b2f3301cf8fd132 100644 (file)
@@ -5,10 +5,10 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.netconf.mdsal.notification.impl;
 
-import java.util.Collections;
+import static java.util.Objects.requireNonNull;
+
 import java.util.Set;
 import org.opendaylight.netconf.api.capability.Capability;
 import org.opendaylight.netconf.api.monitoring.CapabilityListener;
@@ -17,18 +17,31 @@ import org.opendaylight.netconf.mapping.api.NetconfOperationServiceFactory;
 import org.opendaylight.netconf.mapping.api.NetconfOperationServiceFactoryListener;
 import org.opendaylight.netconf.notifications.NetconfNotificationRegistry;
 import org.opendaylight.yangtools.concepts.Registration;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Deactivate;
+import org.osgi.service.component.annotations.Reference;
 
+@Component(service = NetconfOperationServiceFactory.class, immediate = true,
+           property = "type=mdsal-netconf-notification")
 public final class NetconfNotificationOperationServiceFactory implements NetconfOperationServiceFactory, AutoCloseable {
-    private final NetconfNotificationRegistry netconfNotificationRegistry;
-    private final NetconfOperationServiceFactoryListener netconfOperationServiceFactoryListener;
+    private final NetconfNotificationRegistry notifManager;
+    private final NetconfOperationServiceFactoryListener aggregatorRegistry;
 
+    @Activate
     public NetconfNotificationOperationServiceFactory(
-            final NetconfNotificationRegistry netconfNotificationRegistry,
-            final NetconfOperationServiceFactoryListener netconfOperationServiceFactoryListener) {
-        this.netconfNotificationRegistry = netconfNotificationRegistry;
-        this.netconfOperationServiceFactoryListener = netconfOperationServiceFactoryListener;
+            @Reference(target = "(type=netconf-notification-manager)") final NetconfNotificationRegistry notifManager,
+            @Reference(target = "(type=mapper-aggregator-registry)")
+            final NetconfOperationServiceFactoryListener aggregatorRegistry) {
+        this.notifManager = requireNonNull(notifManager);
+        this.aggregatorRegistry = requireNonNull(aggregatorRegistry);
+        this.aggregatorRegistry.onAddNetconfOperationServiceFactory(this);
+    }
 
-        this.netconfOperationServiceFactoryListener.onAddNetconfOperationServiceFactory(this);
+    @Deactivate
+    @Override
+    public void close() {
+        aggregatorRegistry.onRemoveNetconfOperationServiceFactory(this);
     }
 
     @Override
@@ -38,21 +51,16 @@ public final class NetconfNotificationOperationServiceFactory implements Netconf
         // config-netconf-connector (it exposes all the schemas)
         // If the schemas exposed by config-netconf-connector are filtered,
         // this class would expose monitoring related models
-        return Collections.emptySet();
+        return Set.of();
     }
 
     @Override
     public NetconfOperationService createService(final String netconfSessionIdForReporting) {
-        return new NetconfNotificationOperationService(netconfSessionIdForReporting, netconfNotificationRegistry);
+        return new NetconfNotificationOperationService(netconfSessionIdForReporting, notifManager);
     }
 
     @Override
     public Registration registerCapabilityListener(final CapabilityListener listener) {
         return () -> { };
     }
-
-    @Override
-    public void close() {
-        netconfOperationServiceFactoryListener.onRemoveNetconfOperationServiceFactory(this);
-    }
 }