0fcdf8ed30d66b5cbef45467f33a5041e9d1d3f5
[transportpce.git] / renderer / src / main / java / org / opendaylight / transportpce / renderer / RendererProvider.java
1 /*
2  * Copyright © 2017 AT&T 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 package org.opendaylight.transportpce.renderer;
9
10 import org.opendaylight.mdsal.binding.api.RpcProviderService;
11 import org.opendaylight.transportpce.renderer.provisiondevice.RendererServiceOperations;
12 import org.opendaylight.transportpce.renderer.rpcs.DeviceRendererRPCImpl;
13 import org.opendaylight.transportpce.renderer.rpcs.TransportPCEServicePathRPCImpl;
14 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev210618.TransportpceDeviceRendererService;
15 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.TransportpceRendererService;
16 import org.opendaylight.yangtools.concepts.ObjectRegistration;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
19
20 public class RendererProvider {
21
22     private static final Logger LOG = LoggerFactory.getLogger(RendererProvider.class);
23     private final RpcProviderService rpcProviderService;
24     private DeviceRendererRPCImpl deviceRendererRPCImpl;
25     private ObjectRegistration<DeviceRendererRPCImpl> deviceRendererRegistration;
26     private ObjectRegistration<TransportpceRendererService> tpceServiceRegistry;
27     private RendererServiceOperations rendererServiceOperations;
28
29     public RendererProvider(RpcProviderService rpcProviderService, DeviceRendererRPCImpl deviceRendererRPCImpl,
30             RendererServiceOperations rendererServiceOperations) {
31         this.rpcProviderService = rpcProviderService;
32         this.deviceRendererRPCImpl = deviceRendererRPCImpl;
33         this.rendererServiceOperations = rendererServiceOperations;
34     }
35
36     /**
37      * Method called when the blueprint container is created.
38      */
39     public void init() {
40         LOG.info("RendererProvider Session Initiated");
41         TransportPCEServicePathRPCImpl transportPCEServicePathRPCImpl =
42             new TransportPCEServicePathRPCImpl(this.rendererServiceOperations);
43         this.deviceRendererRegistration = this.rpcProviderService
44                 .registerRpcImplementation(TransportpceDeviceRendererService.class, deviceRendererRPCImpl);
45         this.tpceServiceRegistry = this.rpcProviderService
46                 .registerRpcImplementation(TransportpceRendererService.class, transportPCEServicePathRPCImpl);
47     }
48
49     /**
50      * Method called when the blueprint container is destroyed.
51      */
52     public void close() {
53         LOG.info("RendererProvider Closed");
54         if (this.deviceRendererRegistration != null) {
55             this.deviceRendererRegistration.close();
56         }
57         if (this.tpceServiceRegistry != null) {
58             this.tpceServiceRegistry.close();
59         }
60     }
61
62 }