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