diff options
Diffstat (limited to 'participant/participant-intermediary')
5 files changed, 17 insertions, 5 deletions
diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/comm/MessageSender.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/comm/MessageSender.java index 0810a8a8a..2388b3bf8 100644..100755 --- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/comm/MessageSender.java +++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/comm/MessageSender.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2021 Nordix Foundation. + * Copyright (C) 2021,2023 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,6 +29,8 @@ import org.onap.policy.clamp.acm.participant.intermediary.handler.ParticipantHan import org.onap.policy.clamp.acm.participant.intermediary.parameters.ParticipantParameters; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.context.event.ContextRefreshedEvent; +import org.springframework.context.event.EventListener; import org.springframework.stereotype.Component; /** @@ -39,7 +41,8 @@ public class MessageSender extends TimerTask implements Closeable { private static final Logger LOGGER = LoggerFactory.getLogger(MessageSender.class); private final ParticipantHandler participantHandler; - private ScheduledExecutorService timerPool; + private final ScheduledExecutorService timerPool; + private final long interval; /** * Constructor, set the publisher. @@ -52,7 +55,11 @@ public class MessageSender extends TimerTask implements Closeable { // Kick off the timer timerPool = makeTimerPool(); - var interval = parameters.getIntermediaryParameters().getReportingTimeIntervalMs(); + interval = parameters.getIntermediaryParameters().getReportingTimeIntervalMs(); + } + + @EventListener + public void handleContextRefreshEvent(ContextRefreshedEvent ctxRefreshedEvent) { timerPool.scheduleAtFixedRate(this, interval, interval, TimeUnit.MILLISECONDS); } diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/comm/ParticipantMessagePublisher.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/comm/ParticipantMessagePublisher.java index 4c885fa26..0f0f5dd48 100644..100755 --- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/comm/ParticipantMessagePublisher.java +++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/comm/ParticipantMessagePublisher.java @@ -24,6 +24,7 @@ package org.onap.policy.clamp.acm.participant.intermediary.comm; import io.micrometer.core.annotation.Timed; import java.util.List; import javax.ws.rs.core.Response.Status; +import lombok.Getter; import org.onap.policy.clamp.acm.participant.intermediary.handler.Publisher; import org.onap.policy.clamp.common.acm.exception.AutomationCompositionRuntimeException; import org.onap.policy.clamp.models.acm.messages.dmaap.participant.AutomationCompositionDeployAck; @@ -46,6 +47,7 @@ public class ParticipantMessagePublisher implements Publisher { private static final Logger LOGGER = LoggerFactory.getLogger(ParticipantMessagePublisher.class); private static final String NOT_ACTIVE_TEXT = "Not Active!"; + @Getter private boolean active = false; private TopicSinkClient topicSinkClient; diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ParticipantHandler.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ParticipantHandler.java index 8f69fd524..ed1d9182c 100644..100755 --- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ParticipantHandler.java +++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ParticipantHandler.java @@ -222,7 +222,9 @@ public class ParticipantHandler { * Dispatch a heartbeat for this participant. */ public void sendHeartbeat() { - publisher.sendHeartbeat(makeHeartbeat(false)); + if (publisher.isActive()) { + publisher.sendHeartbeat(makeHeartbeat(false)); + } } /** diff --git a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/comm/ParticipantCommTest.java b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/comm/ParticipantCommTest.java index db6a3a554..e959d136a 100644..100755 --- a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/comm/ParticipantCommTest.java +++ b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/comm/ParticipantCommTest.java @@ -137,9 +137,9 @@ class ParticipantCommTest { var participantHandler = mock(ParticipantHandler.class); var participantParameters = CommonTestData.getParticipantParameters(); var messageSender = new MessageSender(participantHandler, participantParameters); + messageSender.handleContextRefreshEvent(null); messageSender.run(); assertFalse(messageSender.makeTimerPool().isTerminated()); messageSender.close(); } - } diff --git a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ParticipantHandlerTest.java b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ParticipantHandlerTest.java index 2f1eb2273..c558e6668 100644..100755 --- a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ParticipantHandlerTest.java +++ b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ParticipantHandlerTest.java @@ -217,6 +217,7 @@ class ParticipantHandlerTest { when(cacheProvider.getParticipantId()).thenReturn(CommonTestData.getParticipantId()); when(cacheProvider.getAutomationCompositions()).thenReturn(CommonTestData.getTestAutomationCompositionMap()); var publisher = mock(ParticipantMessagePublisher.class); + when(publisher.isActive()).thenReturn(true); var participantHandler = new ParticipantHandler(mock(AutomationCompositionHandler.class), mock(AutomationCompositionOutHandler.class), publisher, cacheProvider); participantHandler.sendHeartbeat(); |