First part of onap rename
[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 /*-
3  * ============LICENSE_START=======================================================
4  * ONAP : APPC
5  * ================================================================================
6  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
7  * ================================================================================
8  * Copyright (C) 2017 Amdocs
9  * =============================================================================
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  * 
14  *      http://www.apache.org/licenses/LICENSE-2.0
15  * 
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  * 
22  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
23  * ============LICENSE_END=========================================================
24  */
25 package org.onap.appc.adapter.restHealthcheck;
26
27 import org.onap.appc.Constants;
28 import org.onap.appc.adapter.restHealthcheck.impl.RestHealthcheckAdapterImpl;
29 import org.onap.appc.configuration.Configuration;
30 import org.onap.appc.configuration.ConfigurationFactory;
31 import org.onap.appc.i18n.Msg;
32 import com.att.eelf.configuration.EELFLogger;
33 import com.att.eelf.configuration.EELFManager;
34 import org.osgi.framework.BundleActivator;
35 import org.osgi.framework.BundleContext;
36 import org.osgi.framework.ServiceRegistration;
37
38 public class RestHealthcheckActivator implements BundleActivator {
39
40     /**
41      * The bundle registration
42      */
43     private ServiceRegistration registration = null;
44
45     /**
46      * The reference to the actual implementation object that implements the services
47      */
48     private RestHealthcheckAdapter adapter;
49
50     private static final EELFLogger logger = EELFManager.getInstance().getLogger(RestHealthcheckActivator.class);
51
52     /**
53      * The configuration object used to configure this bundle
54      */
55     private Configuration configuration;
56
57     /**
58      * Called when this bundle is started so the Framework can perform the bundle-specific activities necessary to start
59      * this bundle. This method can be used to register services or to allocate any resources that this bundle needs.
60      * <p>
61      * This method must complete and return to its caller in a timely manner.
62      * </p>
63      * 
64      * @param context
65      *            The execution context of the bundle being started.
66      * @throws java.lang.Exception
67      *             If this method throws an exception, this bundle is marked as stopped and the Framework will remove
68      *             this bundle's listeners, unregister all services registered by this bundle, and release all services
69      *             used by this bundle.
70      * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
71      */
72     @Override
73     public void start(BundleContext context) throws Exception {
74         logger.info("Starting bundle " + getName());
75
76         adapter = new RestHealthcheckAdapterImpl();
77         if (registration == null) {
78             registration = context.registerService(RestHealthcheckAdapter.class, adapter, null);
79         }
80
81     }
82
83     /**
84      * Called when this bundle is stopped so the Framework can perform the bundle-specific activities necessary to stop
85      * the bundle. In general, this method should undo the work that the BundleActivator.start method started. There
86      * should be no active threads that were started by this bundle when this bundle returns. A stopped bundle must not
87      * call any Framework objects.
88      * <p>
89      * This method must complete and return to its caller in a timely manner.
90      * </p>
91      * 
92      * @param context
93      *            The execution context of the bundle being stopped.
94      * @throws java.lang.Exception
95      *             If this method throws an exception, the bundle is still marked as stopped, and the Framework will
96      *             remove the bundle's listeners, unregister all services registered by the bundle, and release all
97      *             services used by the bundle. *
98      * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
99      */
100     @Override
101     public void stop(BundleContext context) throws Exception {
102         logger.info("Stopping bundle " + getName());
103
104         if (registration != null) {
105
106             registration.unregister();
107             registration = null;
108
109         }
110     }
111
112     public String getName() {
113         return "APPC Rest Healthcheck adapter";
114     }
115
116 }