9580550a077cb9f572c33986380e3e966308434d
[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.DataTreeChangeListener;
13 import org.opendaylight.mdsal.binding.api.DataTreeIdentifier;
14 import org.opendaylight.mdsal.binding.api.NotificationPublishService;
15 import org.opendaylight.mdsal.binding.api.NotificationService;
16 import org.opendaylight.mdsal.binding.api.RpcProviderService;
17 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
18 import org.opendaylight.transportpce.servicehandler.service.ServiceDataStoreOperations;
19 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.networkmodel.rev201116.TransportpceNetworkmodelListener;
20 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.TransportpcePceListener;
21 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.TransportpceRendererListener;
22 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.OrgOpenroadmServiceService;
23 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceList;
24 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.service.list.Services;
25 import org.opendaylight.yangtools.concepts.ListenerRegistration;
26 import org.opendaylight.yangtools.concepts.ObjectRegistration;
27 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
28 import org.osgi.service.component.annotations.Activate;
29 import org.osgi.service.component.annotations.Component;
30 import org.osgi.service.component.annotations.Deactivate;
31 import org.osgi.service.component.annotations.Reference;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
34
35 /**
36  * Class to register
37  * Servicehandler Service and Notification.
38  * @author Martial Coulibaly ( martial.coulibaly@gfi.com ) on behalf of Orange
39  *
40  */
41 @Component
42 public class ServicehandlerProvider {
43
44     private static final Logger LOG = LoggerFactory.getLogger(ServicehandlerProvider.class);
45     private static final InstanceIdentifier<Services> SERVICE = InstanceIdentifier.builder(ServiceList.class)
46             .child(Services.class).build();
47
48     private ListenerRegistration<TransportpcePceListener> pcelistenerRegistration;
49     private ListenerRegistration<DataTreeChangeListener<Services>> serviceDataTreeChangeListenerRegistration;
50     private ListenerRegistration<TransportpceRendererListener> rendererlistenerRegistration;
51     private ListenerRegistration<TransportpceNetworkmodelListener> networkmodellistenerRegistration;
52     private ObjectRegistration<OrgOpenroadmServiceService> rpcRegistration;
53     private ServiceDataStoreOperations serviceDataStoreOperations;
54
55     @Activate
56     public ServicehandlerProvider(@Reference final DataBroker dataBroker,
57             @Reference RpcProviderService rpcProviderService,
58             @Reference NotificationService notificationService,
59             @Reference ServiceDataStoreOperations serviceDataStoreOperations,
60             @Reference TransportpcePceListener pceListenerImpl,
61             @Reference TransportpceRendererListener rendererListenerImpl,
62             @Reference TransportpceNetworkmodelListener networkModelListenerImpl,
63             @Reference NotificationPublishService notificationPublishService,
64             @Reference OrgOpenroadmServiceService servicehandler,
65             @Reference DataTreeChangeListener<Services> serviceListener) {
66         this.serviceDataStoreOperations = serviceDataStoreOperations;
67         this.serviceDataStoreOperations.initialize();
68         pcelistenerRegistration = notificationService.registerNotificationListener(pceListenerImpl);
69         rendererlistenerRegistration = notificationService.registerNotificationListener(rendererListenerImpl);
70         networkmodellistenerRegistration = notificationService.registerNotificationListener(networkModelListenerImpl);
71         serviceDataTreeChangeListenerRegistration = dataBroker.registerDataTreeChangeListener(
72             DataTreeIdentifier.create(LogicalDatastoreType.OPERATIONAL, SERVICE), serviceListener);
73         rpcRegistration = rpcProviderService
74             .registerRpcImplementation(OrgOpenroadmServiceService.class, servicehandler);
75         LOG.info("ServicehandlerProvider Session Initiated");
76         LOG.info("Transportpce controller started");
77     }
78
79     /**
80      * Method called when the blueprint container is destroyed.
81      */
82     @Deactivate
83     public void close() {
84         LOG.info("ServicehandlerProvider Closed");
85         pcelistenerRegistration.close();
86         serviceDataTreeChangeListenerRegistration.close();
87         rendererlistenerRegistration.close();
88         networkmodellistenerRegistration.close();
89         rpcRegistration.close();
90     }
91 }