Changed to unmaintained
[appc.git] / appc-adapters / appc-netconf-adapter / appc-netconf-adapter-bundle / src / main / java / org / onap / appc / adapter / netconf / AppcNetconfAdapterActivator.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
4  * ================================================================================
5  * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Copyright (C) 2017 Amdocs
8  * ================================================================================
9  * Modifications Copyright (C) 2019 Ericsson
10  * =============================================================================
11  * Licensed under the Apache License, Version 2.0 (the "License");
12  * you may not use this file except in compliance with the License.
13  * You may obtain a copy of the License at
14  * 
15  *      http://www.apache.org/licenses/LICENSE-2.0
16  * 
17  * Unless required by applicable law or agreed to in writing, software
18  * distributed under the License is distributed on an "AS IS" BASIS,
19  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20  * See the License for the specific language governing permissions and
21  * limitations under the License.
22  * 
23  * ============LICENSE_END=========================================================
24  */
25
26 package org.onap.appc.adapter.netconf;
27
28 import org.onap.appc.adapter.netconf.internal.NetconfDataAccessServiceImpl;
29 import org.onap.ccsdk.sli.core.dblib.DbLibService;
30 import org.osgi.framework.BundleActivator;
31 import org.osgi.framework.BundleContext;
32 import org.osgi.framework.ServiceReference;
33 import org.osgi.framework.ServiceRegistration;
34
35 public class AppcNetconfAdapterActivator implements BundleActivator {
36
37     /**
38      * The bundle registration
39      */
40     private ServiceRegistration registration = null;
41     private ServiceRegistration reporterRegistration = null;
42     private ServiceRegistration factoryRegistration = null;
43     private ServiceRegistration dbRegistration = null;
44
45     /**
46      * Called when this bundle is started so the Framework can perform the bundle-specific activities necessary to start
47      * this bundle. This method can be used to register services or to allocate any resources that this bundle needs.
48      * <p>
49      * This method must complete and return to its caller in a timely manner.
50      * </p>
51      *
52      * @param context
53      *            The execution context of the bundle being started.
54      * @throws java.lang.Exception
55      *             If this method throws an exception, this bundle is marked as stopped and the Framework will remove
56      *             this bundle's listeners, unregister all services registered by this bundle, and release all services
57      *             used by this bundle.
58      * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
59      */
60     @Override
61     public void start(BundleContext context) throws Exception {
62         if (registration == null) {
63             /*
64             * The reference to the actual implementation object that implements the services
65             */
66             NetconfClientFactory clientFactory = new NetconfClientFactory();
67             factoryRegistration = context.registerService(NetconfClientFactory.class, clientFactory, null);
68             NetconfDataAccessService dataAccessService = new NetconfDataAccessServiceImpl();
69             //set dblib service
70             ServiceReference sref = context.getServiceReference(DbLibService.class.getName());
71             dataAccessService.setDbLibService((DbLibService)context.getService(sref));
72
73             factoryRegistration = context.registerService(NetconfDataAccessService.class, dataAccessService, null);
74         }
75     }
76
77     /**
78      * Called when this bundle is stopped so the Framework can perform the bundle-specific activities necessary to stop
79      * the bundle. In general, this method should undo the work that the BundleActivator.start method started. There
80      * should be no active threads that were started by this bundle when this bundle returns. A stopped bundle must not
81      * call any Framework objects.
82      * <p>
83      * This method must complete and return to its caller in a timely manner.
84      * </p>
85      *
86      * @param context
87      *            The execution context of the bundle being stopped.
88      * @throws java.lang.Exception
89      *             If this method throws an exception, the bundle is still marked as stopped, and the Framework will
90      *             remove the bundle's listeners, unregister all services registered by the bundle, and release all
91      *             services used by the bundle. *
92      * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
93      */
94     @Override
95     public void stop(BundleContext context) throws Exception {
96         if (registration != null) {
97             registration.unregister();
98             registration = null;
99         }
100         if (reporterRegistration != null) {
101             reporterRegistration.unregister();
102             reporterRegistration = null;
103         }
104
105         if (null != factoryRegistration) {
106             factoryRegistration.unregister();
107             factoryRegistration = null;
108         }
109
110         if (dbRegistration != null) {
111             dbRegistration.unregister();
112             dbRegistration = null;
113         }
114     }
115 }