Interface D creation. NetworkModel->ServiceHandler
[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.NetworkModelListenerImpl;
18 import org.opendaylight.transportpce.servicehandler.listeners.PceListenerImpl;
19 import org.opendaylight.transportpce.servicehandler.listeners.RendererListenerImpl;
20 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.networkmodel.rev201116.TransportpceNetworkmodelListener;
21 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev200128.TransportpcePceListener;
22 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev201125.TransportpceRendererListener;
23 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.OrgOpenroadmServiceService;
24 import org.opendaylight.yangtools.concepts.ListenerRegistration;
25 import org.opendaylight.yangtools.concepts.ObjectRegistration;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
28
29 /**
30  * Class to register
31  * Servicehandler Service and Notification.
32  * @author Martial Coulibaly ( martial.coulibaly@gfi.com ) on behalf of Orange
33  *
34  */
35 public class ServicehandlerProvider {
36
37     private static final Logger LOG = LoggerFactory.getLogger(ServicehandlerProvider.class);
38
39     private final DataBroker dataBroker;
40     private final RpcProviderService rpcService;
41     private final NotificationService notificationService;
42     private final NotificationPublishService notificationPublishService;
43     private ListenerRegistration<TransportpcePceListener> pcelistenerRegistration;
44     private ListenerRegistration<TransportpceRendererListener> rendererlistenerRegistration;
45     private ListenerRegistration<TransportpceNetworkmodelListener> networkmodellistenerRegistration;
46     private ObjectRegistration<OrgOpenroadmServiceService> rpcRegistration;
47     private PathComputationService pathComputationService;
48     private RendererServiceOperations rendererServiceOperations;
49
50     public ServicehandlerProvider(final DataBroker dataBroker, RpcProviderService rpcProviderService,
51             NotificationService notificationService, PathComputationService pathComputationService,
52             RendererServiceOperations rendererServiceOperations,
53             NotificationPublishService notificationPublishService) {
54         this.dataBroker = dataBroker;
55         this.rpcService = rpcProviderService;
56         this.notificationService = notificationService;
57         this.pathComputationService = pathComputationService;
58         this.rendererServiceOperations = rendererServiceOperations;
59         this.notificationPublishService = notificationPublishService;
60     }
61
62     /**
63      * Method called when the blueprint container is created.
64      */
65     public void init() {
66         LOG.info("ServicehandlerProvider Session Initiated");
67         final PceListenerImpl pceListenerImpl = new PceListenerImpl(rendererServiceOperations,
68                 pathComputationService, notificationPublishService, null);
69         final RendererListenerImpl rendererListenerImpl =
70                 new RendererListenerImpl(pathComputationService, notificationPublishService);
71         final NetworkModelListenerImpl networkModelListenerImpl =
72                 new NetworkModelListenerImpl(notificationPublishService, null);
73         pcelistenerRegistration = notificationService.registerNotificationListener(pceListenerImpl);
74         rendererlistenerRegistration = notificationService.registerNotificationListener(rendererListenerImpl);
75         networkmodellistenerRegistration = notificationService.registerNotificationListener(networkModelListenerImpl);
76         final ServicehandlerImpl servicehandler = new ServicehandlerImpl(dataBroker, pathComputationService,
77                 rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl,
78                 networkModelListenerImpl);
79         rpcRegistration =
80             rpcService.registerRpcImplementation(OrgOpenroadmServiceService.class, servicehandler);
81     }
82
83     /**
84      * Method called when the blueprint container is destroyed.
85      */
86     public void close() {
87         LOG.info("ServicehandlerProvider Closed");
88         pcelistenerRegistration.close();
89         rendererlistenerRegistration.close();
90         networkmodellistenerRegistration.close();
91         rpcRegistration.close();
92     }
93
94 }