ServiceHandler update for new PCE compatibility
[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.controller.md.sal.binding.api.DataBroker;
12 import org.opendaylight.controller.md.sal.binding.api.NotificationService;
13 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RpcRegistration;
14 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
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.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev170426.PceListener;
19 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.OrgOpenroadmServiceService;
20 import org.opendaylight.yangtools.concepts.ListenerRegistration;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
23
24 /**
25  * Class to register
26  * Servicehandler Service and Notification.
27  * @author Martial Coulibaly ( martial.coulibaly@gfi.com ) on behalf of Orange
28  *
29  */
30 public class ServicehandlerProvider {
31
32     private static final Logger LOG = LoggerFactory.getLogger(ServicehandlerProvider.class);
33
34     private final DataBroker dataBroker;
35     private final RpcProviderRegistry rpcRegistry;
36     private final NotificationService notificationService;
37     private ListenerRegistration<PceListener> pcelistenerRegistration;
38     private RpcRegistration<OrgOpenroadmServiceService> rpcRegistration;
39     private PathComputationService pathComputationService;
40     private RendererServiceOperations rendererServiceOperations;
41
42     public ServicehandlerProvider(final DataBroker dataBroker, RpcProviderRegistry rpcProviderRegistry,
43             NotificationService notificationService, PathComputationService pathComputationService,
44             RendererServiceOperations rendererServiceOperations) {
45         this.dataBroker = dataBroker;
46         this.rpcRegistry = rpcProviderRegistry;
47         this.notificationService = notificationService;
48         this.pathComputationService = pathComputationService;
49         this.rendererServiceOperations = rendererServiceOperations;
50     }
51
52     /**
53      * Method called when the blueprint container is created.
54      */
55     public void init() {
56         LOG.info("ServicehandlerProvider Session Initiated");
57         final ServicehandlerImpl servicehandler = new ServicehandlerImpl(dataBroker, pathComputationService,
58                 rendererServiceOperations);
59         final PceListenerImpl pceListener = new PceListenerImpl();
60         pcelistenerRegistration = notificationService.registerNotificationListener(pceListener);
61         rpcRegistration = rpcRegistry.addRpcImplementation(OrgOpenroadmServiceService.class, servicehandler);
62     }
63
64     /**
65      * Method called when the blueprint container is destroyed.
66      */
67     public void close() {
68         LOG.info("ServicehandlerProvider Closed");
69         pcelistenerRegistration.close();
70         rpcRegistration.close();
71     }
72
73 }