bd7564419d3a0f416b60c05dbd31b3fff72a7b63
[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     public ServicehandlerProvider(final DataBroker dataBroker, RpcProviderService rpcProviderService,
51             NotificationService notificationService, ServiceDataStoreOperations serviceDataStoreOperations,
52             PceListenerImpl pceListenerImpl, RendererListenerImpl rendererListenerImpl,
53             NetworkModelListenerImpl networkModelListenerImpl, ServicehandlerImpl servicehandler) {
54         this.dataBroker = dataBroker;
55         this.rpcService = rpcProviderService;
56         this.notificationService = notificationService;
57         this.serviceDataStoreOperations = serviceDataStoreOperations;
58         this.serviceDataStoreOperations.initialize();
59         this.pceListenerImpl = pceListenerImpl;
60         this.rendererListenerImpl = rendererListenerImpl;
61         this.networkModelListenerImpl = networkModelListenerImpl;
62         this.servicehandler = servicehandler;
63     }
64
65     /**
66      * Method called when the blueprint container is created.
67      */
68     public void init() {
69         LOG.info("ServicehandlerProvider Session Initiated");
70         pcelistenerRegistration = notificationService.registerNotificationListener(pceListenerImpl);
71         rendererlistenerRegistration = notificationService.registerNotificationListener(rendererListenerImpl);
72         networkmodellistenerRegistration = notificationService.registerNotificationListener(networkModelListenerImpl);
73         rpcRegistration = rpcService.registerRpcImplementation(OrgOpenroadmServiceService.class, servicehandler);
74     }
75
76     /**
77      * Method called when the blueprint container is destroyed.
78      */
79     public void close() {
80         LOG.info("ServicehandlerProvider Closed");
81         pcelistenerRegistration.close();
82         rendererlistenerRegistration.close();
83         networkmodellistenerRegistration.close();
84         rpcRegistration.close();
85     }
86
87 }