protected URL getServerURL() throws RetryAfterException { // FIXME not sure if this is the proper place URL serverURL = getDiscoveryHandler().getServerUrl(); if (serverURL == null) { throw new RetryAfterException(10); } return serverURL; }
@Override public void run() { long interval = m_syncDelay.get(); while (!isInterrupted()) { try { logDebug("Scheduling controller to run in %d seconds...", interval); TimeUnit.SECONDS.sleep(interval); logDebug("Controller syncing..."); runFeedback(); runAgentUpdate(); runDeploymentUpdate(); interval = m_interval.get(); logDebug("Sync completed..."); } catch (RetryAfterException e) { // any method may throw this causing the sync to abort. The server is busy so no sense in trying // anything else until the retry window has passed. interval = e.getBackoffTime(); logWarning("Sync received retry exception from server. Rescheduled in %d seconds...", interval); } catch (InterruptedException exception) { logDebug(exception.getMessage()); // Ok; break out of our main loop... Thread.currentThread().interrupt(); } } }
/** * Check the server response code and throws exceptions if it is not 200. * * @param connection * The connection to check * @throws RetryAfterException * If the server response is 503 indicating it is not (yet) available. The backoff time (= minimum time * to wait) is included in this exception; * @throws IOException * If the server response is any other code than 200 or 503. */ public static void checkConnectionResponse(URLConnection connection) throws RetryAfterException, IOException { int responseCode = getResponseCode(connection); switch (responseCode) { case 200: case 206: return; case 503: int retry = ((HttpURLConnection) connection).getHeaderFieldInt(HTTP_RETRY_AFTER, DEFAULT_RETRY_TIME); throw new RetryAfterException(retry); default: throw new IOException("Unable to handle server responsecode: " + responseCode + ", for " + connection.getURL()); } }
throw new RetryAfterException(retry);