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=========================================================
22 package org.onap.policy.apex.starter.handler;
24 import java.util.List;
26 import org.onap.policy.apex.starter.parameters.PdpStatusParameters;
27 import org.onap.policy.common.capabilities.Startable;
28 import org.onap.policy.common.endpoints.event.comm.TopicSink;
29 import org.onap.policy.common.endpoints.event.comm.TopicSource;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
34 * This class manages the communication between apex pdp and pap.
36 * @author Ajith Sreekumar (ajith.sreekumar@est.tech)
38 public class CommunicationHandler implements Startable {
40 private static final Logger LOGGER = LoggerFactory.getLogger(CommunicationHandler.class);
42 private List<TopicSink> topicSinks; // topics to which apex-pdp sends pdp status
43 private List<TopicSource> topicSources; // topics to which apex-pdp listens to for messages from pap.
45 private PdpStatusPublisher pdpStatusPublisher;
46 private PdpStatusParameters pdpStatusParameters;
49 * Constructor for instantiating CommunicationHandler
51 * @param topicSinks topics to which apex-pdp sends pdp status
52 * @param topicSources topics to which apex-pdp listens to for messages from pap.
53 * @param pdpStatusParameters pdp status parameters read from the configuration file
55 public CommunicationHandler(final List<TopicSink> topicSinks, final List<TopicSource> topicSources,
56 final PdpStatusParameters pdpStatusParameters) {
57 this.topicSinks = topicSinks;
58 this.topicSources = topicSources;
59 this.pdpStatusParameters = pdpStatusParameters;
63 public boolean start() {
65 pdpStatusPublisher = new PdpStatusPublisher(topicSinks, pdpStatusParameters.getTimeInterval());
66 } catch (final Exception e) {
67 LOGGER.error("Failed to start communication handler for apex-pdp", e);
74 public boolean stop() {
76 pdpStatusPublisher.terminate();
77 } catch (final Exception e) {
78 LOGGER.error("Failed to stop communication handler for apex-pdp", e);
85 public void shutdown() {
90 public boolean isAlive() {
91 return pdpStatusPublisher.isAlive();