Added code for renderer to:
[transportpce.git] / renderer / src / main / java / org / opendaylight / transportpce / renderer / RendererProvider.java
1 /*
2  * Copyright © 2017 AT&T and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.transportpce.renderer;
10
11 import java.util.HashSet;
12 import java.util.Set;
13
14 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
15 import org.opendaylight.controller.md.sal.binding.api.MountPointService;
16 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RpcRegistration;
17 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
18 import org.opendaylight.transportpce.renderer.provisiondevice.DeviceRenderer;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.renderer.rev170228.RendererService;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
22
23 public class RendererProvider {
24
25     private static final Logger LOG = LoggerFactory.getLogger(RendererProvider.class);
26     private final DataBroker dataBroker;
27     private final MountPointService mountPointService;
28     private final RpcProviderRegistry rpcProviderRegistry;
29     private RendererNotificationsImpl rendererNotificationImpl;
30     private RpcRegistration<RendererService> deviceRendererRegistration;
31     private final Set<String> currentMountedDevice;
32
33     public RendererProvider(final DataBroker dataBroker, final MountPointService mountPointService,
34         final RpcProviderRegistry rpcProviderRegistry) {
35         this.dataBroker = dataBroker;
36         this.mountPointService = mountPointService;
37         this.rpcProviderRegistry = rpcProviderRegistry;
38         this.currentMountedDevice = new HashSet<>();
39         if (mountPointService == null) {
40             LOG.error("Mount service is null");
41         }
42     }
43
44     /**
45      * Method called when the blueprint container is created.
46      */
47     public void init() {
48         LOG.info("RendererProvider Session Initiated");
49         // Initializing Notification module
50         rendererNotificationImpl = new RendererNotificationsImpl(dataBroker, mountPointService,
51             currentMountedDevice);
52         //Register REST API RPC implementation for Renderer Service
53         deviceRendererRegistration = rpcProviderRegistry.addRpcImplementation(RendererService.class, new DeviceRenderer(
54             dataBroker, mountPointService, currentMountedDevice));
55     }
56
57     /**
58      * Method called when the blueprint container is destroyed.
59      */
60     public void close() {
61         LOG.info("RendererProvider Closed");
62         // Clean up the RPC service registration
63         if (deviceRendererRegistration != null) {
64             deviceRendererRegistration.close();
65         }
66         // Clean up the RendererNotificationsImpl
67         if (rendererNotificationImpl != null) {
68             rendererNotificationImpl.close();
69         }
70     }
71 }