Catalog RPC Implementation
[transportpce.git] / servicehandler / src / main / java / org / opendaylight / transportpce / servicehandler / impl / ServicehandlerProvider.java
index 29e838d16d1047921735fc94e1e7f1c50d94d967..b77e18eaa7f941a17ddb4491644585ae0963720a 100644 (file)
@@ -8,15 +8,26 @@
 
 package org.opendaylight.transportpce.servicehandler.impl;
 
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
-import org.opendaylight.controller.md.sal.binding.api.NotificationService;
-import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RpcRegistration;
-import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.servicehandler.rev161014.ServicehandlerService;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubpce.rev170426.StubpceListener;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubrenderer.rev170426.StubrendererListener;
+import org.opendaylight.mdsal.binding.api.DataBroker;
+import org.opendaylight.mdsal.binding.api.DataTreeIdentifier;
+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.catalog.CatalogDataStoreOperations;
+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;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.TransportpceRendererListener;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.OrgOpenroadmServiceService;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceList;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.service.list.Services;
 import org.opendaylight.yangtools.concepts.ListenerRegistration;
+import org.opendaylight.yangtools.concepts.ObjectRegistration;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -29,26 +40,41 @@ import org.slf4j.LoggerFactory;
 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 RpcProviderRegistry rpcRegistry;
+    private final RpcProviderService rpcService;
     private final NotificationService notificationService;
-    private final NotificationPublishService notificationPublishService;
+    private ListenerRegistration<TransportpcePceListener> pcelistenerRegistration;
+    private ListenerRegistration<ServiceListener> serviceDataTreeChangeListenerRegistration;
+    private ListenerRegistration<TransportpceRendererListener> rendererlistenerRegistration;
+    private ListenerRegistration<TransportpceNetworkmodelListener> networkmodellistenerRegistration;
+    private ObjectRegistration<OrgOpenroadmServiceService> rpcRegistration;
+    private ServiceDataStoreOperations serviceDataStoreOperations;
+    private CatalogDataStoreOperations catalogDataStoreOperations;
+    private PceListenerImpl pceListenerImpl;
+    private ServiceListener serviceListener;
+    private RendererListenerImpl rendererListenerImpl;
+    private NetworkModelListenerImpl networkModelListenerImpl;
+    private ServicehandlerImpl servicehandler;
 
-    //private ListenerRegistration<ServicehandlerListener> ServicehandlerlistenerRegistration;
-    /* Listener register for StubPce Notification. */
-    private ListenerRegistration<StubpceListener> stubPcelistenerRegistration;
-    /* Listener register for StubRender Notification. */
-    private ListenerRegistration<StubrendererListener> stubRendererlistenerRegistration;
-    private RpcRegistration<ServicehandlerService> rpcRegistration;
-
-
-    public ServicehandlerProvider(final DataBroker dataBroker, RpcProviderRegistry rpcProviderRegistry,
-            NotificationService notificationService, NotificationPublishService notificationPublishService) {
+    public ServicehandlerProvider(final DataBroker dataBroker, RpcProviderService rpcProviderService,
+            NotificationService notificationService, ServiceDataStoreOperations serviceDataStoreOperations,
+            PceListenerImpl pceListenerImpl, ServiceListener serviceListener, RendererListenerImpl rendererListenerImpl,
+            NetworkModelListenerImpl networkModelListenerImpl, ServicehandlerImpl servicehandler,
+                                  CatalogDataStoreOperations catalogDataStoreOperations) {
         this.dataBroker = dataBroker;
-        this.rpcRegistry = rpcProviderRegistry;
+        this.rpcService = rpcProviderService;
         this.notificationService = notificationService;
-        this.notificationPublishService = notificationPublishService;
+        this.serviceDataStoreOperations = serviceDataStoreOperations;
+        this.serviceDataStoreOperations.initialize();
+        this.pceListenerImpl = pceListenerImpl;
+        this.serviceListener = serviceListener;
+        this.rendererListenerImpl = rendererListenerImpl;
+        this.networkModelListenerImpl = networkModelListenerImpl;
+        this.servicehandler = servicehandler;
+        this.catalogDataStoreOperations = catalogDataStoreOperations;
     }
 
     /**
@@ -56,10 +82,12 @@ public class ServicehandlerProvider {
      */
     public void init() {
         LOG.info("ServicehandlerProvider Session Initiated");
-        final ServicehandlerImpl consumer = new ServicehandlerImpl(dataBroker, rpcRegistry, notificationPublishService);
-        stubPcelistenerRegistration = notificationService.registerNotificationListener(consumer);
-        stubRendererlistenerRegistration = notificationService.registerNotificationListener(consumer);
-        rpcRegistration = rpcRegistry.addRpcImplementation(ServicehandlerService.class, consumer);
+        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);
     }
 
     /**
@@ -67,8 +95,11 @@ public class ServicehandlerProvider {
      */
     public void close() {
         LOG.info("ServicehandlerProvider Closed");
-        stubPcelistenerRegistration.close();
-        stubRendererlistenerRegistration.close();
+        pcelistenerRegistration.close();
+        serviceDataTreeChangeListenerRegistration.close();
+        rendererlistenerRegistration.close();
+        networkmodellistenerRegistration.close();
         rpcRegistration.close();
     }
+
 }