2 * ============LICENSE_START=======================================================
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
15 * http://www.apache.org/licenses/LICENSE-2.0
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.
23 * ============LICENSE_END=========================================================
26 package org.onap.appc.adapter.netconf;
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;
35 public class AppcNetconfAdapterActivator implements BundleActivator {
38 * The bundle registration
40 private ServiceRegistration registration = null;
41 private ServiceRegistration reporterRegistration = null;
42 private ServiceRegistration factoryRegistration = null;
43 private ServiceRegistration dbRegistration = null;
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.
49 * This method must complete and return to its caller in a timely manner.
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)
61 public void start(BundleContext context) throws Exception {
62 if (registration == null) {
64 * The reference to the actual implementation object that implements the services
66 NetconfClientFactory clientFactory = new NetconfClientFactory();
67 factoryRegistration = context.registerService(NetconfClientFactory.class, clientFactory, null);
68 NetconfDataAccessService dataAccessService = new NetconfDataAccessServiceImpl();
70 ServiceReference sref = context.getServiceReference(DbLibService.class.getName());
71 dataAccessService.setDbLibService((DbLibService)context.getService(sref));
73 factoryRegistration = context.registerService(NetconfDataAccessService.class, dataAccessService, null);
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.
83 * This method must complete and return to its caller in a timely manner.
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)
95 public void stop(BundleContext context) throws Exception {
96 if (registration != null) {
97 registration.unregister();
100 if (reporterRegistration != null) {
101 reporterRegistration.unregister();
102 reporterRegistration = null;
105 if (null != factoryRegistration) {
106 factoryRegistration.unregister();
107 factoryRegistration = null;
110 if (dbRegistration != null) {
111 dbRegistration.unregister();
112 dbRegistration = null;