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