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