Initial commit for ServiceHandler
[transportpce.git] / servicehandler / src / main / java / org / opendaylight / transportpce / servicehandler / impl / ServicehandlerProvider.java
1 /*
2  * Copyright © 2017 Orange, Inc. 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.servicehandler.impl;
10
11 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
12 import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
13 import org.opendaylight.controller.md.sal.binding.api.NotificationService;
14 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RpcRegistration;
15 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
16 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.servicehandler.rev161014.ServicehandlerService;
17 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubpce.rev170426.StubpceListener;
18 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubrenderer.rev170426.StubrendererListener;
19 import org.opendaylight.yangtools.concepts.ListenerRegistration;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
22
23 /*
24  * Class to register
25  * Servicehandler Service and Notification.
26  * @author Martial Coulibaly ( martial.coulibaly@gfi.com ) on behalf of Orange
27  *
28  */
29 public class ServicehandlerProvider {
30
31     private static final Logger LOG = LoggerFactory.getLogger(ServicehandlerProvider.class);
32
33     private final DataBroker dataBroker;
34     private final RpcProviderRegistry rpcRegistry;
35     private final NotificationService notificationService;
36     private final NotificationPublishService notificationPublishService;
37
38     //private ListenerRegistration<ServicehandlerListener> ServicehandlerlistenerRegistration;
39     /* Listener register for StubPce Notification. */
40     private ListenerRegistration<StubpceListener> stubPcelistenerRegistration;
41     /* Listener register for StubRender Notification. */
42     private ListenerRegistration<StubrendererListener> stubRendererlistenerRegistration;
43     private RpcRegistration<ServicehandlerService> rpcRegistration;
44
45
46     public ServicehandlerProvider(final DataBroker dataBroker, RpcProviderRegistry rpcProviderRegistry,
47             NotificationService notificationService, NotificationPublishService notificationPublishService) {
48         this.dataBroker = dataBroker;
49         this.rpcRegistry = rpcProviderRegistry;
50         this.notificationService = notificationService;
51         this.notificationPublishService = notificationPublishService;
52     }
53
54     /*
55      * Method called when the blueprint container is created.
56      */
57     public void init() {
58         LOG.info("ServicehandlerProvider Session Initiated");
59         final ServicehandlerImpl consumer = new ServicehandlerImpl(dataBroker, rpcRegistry, notificationPublishService);
60         stubPcelistenerRegistration = notificationService.registerNotificationListener(consumer);
61         stubRendererlistenerRegistration = notificationService.registerNotificationListener(consumer);
62         rpcRegistration = rpcRegistry.addRpcImplementation(ServicehandlerService.class, consumer);
63     }
64
65     /*
66      * Method called when the blueprint container is destroyed.
67      */
68     public void close() {
69         LOG.info("ServicehandlerProvider Closed");
70         stubPcelistenerRegistration.close();
71         stubRendererlistenerRegistration.close();
72         rpcRegistration.close();
73     }
74 }