17
17
18
18
package org .openqa .selenium .remote .service ;
19
19
20
- import static java .util .Collections .emptyMap ;
21
- import static java .util .concurrent .TimeUnit .SECONDS ;
22
-
23
20
import com .google .common .collect .ImmutableMap ;
24
21
25
22
import org .openqa .selenium .Beta ;
49
46
import java .util .concurrent .TimeoutException ;
50
47
import java .util .concurrent .locks .ReentrantLock ;
51
48
49
+ import static java .util .Collections .emptyMap ;
50
+ import static java .util .concurrent .TimeUnit .SECONDS ;
51
+
52
52
/**
53
53
* Manages the life and death of a native executable driver server.
54
54
*
59
59
* used to stop the server.
60
60
*/
61
61
public class DriverService implements Closeable {
62
+
62
63
protected static final Duration DEFAULT_TIMEOUT = Duration .ofSeconds (20 );
63
- private static final ExecutorService executorService = Executors .newFixedThreadPool (2 , r -> {
64
+ private final ExecutorService executorService = Executors .newFixedThreadPool (2 , r -> {
64
65
Thread thread = new Thread (r );
65
66
thread .setName ("Driver Service Executor" );
66
67
thread .setDaemon (true );
@@ -77,17 +78,15 @@ public class DriverService implements Closeable {
77
78
* Controls access to {@link #process}.
78
79
*/
79
80
private final ReentrantLock lock = new ReentrantLock ();
80
-
81
+ private final String executable ;
82
+ private final Duration timeout ;
83
+ private final List <String > args ;
84
+ private final Map <String , String > environment ;
81
85
/**
82
86
* A reference to the current child process. Will be {@code null} whenever this service is not
83
87
* running. Protected by {@link #lock}.
84
88
*/
85
89
protected CommandLine process = null ;
86
-
87
- private final String executable ;
88
- private final Duration timeout ;
89
- private final List <String > args ;
90
- private final Map <String , String > environment ;
91
90
private OutputStream outputStream = System .err ;
92
91
93
92
/**
@@ -113,25 +112,6 @@ protected DriverService(
113
112
this .url = getUrl (port );
114
113
}
115
114
116
- protected List <String > getArgs () {
117
- return args ;
118
- }
119
-
120
- protected Map <String , String > getEnvironment () {
121
- return environment ;
122
- }
123
-
124
- protected URL getUrl (int port ) throws IOException {
125
- return new URL (String .format ("http://localhost:%d" , port ));
126
- }
127
-
128
- /**
129
- * @return The base URL for the managed driver server.
130
- */
131
- public URL getUrl () {
132
- return url ;
133
- }
134
-
135
115
/**
136
116
*
137
117
* @param exeName Name of the executable file to look for in PATH
@@ -165,6 +145,25 @@ protected static void checkExecutable(File exe) {
165
145
Require .stateCondition (exe .canExecute (), "It must be an executable file: %s" , exe );
166
146
}
167
147
148
+ protected List <String > getArgs () {
149
+ return args ;
150
+ }
151
+
152
+ protected Map <String , String > getEnvironment () {
153
+ return environment ;
154
+ }
155
+
156
+ protected URL getUrl (int port ) throws IOException {
157
+ return new URL (String .format ("http://localhost:%d" , port ));
158
+ }
159
+
160
+ /**
161
+ * @return The base URL for the managed driver server.
162
+ */
163
+ public URL getUrl () {
164
+ return url ;
165
+ }
166
+
168
167
/**
169
168
* Checks whether the driver child process is currently running.
170
169
*
@@ -181,12 +180,6 @@ public boolean isRunning() {
181
180
}
182
181
}
183
182
184
- private enum StartOrDie {
185
- SERVER_STARTED ,
186
- PROCESS_IS_ACTIVE ,
187
- PROCESS_DIED
188
- }
189
-
190
183
/**
191
184
* Starts this service if it is not already running. This method will block until the server has
192
185
* been fully started and is ready to handle commands.
@@ -317,6 +310,12 @@ public void close() {
317
310
executorService .shutdownNow ();
318
311
}
319
312
313
+ private enum StartOrDie {
314
+ SERVER_STARTED ,
315
+ PROCESS_IS_ACTIVE ,
316
+ PROCESS_DIED
317
+ }
318
+
320
319
public abstract static class Builder <DS extends DriverService , B extends Builder <?, ?>> {
321
320
322
321
private int port = 0 ;
0 commit comments