2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 Nordix Foundation.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.pap.main.startstop;
23 import org.onap.policy.common.parameters.ParameterService;
24 import org.onap.policy.pap.main.PolicyPapException;
25 import org.onap.policy.pap.main.parameters.PapParameterGroup;
26 import org.slf4j.ext.XLogger;
27 import org.slf4j.ext.XLoggerFactory;
30 * This class wraps a distributor so that it can be activated as a complete service together with all its pap and
31 * forwarding handlers.
33 * @author Ram Krishna Verma (ram.krishna.verma@est.tech)
35 public class PapActivator {
36 // The logger for this class
37 private static final XLogger LOGGER = XLoggerFactory.getXLogger(PapActivator.class);
39 // The parameters of this policy pap activator
40 private final PapParameterGroup papParameterGroup;
42 private static boolean alive = false;
45 * Instantiate the activator for policy pap as a complete service.
47 * @param papParameterGroup the parameters for the pap service
49 public PapActivator(final PapParameterGroup papParameterGroup) {
50 this.papParameterGroup = papParameterGroup;
54 * Initialize pap as a complete service.
56 * @throws PolicyPapException on errors in initializing the service
58 public void initialize() throws PolicyPapException {
60 LOGGER.debug("Policy pap starting as a service . . .");
61 registerToParameterService(papParameterGroup);
62 PapActivator.setAlive(true);
63 LOGGER.debug("Policy pap started as a service");
64 } catch (final Exception exp) {
65 LOGGER.error("Policy pap service startup failed", exp);
66 throw new PolicyPapException(exp.getMessage(), exp);
71 * Terminate policy pap.
73 * @throws PolicyPapException on errors in terminating the service
75 public void terminate() throws PolicyPapException {
77 deregisterToParameterService(papParameterGroup);
78 PapActivator.setAlive(false);
80 } catch (final Exception exp) {
81 LOGGER.error("Policy pap service termination failed", exp);
82 throw new PolicyPapException(exp.getMessage(), exp);
87 * Get the parameters used by the activator.
89 * @return the parameters of the activator
91 public PapParameterGroup getParameterGroup() {
92 return papParameterGroup;
96 * Method to register the parameters to Common Parameter Service.
98 * @param papParameterGroup the pap parameter group
100 public void registerToParameterService(final PapParameterGroup papParameterGroup) {
101 ParameterService.register(papParameterGroup);
105 * Method to deregister the parameters from Common Parameter Service.
107 * @param papParameterGroup the pap parameter group
109 public void deregisterToParameterService(final PapParameterGroup papParameterGroup) {
110 ParameterService.deregister(papParameterGroup.getName());
114 * Returns the alive status of pap service.
118 public static boolean isAlive() {
123 * Change the alive status of pap service.
125 * @param status the status
127 public static void setAlive(final boolean status) {