Refactor SH CatalogMapper
[transportpce.git] / servicehandler / src / main / java / org / opendaylight / transportpce / servicehandler / impl / ServicehandlerProvider.java
index 379296038f85ed463703a7ad40961b0acf4a347a..658b50e45daa24e8be8d2cec2694e740cb479edc 100644 (file)
@@ -9,14 +9,12 @@
 package org.opendaylight.transportpce.servicehandler.impl;
 
 import org.opendaylight.mdsal.binding.api.DataBroker;
+import org.opendaylight.mdsal.binding.api.DataTreeChangeListener;
 import org.opendaylight.mdsal.binding.api.DataTreeIdentifier;
+import org.opendaylight.mdsal.binding.api.NotificationPublishService;
 import org.opendaylight.mdsal.binding.api.NotificationService;
 import org.opendaylight.mdsal.binding.api.RpcProviderService;
 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
-import org.opendaylight.transportpce.servicehandler.listeners.NetworkModelListenerImpl;
-import org.opendaylight.transportpce.servicehandler.listeners.PceListenerImpl;
-import org.opendaylight.transportpce.servicehandler.listeners.RendererListenerImpl;
-import org.opendaylight.transportpce.servicehandler.listeners.ServiceListener;
 import org.opendaylight.transportpce.servicehandler.service.ServiceDataStoreOperations;
 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.networkmodel.rev201116.TransportpceNetworkmodelListener;
 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.TransportpcePceListener;
@@ -27,6 +25,10 @@ import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.service
 import org.opendaylight.yangtools.concepts.ListenerRegistration;
 import org.opendaylight.yangtools.concepts.ObjectRegistration;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+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.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -36,59 +38,48 @@ import org.slf4j.LoggerFactory;
  * @author Martial Coulibaly ( martial.coulibaly@gfi.com ) on behalf of Orange
  *
  */
+@Component
 public class ServicehandlerProvider {
 
     private static final Logger LOG = LoggerFactory.getLogger(ServicehandlerProvider.class);
     private static final InstanceIdentifier<Services> SERVICE = InstanceIdentifier.builder(ServiceList.class)
             .child(Services.class).build();
 
-    private final DataBroker dataBroker;
-    private final RpcProviderService rpcService;
-    private final NotificationService notificationService;
     private ListenerRegistration<TransportpcePceListener> pcelistenerRegistration;
-    private ListenerRegistration<ServiceListener> serviceDataTreeChangeListenerRegistration;
+    private ListenerRegistration<DataTreeChangeListener<Services>> serviceDataTreeChangeListenerRegistration;
     private ListenerRegistration<TransportpceRendererListener> rendererlistenerRegistration;
     private ListenerRegistration<TransportpceNetworkmodelListener> networkmodellistenerRegistration;
     private ObjectRegistration<OrgOpenroadmServiceService> rpcRegistration;
     private ServiceDataStoreOperations serviceDataStoreOperations;
-    private PceListenerImpl pceListenerImpl;
-    private ServiceListener serviceListener;
-    private RendererListenerImpl rendererListenerImpl;
-    private NetworkModelListenerImpl networkModelListenerImpl;
-    private ServicehandlerImpl servicehandler;
 
-    public ServicehandlerProvider(final DataBroker dataBroker, RpcProviderService rpcProviderService,
-            NotificationService notificationService, ServiceDataStoreOperations serviceDataStoreOperations,
-            PceListenerImpl pceListenerImpl, ServiceListener serviceListener, RendererListenerImpl rendererListenerImpl,
-            NetworkModelListenerImpl networkModelListenerImpl, ServicehandlerImpl servicehandler) {
-        this.dataBroker = dataBroker;
-        this.rpcService = rpcProviderService;
-        this.notificationService = notificationService;
+    @Activate
+    public ServicehandlerProvider(@Reference final DataBroker dataBroker,
+            @Reference RpcProviderService rpcProviderService,
+            @Reference NotificationService notificationService,
+            @Reference ServiceDataStoreOperations serviceDataStoreOperations,
+            @Reference TransportpcePceListener pceListenerImpl,
+            @Reference TransportpceRendererListener rendererListenerImpl,
+            @Reference TransportpceNetworkmodelListener networkModelListenerImpl,
+            @Reference NotificationPublishService notificationPublishService,
+            @Reference OrgOpenroadmServiceService servicehandler,
+            @Reference DataTreeChangeListener<Services> serviceListener) {
         this.serviceDataStoreOperations = serviceDataStoreOperations;
         this.serviceDataStoreOperations.initialize();
-        this.pceListenerImpl = pceListenerImpl;
-        this.serviceListener = serviceListener;
-        this.rendererListenerImpl = rendererListenerImpl;
-        this.networkModelListenerImpl = networkModelListenerImpl;
-        this.servicehandler = servicehandler;
-    }
-
-    /**
-     * Method called when the blueprint container is created.
-     */
-    public void init() {
-        LOG.info("ServicehandlerProvider Session Initiated");
         pcelistenerRegistration = notificationService.registerNotificationListener(pceListenerImpl);
-        serviceDataTreeChangeListenerRegistration = dataBroker.registerDataTreeChangeListener(
-                DataTreeIdentifier.create(LogicalDatastoreType.OPERATIONAL, SERVICE), serviceListener);
         rendererlistenerRegistration = notificationService.registerNotificationListener(rendererListenerImpl);
         networkmodellistenerRegistration = notificationService.registerNotificationListener(networkModelListenerImpl);
-        rpcRegistration = rpcService.registerRpcImplementation(OrgOpenroadmServiceService.class, servicehandler);
+        serviceDataTreeChangeListenerRegistration = dataBroker.registerDataTreeChangeListener(
+            DataTreeIdentifier.create(LogicalDatastoreType.OPERATIONAL, SERVICE), serviceListener);
+        rpcRegistration = rpcProviderService
+            .registerRpcImplementation(OrgOpenroadmServiceService.class, servicehandler);
+        LOG.info("ServicehandlerProvider Session Initiated");
+        LOG.info("Transportpce controller started");
     }
 
     /**
      * Method called when the blueprint container is destroyed.
      */
+    @Deactivate
     public void close() {
         LOG.info("ServicehandlerProvider Closed");
         pcelistenerRegistration.close();
@@ -97,5 +88,4 @@ public class ServicehandlerProvider {
         networkmodellistenerRegistration.close();
         rpcRegistration.close();
     }
-
-}
+}
\ No newline at end of file