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