Skip to content

Commit 95c78af

Browse files
committed
[grid] Add node removed listener to Redis and Jdbc session map implementations
1 parent 97b6c1b commit 95c78af

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

java/src/org/openqa/selenium/grid/sessionmap/jdbc/JdbcBackedSessionMap.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.openqa.selenium.events.EventBus;
2424
import org.openqa.selenium.grid.config.Config;
2525
import org.openqa.selenium.grid.config.ConfigException;
26+
import org.openqa.selenium.grid.data.NodeRemovedEvent;
2627
import org.openqa.selenium.grid.data.Session;
2728
import org.openqa.selenium.grid.data.SessionClosedEvent;
2829
import org.openqa.selenium.grid.log.LoggingOptions;
@@ -83,6 +84,11 @@ public JdbcBackedSessionMap(Tracer tracer, Connection jdbcConnection, EventBus b
8384

8485
this.connection = jdbcConnection;
8586
this.bus.addListener(SessionClosedEvent.listener(this::remove));
87+
88+
this.bus.addListener(NodeRemovedEvent.listener(nodeStatus -> nodeStatus.getSlots().stream()
89+
.filter(slot -> slot.getSession() != null)
90+
.map(slot -> slot.getSession().getId())
91+
.forEach(this::remove)));
8692
}
8793

8894
public static SessionMap create(Config config) {

java/src/org/openqa/selenium/grid/sessionmap/redis/RedisBackedSessionMap.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.openqa.selenium.NoSuchSessionException;
2525
import org.openqa.selenium.events.EventBus;
2626
import org.openqa.selenium.grid.config.Config;
27+
import org.openqa.selenium.grid.data.NodeRemovedEvent;
2728
import org.openqa.selenium.grid.data.Session;
2829
import org.openqa.selenium.grid.data.SessionClosedEvent;
2930
import org.openqa.selenium.grid.log.LoggingOptions;
@@ -79,6 +80,11 @@ public RedisBackedSessionMap(Tracer tracer, URI serverUri, EventBus bus) {
7980
this.connection = new GridRedisClient(serverUri);
8081
this.serverUri = serverUri;
8182
this.bus.addListener(SessionClosedEvent.listener(this::remove));
83+
84+
this.bus.addListener(NodeRemovedEvent.listener(nodeStatus -> nodeStatus.getSlots().stream()
85+
.filter(slot -> slot.getSession() != null)
86+
.map(slot -> slot.getSession().getId())
87+
.forEach(this::remove)));
8288
}
8389

8490
public static SessionMap create(Config config) {

0 commit comments

Comments
 (0)