2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 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 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 * ============LICENSE_END=========================================================
25 package org.onap.appc.adapter.netconf;
27 import org.onap.appc.adapter.netconf.internal.NetconfDataAccessServiceImpl;
28 import org.onap.ccsdk.sli.core.dblib.DbLibService;
29 import org.osgi.framework.BundleActivator;
30 import org.osgi.framework.BundleContext;
31 import org.osgi.framework.ServiceReference;
32 import org.osgi.framework.ServiceRegistration;
34 public class AppcNetconfAdapterActivator implements BundleActivator {
37 * The bundle registration
39 private ServiceRegistration registration = null;
40 private ServiceRegistration reporterRegistration = null;
41 private ServiceRegistration factoryRegistration = null;
42 private ServiceRegistration dbRegistration = null;
45 * Called when this bundle is started so the Framework can perform the bundle-specific activities necessary to start
46 * this bundle. This method can be used to register services or to allocate any resources that this bundle needs.
48 * This method must complete and return to its caller in a timely manner.
52 * The execution context of the bundle being started.
53 * @throws java.lang.Exception
54 * If this method throws an exception, this bundle is marked as stopped and the Framework will remove
55 * this bundle's listeners, unregister all services registered by this bundle, and release all services
56 * used by this bundle.
57 * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
60 public void start(BundleContext context) throws Exception {
61 if (registration == null) {
63 * The reference to the actual implementation object that implements the services
65 NetconfClientFactory clientFactory = new NetconfClientFactory();
66 factoryRegistration = context.registerService(NetconfClientFactory.class, clientFactory, null);
67 NetconfDataAccessService dataAccessService = new NetconfDataAccessServiceImpl();
69 ServiceReference sref = context.getServiceReference(DbLibService.class.getName());
70 dataAccessService.setDbLibService((DbLibService)context.getService(sref));
71 ///////////////////////////////////
72 factoryRegistration = context.registerService(NetconfDataAccessService.class, dataAccessService, null);
77 * Called when this bundle is stopped so the Framework can perform the bundle-specific activities necessary to stop
78 * the bundle. In general, this method should undo the work that the BundleActivator.start method started. There
79 * should be no active threads that were started by this bundle when this bundle returns. A stopped bundle must not
80 * call any Framework objects.
82 * This method must complete and return to its caller in a timely manner.
86 * The execution context of the bundle being stopped.
87 * @throws java.lang.Exception
88 * If this method throws an exception, the bundle is still marked as stopped, and the Framework will
89 * remove the bundle's listeners, unregister all services registered by the bundle, and release all
90 * services used by the bundle. *
91 * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
94 public void stop(BundleContext context) throws Exception {
95 if (registration != null) {
96 registration.unregister();
99 if (reporterRegistration != null) {
100 reporterRegistration.unregister();
101 reporterRegistration = null;
104 if (null != factoryRegistration) {
105 factoryRegistration.unregister();
106 factoryRegistration = null;
109 if (dbRegistration != null) {
110 dbRegistration.unregister();
111 dbRegistration = null;