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