Moving all files to root directory
[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  * openECOMP : APP-C
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights
6  *                                              reserved.
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  */
21
22 package org.openecomp.appc.adapter.netconf;
23
24 import org.openecomp.appc.adapter.netconf.internal.NetconfDataAccessServiceImpl;
25 import org.openecomp.sdnc.sli.resource.dblib.DbLibService;
26 import org.osgi.framework.BundleActivator;
27 import org.osgi.framework.BundleContext;
28 import org.osgi.framework.ServiceReference;
29 import org.osgi.framework.ServiceRegistration;
30
31 public class AppcNetconfAdapterActivator implements BundleActivator {
32
33     /**
34      * The bundle registration
35      */
36     private ServiceRegistration registration = null;
37     private ServiceRegistration reporterRegistration = null;
38     private ServiceRegistration factoryRegistration = null;
39     private ServiceRegistration dbRegistration = null;
40
41     /**
42      * The reference to the actual implementation object that implements the services
43      */
44     private NetconfClientFactory clientFactory;
45     private NetconfDataAccessService DAService;
46
47     /**
48      * The logger to be used
49      */
50     //private static final EELFLogger logger = EELFManager.getInstance().getLogger(AppcNetconfAdapterActivator.class);
51
52     /**
53      * Called when this bundle is started so the Framework can perform the bundle-specific activities necessary to start
54      * this bundle. This method can be used to register services or to allocate any resources that this bundle needs.
55      * <p>
56      * This method must complete and return to its caller in a timely manner.
57      * </p>
58      *
59      * @param context
60      *            The execution context of the bundle being started.
61      * @throws java.lang.Exception
62      *             If this method throws an exception, this bundle is marked as stopped and the Framework will remove
63      *             this bundle's listeners, unregister all services registered by this bundle, and release all services
64      *             used by this bundle.
65      * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
66      */
67     @Override
68     public void start(BundleContext context) throws Exception {
69
70         if (registration == null) {
71             clientFactory = new NetconfClientFactory();
72             factoryRegistration = context.registerService(NetconfClientFactory.class, clientFactory, null);
73
74             DAService = new NetconfDataAccessServiceImpl();
75             //set dblib service
76             DbLibService dblibSvc = null;
77             ServiceReference sref = context.getServiceReference(DbLibService.class.getName());
78             dblibSvc  = (DbLibService)context.getService(sref);
79             DAService.setDbLibService(dblibSvc);
80             ///////////////////////////////////
81             factoryRegistration = context.registerService(NetconfDataAccessService.class, DAService, null);
82         }
83
84         //logger.info(Msg.COMPONENT_INITIALIZED, "NETCONF adapter");
85     }
86
87     /**
88      * Called when this bundle is stopped so the Framework can perform the bundle-specific activities necessary to stop
89      * the bundle. In general, this method should undo the work that the BundleActivator.start method started. There
90      * should be no active threads that were started by this bundle when this bundle returns. A stopped bundle must not
91      * call any Framework objects.
92      * <p>
93      * This method must complete and return to its caller in a timely manner.
94      * </p>
95      *
96      * @param context
97      *            The execution context of the bundle being stopped.
98      * @throws java.lang.Exception
99      *             If this method throws an exception, the bundle is still marked as stopped, and the Framework will
100      *             remove the bundle's listeners, unregister all services registered by the bundle, and release all
101      *             services used by the bundle. *
102      * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
103      */
104     @Override
105     public void stop(BundleContext context) throws Exception {
106         if (registration != null) {
107             registration.unregister();
108             registration = null;
109         }
110         if (reporterRegistration != null) {
111             reporterRegistration.unregister();
112             reporterRegistration = null;
113         }
114
115         if (null != factoryRegistration) {
116             factoryRegistration.unregister();
117             factoryRegistration = null;
118         }
119
120         if (dbRegistration != null) {
121             dbRegistration.unregister();
122             dbRegistration = null;
123         }
124     }
125
126     public String getName() {
127         return "APPC NETCONF adapter";
128     }
129
130 }