f2b9fbe51b3b06a9bbfacb78aaf3222ed2b8fb3d
[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.stubpce.rev170426.StubpceListener;
17 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubrenderer.rev170426.StubrendererListener;
18 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.OrgOpenroadmServiceService;
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  *
27  * @author <a href="mailto:martial.coulibaly@gfi.com">Martial Coulibaly</a> on behalf of Orange
28  *
29  */
30 public class ServicehandlerProvider {
31
32     private static final Logger LOG = LoggerFactory.getLogger(ServicehandlerProvider.class);
33
34     private final DataBroker dataBroker;
35     private final RpcProviderRegistry rpcRegistry;
36     private final NotificationService notificationService;
37     private final NotificationPublishService notificationPublishService;
38
39     /** Listener register for TransportpceService Notification. */
40     private ListenerRegistration<StubpceListener> stubpcelistenerRegistration;
41     private ListenerRegistration<StubrendererListener> stubrendererlistenerRegistration;
42     private RpcRegistration<OrgOpenroadmServiceService> rpcRegistration;
43
44
45     public ServicehandlerProvider(final DataBroker dataBroker, RpcProviderRegistry rpcProviderRegistry,
46             NotificationService notificationService, NotificationPublishService notificationPublishService) {
47         this.dataBroker = dataBroker;
48         this.rpcRegistry = rpcProviderRegistry;
49         this.notificationService = notificationService;
50         this.notificationPublishService = notificationPublishService;
51     }
52
53     /**
54      * Method called when the blueprint container is created.
55      */
56     public void init() {
57         LOG.info("ServicehandlerProvider Session Initiated");
58         final ServicehandlerImpl consumer = new ServicehandlerImpl(dataBroker, rpcRegistry, notificationPublishService);
59         stubpcelistenerRegistration = notificationService.registerNotificationListener(consumer);
60         stubrendererlistenerRegistration = notificationService.registerNotificationListener(consumer);
61         rpcRegistration = rpcRegistry.addRpcImplementation(OrgOpenroadmServiceService.class, consumer);
62     }
63
64     /**
65      * Method called when the blueprint container is destroyed.
66      */
67     public void close() {
68         LOG.info("ServicehandlerProvider Closed");
69         stubpcelistenerRegistration.close();
70         stubrendererlistenerRegistration.close();
71         rpcRegistration.close();
72     }
73 }