diff options
Diffstat (limited to 'main/src/main/java/org/onap/policy/pap/main/startstop/PapActivator.java')
-rw-r--r-- | main/src/main/java/org/onap/policy/pap/main/startstop/PapActivator.java | 46 |
1 files changed, 34 insertions, 12 deletions
diff --git a/main/src/main/java/org/onap/policy/pap/main/startstop/PapActivator.java b/main/src/main/java/org/onap/policy/pap/main/startstop/PapActivator.java index 1b7281ca..e1ad80e2 100644 --- a/main/src/main/java/org/onap/policy/pap/main/startstop/PapActivator.java +++ b/main/src/main/java/org/onap/policy/pap/main/startstop/PapActivator.java @@ -24,7 +24,6 @@ package org.onap.policy.pap.main.startstop; import java.util.Arrays; import java.util.Properties; import java.util.concurrent.atomic.AtomicReference; - import org.onap.policy.common.endpoints.event.comm.TopicEndpoint; import org.onap.policy.common.endpoints.event.comm.TopicSource; import org.onap.policy.common.endpoints.listeners.MessageTypeDispatcher; @@ -39,6 +38,7 @@ import org.onap.policy.pap.main.PolicyModelsProviderFactoryWrapper; import org.onap.policy.pap.main.PolicyPapRuntimeException; import org.onap.policy.pap.main.comm.PdpHeartbeatListener; import org.onap.policy.pap.main.comm.PdpModifyRequestMap; +import org.onap.policy.pap.main.comm.PdpTracker; import org.onap.policy.pap.main.comm.Publisher; import org.onap.policy.pap.main.comm.TimerManager; import org.onap.policy.pap.main.parameters.PapParameterGroup; @@ -57,12 +57,12 @@ public class PapActivator extends ServiceManagerContainer { private static final String[] MSG_TYPE_NAMES = { "messageName" }; private static final String[] REQ_ID_NAMES = { "response", "responseTo" }; - private final PapParameterGroup papParameterGroup; - /** - * The PAP REST API server. + * Max number of heat beats that can be missed before PAP removes a PDP. */ - private PapRestServer restServer; + private static final int MAX_MISSED_HEARTBEATS = 3; + + private final PapParameterGroup papParameterGroup; /** * Listens for messages on the topic, decodes them into a {@link PdpStatus} message, and then dispatches them to @@ -110,7 +110,10 @@ public class PapActivator extends ServiceManagerContainer { final AtomicReference<Publisher> pdpPub = new AtomicReference<>(); final AtomicReference<TimerManager> pdpUpdTimers = new AtomicReference<>(); final AtomicReference<TimerManager> pdpStChgTimers = new AtomicReference<>(); + final AtomicReference<TimerManager> heartBeatTimers = new AtomicReference<>(); final AtomicReference<PolicyModelsProviderFactoryWrapper> daoFactory = new AtomicReference<>(); + final AtomicReference<PdpModifyRequestMap> requestMap = new AtomicReference<>(); + final AtomicReference<PapRestServer> restServer = new AtomicReference<>(); // @formatter:off addAction("PAP parameters", @@ -153,6 +156,14 @@ public class PapActivator extends ServiceManagerContainer { }, () -> pdpPub.get().stop()); + addAction("PDP heart beat timers", + () -> { + long maxWaitHeartBeatMs = MAX_MISSED_HEARTBEATS * pdpParams.getHeartBeatMs(); + heartBeatTimers.set(new TimerManager("heart beat", maxWaitHeartBeatMs)); + startThread(heartBeatTimers.get()); + }, + () -> heartBeatTimers.get().stop()); + addAction("PDP update timers", () -> { pdpUpdTimers.set(new TimerManager("update", pdpParams.getUpdateParameters().getMaxWaitMs())); @@ -172,7 +183,8 @@ public class PapActivator extends ServiceManagerContainer { () -> Registry.unregister(PapConstants.REG_PDP_MODIFY_LOCK)); addAction("PDP modification requests", - () -> Registry.register(PapConstants.REG_PDP_MODIFY_MAP, new PdpModifyRequestMap( + () -> { + requestMap.set(new PdpModifyRequestMap( new PdpModifyRequestMapParams() .setDaoFactory(daoFactory.get()) .setModifyLock(pdpUpdateLock) @@ -180,16 +192,26 @@ public class PapActivator extends ServiceManagerContainer { .setPublisher(pdpPub.get()) .setResponseDispatcher(reqIdDispatcher) .setStateChangeTimers(pdpStChgTimers.get()) - .setUpdateTimers(pdpUpdTimers.get()))), + .setUpdateTimers(pdpUpdTimers.get()))); + Registry.register(PapConstants.REG_PDP_MODIFY_MAP, requestMap.get()); + }, () -> Registry.unregister(PapConstants.REG_PDP_MODIFY_MAP)); - addAction("Create REST server", - () -> restServer = new PapRestServer(papParameterGroup.getRestServerParameters()), - () -> restServer = null); + addAction("PDP heart beat tracker", + () -> Registry.register(PapConstants.REG_PDP_TRACKER, PdpTracker.builder() + .daoFactory(daoFactory.get()) + .timers(heartBeatTimers.get()) + .modifyLock(pdpUpdateLock) + .requestMap(requestMap.get()) + .build()), + () -> Registry.unregister(PapConstants.REG_PDP_TRACKER)); addAction("REST server", - () -> restServer.start(), - () -> restServer.stop()); + () -> { + restServer.set(new PapRestServer(papParameterGroup.getRestServerParameters())); + restServer.get().start(); + }, + () -> restServer.get().stop()); // @formatter:on } |