2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * Copyright (C) 2017 Amdocs
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
20 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
23 package org.openecomp.appc.adapter.netconf;
25 import org.openecomp.appc.adapter.netconf.internal.NetconfDataAccessServiceImpl;
26 import org.openecomp.sdnc.sli.resource.dblib.DbLibService;
27 import org.openecomp.appc.i18n.Msg;
28 import com.att.eelf.configuration.EELFLogger;
29 import com.att.eelf.configuration.EELFManager;
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 * The reference to the actual implementation object that implements the services
48 private NetconfClientFactory clientFactory;
49 private NetconfDataAccessService DAService;
52 * The logger to be used
54 private static final EELFLogger logger = EELFManager.getInstance().getLogger(AppcNetconfAdapterActivator.class);
57 * Called when this bundle is started so the Framework can perform the bundle-specific activities necessary to start
58 * this bundle. This method can be used to register services or to allocate any resources that this bundle needs.
60 * This method must complete and return to its caller in a timely manner.
64 * The execution context of the bundle being started.
65 * @throws java.lang.Exception
66 * If this method throws an exception, this bundle is marked as stopped and the Framework will remove
67 * this bundle's listeners, unregister all services registered by this bundle, and release all services
68 * used by this bundle.
69 * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
72 public void start(BundleContext context) throws Exception {
74 if (registration == null) {
75 clientFactory = new NetconfClientFactory();
76 factoryRegistration = context.registerService(NetconfClientFactory.class, clientFactory, null);
78 DAService = new NetconfDataAccessServiceImpl();
80 DbLibService dblibSvc = null;
81 ServiceReference sref = context.getServiceReference(DbLibService.class.getName());
82 dblibSvc = (DbLibService)context.getService(sref);
83 DAService.setDbLibService(dblibSvc);
84 ///////////////////////////////////
85 factoryRegistration = context.registerService(NetconfDataAccessService.class, DAService, null);
88 logger.info(Msg.COMPONENT_INITIALIZED, "NETCONF adapter");
92 * Called when this bundle is stopped so the Framework can perform the bundle-specific activities necessary to stop
93 * the bundle. In general, this method should undo the work that the BundleActivator.start method started. There
94 * should be no active threads that were started by this bundle when this bundle returns. A stopped bundle must not
95 * call any Framework objects.
97 * This method must complete and return to its caller in a timely manner.
101 * The execution context of the bundle being stopped.
102 * @throws java.lang.Exception
103 * If this method throws an exception, the bundle is still marked as stopped, and the Framework will
104 * remove the bundle's listeners, unregister all services registered by the bundle, and release all
105 * services used by the bundle. *
106 * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
109 public void stop(BundleContext context) throws Exception {
110 if (registration != null) {
111 registration.unregister();
114 if (reporterRegistration != null) {
115 reporterRegistration.unregister();
116 reporterRegistration = null;
119 if (null != factoryRegistration) {
120 factoryRegistration.unregister();
121 factoryRegistration = null;
124 if (dbRegistration != null) {
125 dbRegistration.unregister();
126 dbRegistration = null;
130 public String getName() {
131 return "APPC NETCONF adapter";