import java.util.Timer;
import java.util.TimerTask;
import org.onap.policy.common.endpoints.event.comm.client.TopicSinkClient;
+import org.onap.policy.models.pdp.concepts.PdpStateChange;
import org.onap.policy.models.pdp.enums.PdpState;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class XacmlPdpHeartbeatPublisher extends TimerTask {
+public class XacmlPdpHearbeatPublisher extends TimerTask {
- private static final Logger LOGGER = LoggerFactory.getLogger(XacmlPdpHeartbeatPublisher.class);
+ private static final Logger LOGGER = LoggerFactory.getLogger(XacmlPdpHearbeatPublisher.class);
- private TopicSinkClient topicSinkClient;
private Timer timer;
private XacmlPdpMessage heartbeatMessage;
- private PdpState pdpState;
-
+ private Object message;
+ private static TopicSinkClient topicSinkClient;
private static volatile boolean alive = false;
+ public static PdpState pdpState;
+
/**
- * Constructor for instantiating XacmlPdpHeartbeatPublisher.
+ * Constructor for instantiating XacmlPdpPublisher.
*
- * @param state of the PDP
+ * @param message of the PDP
* @param topicSinkClient used to send heartbeat message
*/
- public XacmlPdpHeartbeatPublisher(TopicSinkClient topicSinkClient, PdpState state) {
+ public XacmlPdpHearbeatPublisher(TopicSinkClient topicSinkClient, PdpStateChange message) {
+ this.message = message;
+ this.pdpState = message.getState();
this.topicSinkClient = topicSinkClient;
this.heartbeatMessage = new XacmlPdpMessage();
- this.pdpState = state;
timer = new Timer(false);
timer.scheduleAtFixedRate(this, 0, 60000); // time interval temp hard coded now but will be parameterized
setAlive(true);
@Override
public void run() {
- topicSinkClient.send(heartbeatMessage.formatStatusMessage(pdpState));
+ topicSinkClient.send(heartbeatMessage.formatHeartbeatMessage((PdpStateChange) message));
LOGGER.info("Sending Xacml PDP heartbeat to the PAP");
}
}
public void updateInternalState(PdpState state) {
+ ((PdpStateChange) this.message).setState(state);
this.pdpState = state;
}
public void setAlive(boolean alive) {
this.alive = alive;
}
-
}