ec1e2f55649c13085795b59eac4dac554a814efa
[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.NotificationPublishService;
13 import org.opendaylight.mdsal.binding.api.NotificationService;
14 import org.opendaylight.mdsal.binding.api.RpcProviderService;
15 import org.opendaylight.transportpce.pce.service.PathComputationService;
16 import org.opendaylight.transportpce.renderer.provisiondevice.RendererServiceOperations;
17 import org.opendaylight.transportpce.servicehandler.listeners.PceListenerImpl;
18 import org.opendaylight.transportpce.servicehandler.listeners.RendererListenerImpl;
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 final NotificationPublishService notificationPublishService;
41     private ListenerRegistration<TransportpcePceListener> pcelistenerRegistration;
42     private ListenerRegistration<TransportpceRendererListener> rendererlistenerRegistration;
43     private ObjectRegistration<OrgOpenroadmServiceService> rpcRegistration;
44     private PathComputationService pathComputationService;
45     private RendererServiceOperations rendererServiceOperations;
46
47     public ServicehandlerProvider(final DataBroker dataBroker, RpcProviderService rpcProviderService,
48             NotificationService notificationService, PathComputationService pathComputationService,
49             RendererServiceOperations rendererServiceOperations,
50             NotificationPublishService notificationPublishService) {
51         this.dataBroker = dataBroker;
52         this.rpcService = rpcProviderService;
53         this.notificationService = notificationService;
54         this.pathComputationService = pathComputationService;
55         this.rendererServiceOperations = rendererServiceOperations;
56         this.notificationPublishService = notificationPublishService;
57     }
58
59     /**
60      * Method called when the blueprint container is created.
61      */
62     public void init() {
63         LOG.info("ServicehandlerProvider Session Initiated");
64         final PceListenerImpl pceListenerImpl = new PceListenerImpl(rendererServiceOperations,
65                 pathComputationService, notificationPublishService, null);
66         final RendererListenerImpl rendererListenerImpl =
67                 new RendererListenerImpl(pathComputationService, notificationPublishService);
68         pcelistenerRegistration = notificationService.registerNotificationListener(pceListenerImpl);
69         rendererlistenerRegistration = notificationService.registerNotificationListener(rendererListenerImpl);
70         final ServicehandlerImpl servicehandler = new ServicehandlerImpl(dataBroker, pathComputationService,
71                 rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl);
72         rpcRegistration =
73             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         rpcRegistration.close();
84     }
85
86 }