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