42
42
import java .util .function .Consumer ;
43
43
import java .util .logging .Level ;
44
44
import java .util .logging .Logger ;
45
+ import org .openqa .selenium .concurrent .ExecutorServices ;
45
46
import org .openqa .selenium .events .Event ;
46
47
import org .openqa .selenium .events .EventBus ;
47
48
import org .openqa .selenium .events .EventListener ;
@@ -61,6 +62,7 @@ class UnboundZmqEventBus implements EventBus {
61
62
private static final Logger LOG = Logger .getLogger (EventBus .class .getName ());
62
63
private static final Json JSON = new Json ();
63
64
private final AtomicBoolean pollingStarted = new AtomicBoolean (false );
65
+ private final PollingRunnable socketPolling ;
64
66
private final ExecutorService socketPollingExecutor ;
65
67
private final ExecutorService socketPublishingExecutor ;
66
68
private final ExecutorService listenerNotificationExecutor ;
@@ -147,7 +149,8 @@ class UnboundZmqEventBus implements EventBus {
147
149
148
150
LOG .info ("Sockets created" );
149
151
150
- socketPollingExecutor .submit (new PollingRunnable (secret ));
152
+ socketPolling = new PollingRunnable (secret );
153
+ socketPollingExecutor .submit (socketPolling );
151
154
152
155
// Give ourselves up to a second to connect, using The World's Worst heuristic. If we don't
153
156
// manage to connect, it's not the end of the world, as the socket we're connecting to may not
@@ -211,9 +214,11 @@ public void fire(Event event) {
211
214
212
215
@ Override
213
216
public void close () {
214
- socketPollingExecutor .shutdownNow ();
215
- socketPublishingExecutor .shutdownNow ();
216
- listenerNotificationExecutor .shutdownNow ();
217
+ socketPolling .shutdown = true ;
218
+ ExecutorServices .shutdownGracefully ("Event Bus Poller" , socketPollingExecutor );
219
+ ExecutorServices .shutdownGracefully ("Event Bus Publisher" , socketPublishingExecutor );
220
+ ExecutorServices .shutdownGracefully (
221
+ "Event Bus Listener Notifier" , listenerNotificationExecutor );
217
222
poller .close ();
218
223
219
224
if (sub != null ) {
@@ -226,14 +231,15 @@ public void close() {
226
231
227
232
private class PollingRunnable implements Runnable {
228
233
private final Secret secret ;
234
+ private volatile boolean shutdown ;
229
235
230
236
public PollingRunnable (Secret secret ) {
231
237
this .secret = secret ;
232
238
}
233
239
234
240
@ Override
235
241
public void run () {
236
- while (!Thread .currentThread ().isInterrupted ()) {
242
+ while (!Thread .currentThread ().isInterrupted () && ! shutdown ) {
237
243
try {
238
244
int count = poller .poll (150 );
239
245
0 commit comments