private void doHttpMaxFailover() {
   long maxTimeAgo = clock.now() - silentPeriodForMaxHttpRequest;
   if (!httpRequestControl.requestQueued(HttpRequestControl.RequestReason.MAX)
       && UpdateSettings.LAST_SIMPP_FAILOVER.getValue() < maxTimeAgo) {
     int rndDelay = RANDOM.nextInt(maxMaxHttpRequestDelay) + minMaxHttpRequestDelay;
     final String rndUri = maxedUpdateList.get(RANDOM.nextInt(maxedUpdateList.size()));
     LOG.debug("Scheduling http max failover in: " + rndDelay + ", to: " + rndUri);
     backgroundExecutor.schedule(
         new Runnable() {
           public void run() {
             String url = rndUri;
             try {
               launchHTTPUpdate(url);
             } catch (URISyntaxException e) {
               httpRequestControl.requestFinished();
               httpRequestControl.cancelRequest();
               LOG.warn("uri failure", e);
             }
           }
         },
         rndDelay,
         TimeUnit.MILLISECONDS);
   } else {
     LOG.debug("Ignoring http max failover.");
   }
 }
Пример #2
0
  /** begins an http failover. */
  private void checkForStaleUpdateAndMaybeDoHttpFailover() {
    LOG.debug("checking for timeout http failover");
    long monthAgo = clock.now() - ONE_MONTH;
    if (UpdateSettings.LAST_UPDATE_TIMESTAMP.getValue() < monthAgo
        && // more than a month ago
        UpdateSettings.LAST_HTTP_FAILOVER.getValue() < monthAgo
        && // and last failover too
        !httpRequestControl.requestQueued(
            HttpRequestControl.RequestReason.TIMEOUT)) { // and we're not already doing a failover

      long when = (connectionServices.isConnected() ? 1 : 5) * 60 * 1000;
      if (LOG.isDebugEnabled()) LOG.debug("scheduling http failover in " + when);

      backgroundExecutor.schedule(
          new Runnable() {
            public void run() {
              try {
                launchHTTPUpdate(timeoutUpdateLocation);
              } catch (URISyntaxException e) {
                httpRequestControl.requestFinished();
                httpRequestControl.cancelRequest();
                LOG.warn(e.toString(), e);
              }
            }
          },
          when,
          TimeUnit.MILLISECONDS);
    }
  }