[grid] Start heartbeat after registering the Node
import org.openqa.selenium.grid.data.Availability;
import org.openqa.selenium.grid.data.CreateSessionRequest;
import org.openqa.selenium.grid.data.CreateSessionResponse;
+import org.openqa.selenium.grid.data.NodeAddedEvent;
import org.openqa.selenium.grid.data.NodeDrainComplete;
import org.openqa.selenium.grid.data.NodeDrainStarted;
import org.openqa.selenium.grid.data.NodeHeartBeatEvent;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ExecutionException;
+import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.logging.Logger;
import java.util.stream.Collectors;
private final Cache<SessionId, TemporaryFilesystem> tempFileSystems;
private final Regularly regularly;
private final AtomicInteger pendingSessions = new AtomicInteger();
+ private final AtomicBoolean heartBeatStarted = new AtomicBoolean(false);
private LocalNode(
Tracer tracer,
@@ -170,7 +173,15 @@ private LocalNode(
this.regularly = new Regularly("Local Node: " + externalUri);
regularly.submit(currentSessions::cleanUp, Duration.ofSeconds(30), Duration.ofSeconds(30));
regularly.submit(tempFileSystems::cleanUp, Duration.ofSeconds(30), Duration.ofSeconds(30));
- regularly.submit(() -> bus.fire(new NodeHeartBeatEvent(getStatus())), heartbeatPeriod, heartbeatPeriod);
+ bus.addListener(NodeAddedEvent.listener(nodeId -> {
+ if (getId().equals(nodeId)) {
+ // Lets avoid to create more than one "Regularly" when the Node registers again.
+ if (!heartBeatStarted.getAndSet(true)) {
+ regularly.submit(
+ () -> bus.fire(new NodeHeartBeatEvent(getStatus())), heartbeatPeriod, heartbeatPeriod);
+ }
+ }
+ }));
bus.addListener(SessionClosedEvent.listener(id -> {
try {
