Added code for renderer to:
[transportpce.git] / renderer / src / main / java / org / opendaylight / transportpce / renderer / RendererProvider.java
index 66eee2251f66766c8f160eab9238cac59b8b8b80..2f6ede4126a7c36d9417fdea7a33f41a981a7797 100644 (file)
@@ -1,30 +1,44 @@
 /*
- * Copyright © 2016 Orange and others.  All rights reserved.
+ * Copyright © 2017 AT&T and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * 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.transportpce.renderer;
 
+import java.util.HashSet;
+import java.util.Set;
+
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.MountPointService;
-
-
+import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RpcRegistration;
+import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
+import org.opendaylight.transportpce.renderer.provisiondevice.DeviceRenderer;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.renderer.rev170228.RendererService;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 public class RendererProvider {
 
     private static final Logger LOG = LoggerFactory.getLogger(RendererProvider.class);
-
     private final DataBroker dataBroker;
-
     private final MountPointService mountPointService;
+    private final RpcProviderRegistry rpcProviderRegistry;
+    private RendererNotificationsImpl rendererNotificationImpl;
+    private RpcRegistration<RendererService> deviceRendererRegistration;
+    private final Set<String> currentMountedDevice;
 
-    public RendererProvider(final DataBroker dataBroker, final MountPointService mountPointService) {
+    public RendererProvider(final DataBroker dataBroker, final MountPointService mountPointService,
+        final RpcProviderRegistry rpcProviderRegistry) {
         this.dataBroker = dataBroker;
         this.mountPointService = mountPointService;
+        this.rpcProviderRegistry = rpcProviderRegistry;
+        this.currentMountedDevice = new HashSet<>();
+        if (mountPointService == null) {
+            LOG.error("Mount service is null");
+        }
     }
 
     /**
@@ -32,6 +46,12 @@ public class RendererProvider {
      */
     public void init() {
         LOG.info("RendererProvider Session Initiated");
+        // Initializing Notification module
+        rendererNotificationImpl = new RendererNotificationsImpl(dataBroker, mountPointService,
+            currentMountedDevice);
+        //Register REST API RPC implementation for Renderer Service
+        deviceRendererRegistration = rpcProviderRegistry.addRpcImplementation(RendererService.class, new DeviceRenderer(
+            dataBroker, mountPointService, currentMountedDevice));
     }
 
     /**
@@ -39,5 +59,13 @@ public class RendererProvider {
      */
     public void close() {
         LOG.info("RendererProvider Closed");
+        // Clean up the RPC service registration
+        if (deviceRendererRegistration != null) {
+            deviceRendererRegistration.close();
+        }
+        // Clean up the RendererNotificationsImpl
+        if (rendererNotificationImpl != null) {
+            rendererNotificationImpl.close();
+        }
     }
-}
+}
\ No newline at end of file