2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018, 2020-2021 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.drools.pooling.state;
24 import org.onap.policy.drools.pooling.PoolingManager;
25 import org.onap.policy.drools.pooling.message.Heartbeat;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
30 * The start state. Upon entry, a heart beat is generated and the event filter is changed
31 * to look for just that particular message. Once the message is seen, it goes into the
35 public class StartState extends State {
37 private static final Logger logger = LoggerFactory.getLogger(StartState.class);
40 * Time stamp inserted into the heart beat message.
42 private long hbTimestampMs = System.currentTimeMillis();
47 * @param mgr pooling manager
49 public StartState(PoolingManager mgr) {
58 var hb = makeHeartbeat(hbTimestampMs);
59 publish(getHost(), hb);
62 * heart beat generator
64 long genMs = getProperties().getInterHeartbeatMs();
66 scheduleWithFixedDelay(genMs, genMs, () -> {
67 publish(getHost(), hb);
72 * my heart beat checker
74 schedule(getProperties().getStartHeartbeatMs(), () -> {
75 logger.error("missed heartbeat on topic {}", getTopic());
76 return internalTopicFailed();
81 * Transitions to the query state if the heart beat originated from this host and its
85 public State process(Heartbeat msg) {
86 if (msg.getTimestampMs() == hbTimestampMs && getHost().equals(msg.getSource())) {
87 // saw our own heart beat - transition to query state
88 logger.info("saw our own heartbeat on topic {}", getTopic());
93 logger.info("ignored old heartbeat message from {} on topic {}", msg.getSource(), getTopic());