Updating licenses in all files
[appc.git] / appc-adapters / appc-netconf-adapter / appc-netconf-adapter-bundle / src / main / java / org / openecomp / appc / adapter / netconf / AppcNetconfAdapterActivator.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * APPC
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
11  * 
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  * 
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.
21  */
22
23 package org.openecomp.appc.adapter.netconf;
24
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;
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      * The reference to the actual implementation object that implements the services
47      */
48     private NetconfClientFactory clientFactory;
49     private NetconfDataAccessService DAService;
50
51     /**
52      * The logger to be used
53      */
54     private static final EELFLogger logger = EELFManager.getInstance().getLogger(AppcNetconfAdapterActivator.class);
55
56     /**
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.
59      * <p>
60      * This method must complete and return to its caller in a timely manner.
61      * </p>
62      *
63      * @param context
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)
70      */
71     @Override
72     public void start(BundleContext context) throws Exception {
73
74         if (registration == null) {
75             clientFactory = new NetconfClientFactory();
76             factoryRegistration = context.registerService(NetconfClientFactory.class, clientFactory, null);
77
78             DAService = new NetconfDataAccessServiceImpl();
79             //set dblib service
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);
86         }
87
88         logger.info(Msg.COMPONENT_INITIALIZED, "NETCONF adapter");
89     }
90
91     /**
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.
96      * <p>
97      * This method must complete and return to its caller in a timely manner.
98      * </p>
99      *
100      * @param context
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)
107      */
108     @Override
109     public void stop(BundleContext context) throws Exception {
110         if (registration != null) {
111             registration.unregister();
112             registration = null;
113         }
114         if (reporterRegistration != null) {
115             reporterRegistration.unregister();
116             reporterRegistration = null;
117         }
118
119         if (null != factoryRegistration) {
120             factoryRegistration.unregister();
121             factoryRegistration = null;
122         }
123
124         if (dbRegistration != null) {
125             dbRegistration.unregister();
126             dbRegistration = null;
127         }
128     }
129
130     public String getName() {
131         return "APPC NETCONF adapter";
132     }
133
134 }