Migration to TAPI 2.4 Step2
[transportpce.git] / nbinotifications / src / main / java / org / opendaylight / transportpce / nbinotifications / impl / NbiNotificationsProvider.java
index 24c0383e4dbfb516383666a734612d217a8b5089..c26c1478ffd51c4a5be37591b38bc00ac6096acc 100644 (file)
@@ -14,68 +14,92 @@ import org.opendaylight.mdsal.binding.api.NotificationService;
 import org.opendaylight.mdsal.binding.api.RpcProviderService;
 import org.opendaylight.mdsal.binding.dom.codec.spi.BindingDOMCodecServices;
 import org.opendaylight.transportpce.common.converter.JsonStringConverter;
-import org.opendaylight.transportpce.nbinotifications.listener.NbiNotificationsListenerImpl;
+import org.opendaylight.transportpce.common.network.NetworkTransactionService;
+import org.opendaylight.transportpce.nbinotifications.listener.NbiNotificationsHandler;
 import org.opendaylight.transportpce.nbinotifications.producer.Publisher;
-import org.opendaylight.transportpce.nbinotifications.serialization.NotificationAlarmServiceSerializer;
-import org.opendaylight.transportpce.nbinotifications.serialization.NotificationServiceSerializer;
-import org.opendaylight.yang.gen.v1.nbi.notifications.rev210813.NbiNotificationsListener;
-import org.opendaylight.yang.gen.v1.nbi.notifications.rev210813.NbiNotificationsService;
-import org.opendaylight.yang.gen.v1.nbi.notifications.rev210813.NotificationAlarmService;
-import org.opendaylight.yang.gen.v1.nbi.notifications.rev210813.NotificationProcessService;
-import org.opendaylight.yangtools.concepts.ListenerRegistration;
-import org.opendaylight.yangtools.concepts.ObjectRegistration;
+import org.opendaylight.transportpce.nbinotifications.utils.TopicManager;
+import org.opendaylight.yang.gen.v1.nbi.notifications.rev230728.NotificationAlarmService;
+import org.opendaylight.yang.gen.v1.nbi.notifications.rev230728.NotificationProcessService;
+import org.opendaylight.yang.gen.v1.nbi.notifications.rev230728.NotificationTapiService;
+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;
+import org.osgi.service.metatype.annotations.AttributeDefinition;
+import org.osgi.service.metatype.annotations.ObjectClassDefinition;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+@Component(configurationPid = "org.opendaylight.transportpce.nbinotifications")
 public class NbiNotificationsProvider {
 
+    @ObjectClassDefinition
+    public @interface Configuration {
+        @AttributeDefinition
+        String suscriberServer() default "";
+        @AttributeDefinition
+        String publisherServer() default "";
+    }
+
     private static final Logger LOG = LoggerFactory.getLogger(NbiNotificationsProvider.class);
     private static Map<String, Publisher<NotificationProcessService>> publishersServiceMap =  new HashMap<>();
     private static Map<String, Publisher<NotificationAlarmService>> publishersAlarmMap =  new HashMap<>();
-    private final RpcProviderService rpcService;
-    private final NotificationService notificationService;
-    private final JsonStringConverter<NotificationProcessService> converterService;
-    private final JsonStringConverter<NotificationAlarmService> converterAlarmService;
-    private final String subscriberServer;
-    private ObjectRegistration<NbiNotificationsService> rpcRegistration;
-    private ListenerRegistration<NbiNotificationsListener> listenerRegistration;
+    private Registration listenerRegistration;
+    private Registration rpcRegistration;
 
+    @Activate
+    public NbiNotificationsProvider(@Reference RpcProviderService rpcProviderService,
+            @Reference NotificationService notificationService,
+            @Reference BindingDOMCodecServices bindingDOMCodecServices,
+            @Reference NetworkTransactionService networkTransactionService,
+            final Configuration configuration) {
+        this(configuration.suscriberServer(), configuration.publisherServer(), rpcProviderService, notificationService,
+                bindingDOMCodecServices, networkTransactionService);
+    }
 
-    public NbiNotificationsProvider(List<String> publishersService, List<String> publishersAlarm,
-            String subscriberServer, String publisherServer,
+    public NbiNotificationsProvider(String subscriberServer, String publisherServer,
             RpcProviderService rpcProviderService, NotificationService notificationService,
-            BindingDOMCodecServices bindingDOMCodecServices) {
-        this.rpcService = rpcProviderService;
-        this.notificationService = notificationService;
-        converterService =  new JsonStringConverter<>(bindingDOMCodecServices);
-        for (String publisherService: publishersService) {
+            BindingDOMCodecServices bindingDOMCodecServices, NetworkTransactionService networkTransactionService) {
+        List<String> publishersServiceList = List.of("PceListener", "ServiceHandlerOperations", "ServiceHandler",
+                "RendererListener");
+        TopicManager topicManager = TopicManager.getInstance();
+        topicManager.setPublisherServer(publisherServer);
+        JsonStringConverter<NotificationProcessService> converterService =
+            new JsonStringConverter<>(bindingDOMCodecServices);
+        topicManager.setProcessConverter(converterService);
+        for (String publisherService: publishersServiceList) {
             LOG.info("Creating publisher for the following class {}", publisherService);
-            publishersServiceMap.put(publisherService, new Publisher<>(publisherService, publisherServer,
-                    converterService, NotificationServiceSerializer.class));
+            topicManager.addProcessTopic(publisherService);
         }
-        converterAlarmService = new JsonStringConverter<>(bindingDOMCodecServices);
-        for (String publisherAlarm: publishersAlarm) {
+        JsonStringConverter<NotificationAlarmService> converterAlarmService =
+                new JsonStringConverter<>(bindingDOMCodecServices);
+        topicManager.setAlarmConverter(converterAlarmService);
+        List<String> publishersAlarmList = List.of("ServiceListener");
+        for (String publisherAlarm: publishersAlarmList) {
             LOG.info("Creating publisher for the following class {}", publisherAlarm);
-            publishersAlarmMap.put(publisherAlarm, new Publisher<>(publisherAlarm, publisherServer,
-                    converterAlarmService, NotificationAlarmServiceSerializer.class));
+            topicManager.addAlarmTopic(publisherAlarm);
         }
-        this.subscriberServer = subscriberServer;
-    }
+        JsonStringConverter<NotificationTapiService> converterTapiService =
+                new JsonStringConverter<>(bindingDOMCodecServices);
+        LOG.info("baozhi tapi converter: {}", converterTapiService);
+        topicManager.setTapiConverter(converterTapiService);
 
-    /**
-     * Method called when the blueprint container is created.
-     */
-    public void init() {
+        NbiNotificationsImpl nbiImpl = new NbiNotificationsImpl(converterService, converterAlarmService,
+            converterTapiService, subscriberServer, networkTransactionService, topicManager);
+        rpcRegistration = rpcProviderService.registerRpcImplementations(nbiImpl.registerRPCs());
+        NbiNotificationsHandler notificationsListener = new NbiNotificationsHandler(
+            topicManager.getProcessTopicMap(), topicManager.getAlarmTopicMap(), topicManager.getTapiTopicMap());
+        listenerRegistration = notificationService.registerCompositeListener(
+            notificationsListener.getCompositeListener());
+        topicManager.setNbiNotificationsListener(notificationsListener);
         LOG.info("NbiNotificationsProvider Session Initiated");
-        rpcRegistration = rpcService.registerRpcImplementation(NbiNotificationsService.class,
-                new NbiNotificationsImpl(converterService, converterAlarmService, subscriberServer));
-        listenerRegistration = notificationService.registerNotificationListener(
-                new NbiNotificationsListenerImpl(publishersServiceMap, publishersAlarmMap));
     }
 
     /**
      * Method called when the blueprint container is destroyed.
      */
+    @Deactivate
     public void close() {
         for (Publisher<NotificationProcessService> publisher : publishersServiceMap.values()) {
             publisher.close();
@@ -87,5 +111,4 @@ public class NbiNotificationsProvider {
         listenerRegistration.close();
         LOG.info("NbiNotificationsProvider Closed");
     }
-
 }