|
42 | 42 | import org.openqa.selenium.grid.data.NodeId; |
43 | 43 | import org.openqa.selenium.grid.data.NodeStatus; |
44 | 44 | import org.openqa.selenium.grid.data.Session; |
45 | | -import org.openqa.selenium.grid.data.SessionClosedEvent; |
46 | 45 | import org.openqa.selenium.grid.data.Slot; |
47 | 46 | import org.openqa.selenium.grid.data.SlotId; |
48 | 47 | import org.openqa.selenium.grid.jmx.JMXHelper; |
@@ -217,18 +216,6 @@ private LocalNode( |
217 | 216 | heartbeatPeriod.getSeconds(), |
218 | 217 | TimeUnit.SECONDS); |
219 | 218 |
|
220 | | - bus.addListener(SessionClosedEvent.listener(id -> { |
221 | | - // Shouldn't we check that the session actually belongs to this Node? |
222 | | - // Listen to session terminated events, so we know when to fire the NodeDrainComplete event |
223 | | - if (this.isDraining()) { |
224 | | - int done = pendingSessions.decrementAndGet(); |
225 | | - if (done <= 0) { |
226 | | - LOG.info("Firing node drain complete message"); |
227 | | - bus.fire(new NodeDrainComplete(this.getId())); |
228 | | - } |
229 | | - } |
230 | | - })); |
231 | | - |
232 | 219 | Runtime.getRuntime().addShutdownHook(new Thread(this::stopAllSessions)); |
233 | 220 | new JMXHelper().register(this); |
234 | 221 | } |
@@ -487,6 +474,15 @@ public void stop(SessionId id) throws NoSuchSessionException { |
487 | 474 |
|
488 | 475 | currentSessions.invalidate(id); |
489 | 476 | tempFileSystems.invalidate(id); |
| 477 | + |
| 478 | + // Decrement pending sessions if Node is draining |
| 479 | + if (this.isDraining()) { |
| 480 | + int done = pendingSessions.decrementAndGet(); |
| 481 | + if (done <= 0) { |
| 482 | + LOG.info("Node draining complete!"); |
| 483 | + bus.fire(new NodeDrainComplete(this.getId())); |
| 484 | + } |
| 485 | + } |
490 | 486 | } |
491 | 487 |
|
492 | 488 | private void stopAllSessions() { |
|
0 commit comments