Merge changes I8295bb63,I628ef618,Ic7ebdea9,I21faea97
[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.mdsal.binding.api.DataBroker;
12 import org.opendaylight.mdsal.binding.api.NotificationService;
13 import org.opendaylight.mdsal.binding.api.RpcProviderService;
14 import org.opendaylight.transportpce.servicehandler.listeners.NetworkModelListenerImpl;
15 import org.opendaylight.transportpce.servicehandler.listeners.PceListenerImpl;
16 import org.opendaylight.transportpce.servicehandler.listeners.RendererListenerImpl;
17 import org.opendaylight.transportpce.servicehandler.service.ServiceDataStoreOperations;
18 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.networkmodel.rev201116.TransportpceNetworkmodelListener;
19 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev200128.TransportpcePceListener;
20 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev201125.TransportpceRendererListener;
21 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.OrgOpenroadmServiceService;
22 import org.opendaylight.yangtools.concepts.ListenerRegistration;
23 import org.opendaylight.yangtools.concepts.ObjectRegistration;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
26
27 /**
28  * Class to register
29  * Servicehandler Service and Notification.
30  * @author Martial Coulibaly ( martial.coulibaly@gfi.com ) on behalf of Orange
31  *
32  */
33 public class ServicehandlerProvider {
34
35     private static final Logger LOG = LoggerFactory.getLogger(ServicehandlerProvider.class);
36
37     private final DataBroker dataBroker;
38     private final RpcProviderService rpcService;
39     private final NotificationService notificationService;
40     private ListenerRegistration<TransportpcePceListener> pcelistenerRegistration;
41     private ListenerRegistration<TransportpceRendererListener> rendererlistenerRegistration;
42     private ListenerRegistration<TransportpceNetworkmodelListener> networkmodellistenerRegistration;
43     private ObjectRegistration<OrgOpenroadmServiceService> rpcRegistration;
44     private ServiceDataStoreOperations serviceDataStoreOperations;
45     private PceListenerImpl pceListenerImpl;
46     private RendererListenerImpl rendererListenerImpl;
47     private NetworkModelListenerImpl networkModelListenerImpl;
48     private ServicehandlerImpl servicehandler;
49
50
51     public ServicehandlerProvider(final DataBroker dataBroker, RpcProviderService rpcProviderService,
52             NotificationService notificationService, ServiceDataStoreOperations serviceDataStoreOperations,
53             PceListenerImpl pceListenerImpl, RendererListenerImpl rendererListenerImpl,
54             NetworkModelListenerImpl networkModelListenerImpl, ServicehandlerImpl servicehandler) {
55         this.dataBroker = dataBroker;
56         this.rpcService = rpcProviderService;
57         this.notificationService = notificationService;
58         this.serviceDataStoreOperations = serviceDataStoreOperations;
59         this.serviceDataStoreOperations.initialize();
60         this.pceListenerImpl = pceListenerImpl;
61         this.rendererListenerImpl = rendererListenerImpl;
62         this.networkModelListenerImpl = networkModelListenerImpl;
63         this.servicehandler = servicehandler;
64     }
65
66     /**
67      * Method called when the blueprint container is created.
68      */
69     public void init() {
70         LOG.info("ServicehandlerProvider Session Initiated");
71         pcelistenerRegistration = notificationService.registerNotificationListener(pceListenerImpl);
72         rendererlistenerRegistration = notificationService.registerNotificationListener(rendererListenerImpl);
73         networkmodellistenerRegistration = notificationService.registerNotificationListener(networkModelListenerImpl);
74         rpcRegistration = rpcService.registerRpcImplementation(OrgOpenroadmServiceService.class, servicehandler);
75     }
76
77     /**
78      * Method called when the blueprint container is destroyed.
79      */
80     public void close() {
81         LOG.info("ServicehandlerProvider Closed");
82         pcelistenerRegistration.close();
83         rendererlistenerRegistration.close();
84         networkmodellistenerRegistration.close();
85         rpcRegistration.close();
86     }
87
88 }