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