7d644a0f188e263bb95de98a49d39176e792d112
[appc.git] / appc-adapters / appc-rest-healthcheck-adapter / appc-rest-healthcheck-adapter-bundle / src / main / java / org / onap / appc / adapter / restHealthcheck / RestHealthcheckActivator.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
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
12  * 
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  * 
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.
20  * 
21  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22  * ============LICENSE_END=========================================================
23  */
24 package org.onap.appc.adapter.restHealthcheck;
25
26 import org.onap.appc.adapter.restHealthcheck.impl.RestHealthcheckAdapterImpl;
27 import org.onap.appc.configuration.Configuration;
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.ServiceRegistration;
33
34 public class RestHealthcheckActivator implements BundleActivator {
35     /**
36      * The bundle registration
37      */
38     private ServiceRegistration registration = null;
39     private static final EELFLogger logger = EELFManager.getInstance().getLogger(RestHealthcheckActivator.class);
40     private static final String APPNAME = "APPC Rest Healthcheck adapter";
41
42     /**
43      * Called when this bundle is started so the Framework can perform the bundle-specific activities necessary to start
44      * this bundle. This method can be used to register services or to allocate any resources that this bundle needs.
45      * <p>
46      * This method must complete and return to its caller in a timely manner.
47      * </p>
48      * 
49      * @param context
50      *            The execution context of the bundle being started.
51      * @throws java.lang.Exception
52      *             If this method throws an exception, this bundle is marked as stopped and the Framework will remove
53      *             this bundle's listeners, unregister all services registered by this bundle, and release all services
54      *             used by this bundle.
55      * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
56      */
57     @Override
58     public void start(BundleContext context) throws Exception {
59         logger.info("Starting bundle " + getName());
60        /* The reference to the actual implementation object that implements the services */
61         RestHealthcheckAdapter adapter = new RestHealthcheckAdapterImpl();
62
63         if (registration == null) {
64             registration = context.registerService(RestHealthcheckAdapter.class, adapter, null);
65         }
66
67     }
68     /**
69      * Called when this bundle is stopped so the Framework can perform the bundle-specific activities necessary to stop
70      * the bundle. In general, this method should undo the work that the BundleActivator.start method started. There
71      * should be no active threads that were started by this bundle when this bundle returns. A stopped bundle must not
72      * call any Framework objects.
73      * <p>
74      * This method must complete and return to its caller in a timely manner.
75      * </p>
76      * 
77      * @param context
78      *            The execution context of the bundle being stopped.
79      * @throws java.lang.Exception
80      *             If this method throws an exception, the bundle is still marked as stopped, and the Framework will
81      *             remove the bundle's listeners, unregister all services registered by the bundle, and release all
82      *             services used by the bundle. *
83      * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
84      */
85     @Override
86     public void stop(BundleContext context) throws Exception {
87         logger.info("Stopping bundle " + getName());
88
89         if (registration != null) {
90
91             registration.unregister();
92             registration = null;
93
94         }
95     }
96     public String getName() {
97         return APPNAME;
98     }
99
100 }