Bump upstream dependencies to Ca
[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.NotificationService;
15 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
16 import org.opendaylight.transportpce.servicehandler.listeners.NetworkModelNotificationHandler;
17 import org.opendaylight.transportpce.servicehandler.listeners.PceNotificationHandler;
18 import org.opendaylight.transportpce.servicehandler.listeners.RendererNotificationHandler;
19 import org.opendaylight.transportpce.servicehandler.service.ServiceDataStoreOperations;
20 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceList;
21 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.service.list.Services;
22 import org.opendaylight.yangtools.concepts.Registration;
23 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
24 import org.osgi.service.component.annotations.Activate;
25 import org.osgi.service.component.annotations.Component;
26 import org.osgi.service.component.annotations.Deactivate;
27 import org.osgi.service.component.annotations.Reference;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
30
31 /**
32  * Class to register
33  * Servicehandler Service and Notification.
34  * @author Martial Coulibaly ( martial.coulibaly@gfi.com ) on behalf of Orange
35  *
36  */
37 @Component
38 public class ServiceHandlerProvider {
39
40     private static final Logger LOG = LoggerFactory.getLogger(ServiceHandlerProvider.class);
41     private static final InstanceIdentifier<Services> SERVICE = InstanceIdentifier.create(ServiceList.class)
42             .child(Services.class);
43
44     private final Registration pcelistenerRegistration;
45     private Registration serviceListListenerRegistration;
46     private final Registration rendererlistenerRegistration;
47     private final Registration networkmodellistenerRegistration;
48     private ServiceDataStoreOperations serviceDataStoreOperations;
49
50     @Activate
51     public ServiceHandlerProvider(@Reference final DataBroker dataBroker,
52             @Reference NotificationService notificationService,
53             @Reference ServiceDataStoreOperations serviceDataStoreOperations,
54             @Reference PceNotificationHandler pceNotificationHandler,
55             @Reference RendererNotificationHandler rendererNotificationHandler,
56             @Reference NetworkModelNotificationHandler networkModelNotificationHandler,
57             @Reference DataTreeChangeListener<Services> serviceListener) {
58         this.serviceDataStoreOperations = serviceDataStoreOperations;
59         this.serviceDataStoreOperations.initialize();
60         pcelistenerRegistration = notificationService
61             .registerCompositeListener(pceNotificationHandler.getCompositeListener());
62         rendererlistenerRegistration = notificationService
63             .registerCompositeListener(rendererNotificationHandler.getCompositeListener());
64         networkmodellistenerRegistration = notificationService
65             .registerCompositeListener(networkModelNotificationHandler.getCompositeListener());
66         final var serviceListId = DataTreeIdentifier.of(LogicalDatastoreType.OPERATIONAL, SERVICE);
67         serviceListListenerRegistration = dataBroker.registerTreeChangeListener(serviceListId, serviceListener);
68         LOG.info("ServicehandlerProvider Session Initiated");
69         LOG.info("Transportpce controller started");
70     }
71
72     /**
73      * Method called when the blueprint container is destroyed.
74      */
75     @Deactivate
76     public void close() {
77         LOG.info("ServicehandlerProvider Closed");
78         pcelistenerRegistration.close();
79         serviceListListenerRegistration.close();
80         rendererlistenerRegistration.close();
81         networkmodellistenerRegistration.close();
82     }
83 }