53
53
import java .util .Arrays ;
54
54
import java .util .List ;
55
55
import java .util .Map ;
56
+ import java .util .logging .Level ;
56
57
import java .util .logging .Logger ;
57
58
58
59
import javax .servlet .Servlet ;
59
60
60
61
public class SelfRegisteringRemote {
61
62
62
- private static final Logger log = Logger .getLogger (SelfRegisteringRemote .class .getName ());
63
+ private static final Logger LOG = Logger .getLogger (SelfRegisteringRemote .class .getName ());
63
64
64
65
private RegistrationRequest nodeConfig ;
65
66
@@ -105,7 +106,9 @@ public void startRemoteServer() throws Exception {
105
106
remoteControlConfiguration .setBrowserTimeoutInMs (browserTimeout );
106
107
}
107
108
}catch (Exception e ) {
108
- log .warning ("error getting the parameters from the hub. The node may end up with wrong timeouts." +e .getMessage ());
109
+ LOG .warning (
110
+ "error getting the parameters from the hub. The node may end up with wrong timeouts." + e
111
+ .getMessage ());
109
112
}
110
113
111
114
server = new SeleniumServer (remoteControlConfiguration );
@@ -128,8 +131,8 @@ public void startRemoteServer() throws Exception {
128
131
String path = "/" + servletClass .getSimpleName () + "/*" ;
129
132
String clazz = servletClass .getCanonicalName ();
130
133
handler .addServlet (path , clazz );
131
- log .info ("started extra node servlet visible at : http://xxx:"
132
- + nodeConfig .getConfiguration ().get (RegistrationRequest .PORT ) + "/extra" + path );
134
+ LOG .info ("started extra node servlet visible at : http://xxx:"
135
+ + nodeConfig .getConfiguration ().get (RegistrationRequest .PORT ) + "/extra" + path );
133
136
}
134
137
}
135
138
extra .addHandler (handler );
@@ -184,20 +187,21 @@ public void sendRegistrationRequest() {
184
187
* - register again every X ms is specified in the config of the node.
185
188
*/
186
189
public void startRegistrationProcess () {
187
- log .info ("using the json request : " + nodeConfig .toJSON ());
190
+ LOG .info ("Using the json request : " + nodeConfig .toJSON ());
188
191
189
192
Boolean register = (Boolean ) nodeConfig .getConfiguration ().get (AUTO_REGISTER );
190
193
191
194
if (!register ) {
192
- log .info ("no registration sent ( " + AUTO_REGISTER + " = false )" );
195
+ LOG .info ("No registration sent ( " + AUTO_REGISTER + " = false )" );
193
196
} else {
194
197
final int registerCycleInterval = nodeConfig .getConfigAsInt (RegistrationRequest .REGISTER_CYCLE , 0 );
195
198
if (registerCycleInterval > 0 ) {
196
199
new Thread (new Runnable () { // Thread safety reviewed
197
200
198
201
public void run () {
199
202
boolean first = true ;
200
- log .info ("Starting auto register thread. Will try to register every " + registerCycleInterval + " ms." );
203
+ LOG .info ("Starting auto register thread. Will try to register every "
204
+ + registerCycleInterval + " ms." );
201
205
while (true ) {
202
206
try {
203
207
boolean checkForPresence = true ;
@@ -207,7 +211,7 @@ public void run() {
207
211
}
208
212
registerToHub (checkForPresence );
209
213
} catch (GridException e ) {
210
- log .info ("couldn 't register this node : " + e .getMessage ());
214
+ LOG .info ("Couldn 't register this node: " + e .getMessage ());
211
215
}
212
216
try {
213
217
Thread .sleep (registerCycleInterval );
@@ -248,7 +252,7 @@ private void registerToHub(boolean checkPresenceFirst) {
248
252
HttpClient client = httpClientFactory .getHttpClient ();
249
253
try {
250
254
URL registration = new URL (tmp );
251
- log .info ("Registering the node to hub : " + registration );
255
+ LOG .info ("Registering the node to hub: " + registration );
252
256
253
257
BasicHttpEntityEnclosingRequest r =
254
258
new BasicHttpEntityEnclosingRequest ("POST" , registration .toExternalForm ());
@@ -258,13 +262,15 @@ private void registerToHub(boolean checkPresenceFirst) {
258
262
HttpHost host = new HttpHost (registration .getHost (), registration .getPort ());
259
263
HttpResponse response = client .execute (host , r );
260
264
if (response .getStatusLine ().getStatusCode () != 200 ) {
261
- throw new RuntimeException ("Error sending the registration request." );
265
+ throw new RuntimeException (String .format ("The hub responded with %s:%s" ,
266
+ response .getStatusLine ().getStatusCode (),
267
+ response .getStatusLine ().getReasonPhrase ()));
262
268
}
263
269
} catch (Exception e ) {
264
- throw new GridException ("Error sending the registration request." , e );
270
+ throw new GridException ("Error sending the registration request: " + e . getMessage () );
265
271
}
266
272
} else {
267
- log .fine ("The node is already present on the hub. Skipping registration." );
273
+ LOG .fine ("The node is already present on the hub. Skipping registration." );
268
274
}
269
275
270
276
}
@@ -312,12 +318,14 @@ private boolean isAlreadyRegistered(RegistrationRequest node) {
312
318
313
319
HttpResponse response = client .execute (host , r );
314
320
if (response .getStatusLine ().getStatusCode () != 200 ) {
315
- throw new GridException ("Hub is down or not responding." );
321
+ throw new GridException (String .format ("The hub responded with %s:%s" ,
322
+ response .getStatusLine ().getStatusCode (),
323
+ response .getStatusLine ().getReasonPhrase ()));
316
324
}
317
325
JsonObject o = extractObject (response );
318
326
return o .get ("success" ).getAsBoolean ();
319
327
} catch (Exception e ) {
320
- throw new GridException ("Hub is down or not responding: " + e .getMessage ());
328
+ throw new GridException ("The hub is down or not responding: " + e .getMessage ());
321
329
}
322
330
}
323
331
0 commit comments