1717
1818package org .openqa .selenium .grid .router ;
1919
20+ import static org .openqa .selenium .remote .HttpSessionId .getSessionId ;
21+ import static org .openqa .selenium .remote .RemoteTags .SESSION_ID ;
22+ import static org .openqa .selenium .remote .RemoteTags .SESSION_ID_EVENT ;
23+ import static org .openqa .selenium .remote .http .Contents .asJson ;
24+ import static org .openqa .selenium .remote .tracing .Tags .EXCEPTION ;
25+ import static org .openqa .selenium .remote .tracing .Tags .HTTP_REQUEST ;
26+ import static org .openqa .selenium .remote .tracing .Tags .HTTP_REQUEST_EVENT ;
27+ import static org .openqa .selenium .remote .tracing .Tags .HTTP_RESPONSE ;
28+
2029import com .google .common .cache .Cache ;
2130import com .google .common .cache .CacheBuilder ;
2231import com .google .common .cache .RemovalListener ;
2332import com .google .common .collect .ImmutableMap ;
2433
2534import org .openqa .selenium .NoSuchSessionException ;
26- import org .openqa .selenium .concurrent .Regularly ;
2735import org .openqa .selenium .grid .data .Session ;
2836import org .openqa .selenium .grid .sessionmap .SessionMap ;
2937import org .openqa .selenium .grid .web .ReverseProxyHandler ;
4755import java .util .HashMap ;
4856import java .util .Map ;
4957import java .util .concurrent .Callable ;
50-
51- import static org .openqa .selenium .remote .HttpSessionId .getSessionId ;
52- import static org .openqa .selenium .remote .RemoteTags .SESSION_ID ;
53- import static org .openqa .selenium .remote .RemoteTags .SESSION_ID_EVENT ;
54- import static org .openqa .selenium .remote .http .Contents .asJson ;
55- import static org .openqa .selenium .remote .tracing .Tags .EXCEPTION ;
56- import static org .openqa .selenium .remote .tracing .Tags .HTTP_REQUEST ;
57- import static org .openqa .selenium .remote .tracing .Tags .HTTP_REQUEST_EVENT ;
58- import static org .openqa .selenium .remote .tracing .Tags .HTTP_RESPONSE ;
58+ import java .util .concurrent .Executors ;
59+ import java .util .concurrent .ScheduledExecutorService ;
60+ import java .util .concurrent .TimeUnit ;
5961
6062class HandleSession implements HttpHandler {
6163
@@ -77,8 +79,16 @@ class HandleSession implements HttpHandler {
7779 .removalListener ((RemovalListener <URL , HttpClient >) removal -> removal .getValue ().close ())
7880 .build ();
7981
80- new Regularly ("Clean up http clients cache" ).submit (
81- httpClients ::cleanUp , Duration .ofMinutes (1 ), Duration .ofMinutes (1 ));
82+ ScheduledExecutorService cleanUpHttpClientsCacheService =
83+ Executors .newSingleThreadScheduledExecutor (
84+ r -> {
85+ Thread thread = new Thread (r );
86+ thread .setDaemon (true );
87+ thread .setName ("HandleSession - Clean up http clients cache" );
88+ return thread ;
89+ });
90+ cleanUpHttpClientsCacheService .scheduleAtFixedRate (
91+ httpClients ::cleanUp , 1 , 1 , TimeUnit .MINUTES );
8292 }
8393
8494 @ Override
0 commit comments