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