Remove static instantiations from RendererProvider
[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.DeviceRendererService;
12 import org.opendaylight.transportpce.renderer.provisiondevice.OtnDeviceRendererService;
13 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.TransportpceDeviceRendererService;
14 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.TransportpceRendererService;
15 import org.opendaylight.yangtools.concepts.ObjectRegistration;
16 import org.osgi.service.component.annotations.Activate;
17 import org.osgi.service.component.annotations.Component;
18 import org.osgi.service.component.annotations.Deactivate;
19 import org.osgi.service.component.annotations.Reference;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
22
23 @Component
24 public class RendererProvider {
25
26     private static final Logger LOG = LoggerFactory.getLogger(RendererProvider.class);
27     private final RpcProviderService rpcProviderService;
28     private ObjectRegistration<TransportpceDeviceRendererService> deviceRendererRegistration;
29     private ObjectRegistration<TransportpceRendererService> tpceServiceRegistry;
30
31     @Activate
32     public RendererProvider(@Reference RpcProviderService rpcProviderService,
33             @Reference DeviceRendererService deviceRenderer,
34             @Reference OtnDeviceRendererService otnDeviceRendererService,
35             @Reference TransportpceDeviceRendererService deviceRendererRPCImpl,
36             @Reference TransportpceRendererService transportPCEServicePathRPCImpl) {
37         this.rpcProviderService = rpcProviderService;
38         LOG.info("RendererProvider Session Initiated");
39         this.deviceRendererRegistration = this.rpcProviderService
40                 .registerRpcImplementation(TransportpceDeviceRendererService.class, deviceRendererRPCImpl);
41         this.tpceServiceRegistry = this.rpcProviderService
42                 .registerRpcImplementation(TransportpceRendererService.class, transportPCEServicePathRPCImpl);
43     }
44
45     /**
46      * Method called when the blueprint container is destroyed.
47      */
48     @Deactivate
49     public void close() {
50         LOG.info("RendererProvider Closed");
51         if (this.deviceRendererRegistration != null) {
52             this.deviceRendererRegistration.close();
53         }
54         if (this.tpceServiceRegistry != null) {
55             this.tpceServiceRegistry.close();
56         }
57     }
58 }