2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 Nordix Foundation.
4 * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
5 * ================================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.models.sim.pdp.comm;
24 import java.util.List;
25 import java.util.Timer;
26 import java.util.TimerTask;
28 import org.onap.policy.common.endpoints.event.comm.TopicSink;
29 import org.onap.policy.common.endpoints.event.comm.client.TopicSinkClient;
30 import org.onap.policy.models.pdp.concepts.PdpStatus;
31 import org.onap.policy.models.sim.pdp.handler.PdpMessageHandler;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
36 * This class is used to send pdp status messages to pap using TopicSinkClient.
38 * @author Ajith Sreekumar (ajith.sreekumar@est.tech)
40 public class PdpStatusPublisher extends TimerTask {
42 private static final Logger LOGGER = LoggerFactory.getLogger(PdpStatusPublisher.class);
44 private TopicSinkClient topicSinkClient;
47 private long interval;
50 * Constructor for instantiating PdpStatusPublisher.
52 * @param topicSinks the topic sinks
53 * @param interval time interval to send pdp status
55 public PdpStatusPublisher(final List<TopicSink> topicSinks, final long interval) {
56 this.topicSinkClient = new TopicSinkClient(topicSinks.get(0));
57 this.interval = interval;
58 timer = new Timer(false);
59 timer.scheduleAtFixedRate(this, 0, interval);
64 final var pdpStatus = new PdpMessageHandler().createPdpStatusFromContext();
65 topicSinkClient.send(pdpStatus);
66 LOGGER.debug("Sent heartbeat to PAP - {}", pdpStatus);
70 * Terminates the current timer.
72 public void terminate() {
78 * Method to send pdp status message to pap on demand.
80 * @param pdpStatus the pdp status
82 public void send(final PdpStatus pdpStatus) {
83 topicSinkClient.send(pdpStatus);
84 LOGGER.debug("Sent pdp status message to PAP - {}", pdpStatus);