diff --git a/hub/src/main/java/com/thoughtworks/selenium/grid/hub/remotecontrol/RemoteControlProxy.java b/hub/src/main/java/com/thoughtworks/selenium/grid/hub/remotecontrol/RemoteControlProxy.java index a3efe15c..59b3fbe0 100755 --- a/hub/src/main/java/com/thoughtworks/selenium/grid/hub/remotecontrol/RemoteControlProxy.java +++ b/hub/src/main/java/com/thoughtworks/selenium/grid/hub/remotecontrol/RemoteControlProxy.java @@ -130,51 +130,47 @@ public boolean canHandleNewSession() { return !sessionInProgress(); } - public boolean unreliable() { + public boolean unreliable() { final Response response; try { LOGGER.debug("Polling Remote Control at " + host + ":" + port); response = httpClient.get(remoteControlPingURL()); - } catch (Exception e) { - LOGGER.warn("Remote Control at " + host + ":" + port + " is unresponsive"); - - if (this.sessionInProgress() && (failedHeartbeatCount < MAX_FAILED_HEARTBEATS)) { - LOGGER.warn(String.format("... attempt %d of %d -- trying again.", failedHeartbeatCount + 1, MAX_FAILED_HEARTBEATS)); - - failedHeartbeatCount++; - return unreliable(); - } - else { - failedHeartbeatCount = 0; - return true; - } + } catch (final IOException ioe) { + LOGGER.warn("Remote Control at " + host + ":" + port + " is unresponsive", ioe); + return failedHeartBeat(); + } catch (final RuntimeException re) { + LOGGER.warn("Remote Control at " + host + ":" + port + " is unresponsive", re); + return failedHeartBeat(); } if (response.statusCode() != 200) { LOGGER.warn("Remote Control at " + host + ":" + port + " did not respond correctly"); - - if (this.sessionInProgress() && (failedHeartbeatCount < MAX_FAILED_HEARTBEATS)) { - LOGGER.warn(String.format("... attempt %d of %d -- trying again.", failedHeartbeatCount + 1, MAX_FAILED_HEARTBEATS)); - - failedHeartbeatCount++; - return unreliable(); - } - else { - failedHeartbeatCount = 0; - return true; - } + return failedHeartBeat(); } failedHeartbeatCount = 0; return false; } - public String sessionId() { - return sessionId; - } + public boolean failedHeartBeat() { + if (sessionInProgress() && (failedHeartbeatCount < MAX_FAILED_HEARTBEATS)) { + LOGGER.warn(String.format("... attempt %d of %d -- trying again.", failedHeartbeatCount + 1, MAX_FAILED_HEARTBEATS)); + + failedHeartbeatCount++; + return unreliable(); + } + else { + failedHeartbeatCount = 0; + return true; + } + } + + public String sessionId() { + return sessionId; + } - public void setSessionId(String sessionId){ - this.sessionId = sessionId; - } + public void setSessionId(String sessionId){ + this.sessionId = sessionId; + } }