@Override protected void configure() { requireBinding(CommandLineArguments.class); bind(GmailService.class).in(Singleton.class); bind(Credential.class) .toProvider(Authorizer.class) .in(Singleton.class); bind(ExponentialBackOff.Builder.class) .toInstance(new ExponentialBackOff.Builder() .setInitialIntervalMillis(1000) .setMultiplier(2) .setRandomizationFactor(0.5) .setMaxIntervalMillis(60000) .setMaxElapsedTimeMillis(300000)); }
.setMultiplier(1.3) .setMaxIntervalMillis(Ints.checkedCast(TimeUnit.SECONDS.toMillis(60))) .setMaxElapsedTimeMillis(Ints.checkedCast(timeUnit.toMillis(timeout)))
/** Creates new generic BackOff used for retries. */ @VisibleForTesting ExponentialBackOff createBackOff() { return new ExponentialBackOff.Builder() .setInitialIntervalMillis(readOptions.getBackoffInitialIntervalMillis()) .setRandomizationFactor(readOptions.getBackoffRandomizationFactor()) .setMultiplier(readOptions.getBackoffMultiplier()) .setMaxIntervalMillis(readOptions.getBackoffMaxIntervalMillis()) .setMaxElapsedTimeMillis(readOptions.getBackoffMaxElapsedTimeMillis()) .setNanoClock(clock) .build(); }
.setMaxIntervalMillis(500) .setInitialIntervalMillis(100) .setMultiplier(1.5) .setRandomizationFactor(0.15) .build();
@Override public void initialize(HttpRequest request) throws IOException { // Set a timeout for hanging-gets. // TODO: Do this exclusively for work requests. request.setReadTimeout(HANGING_GET_TIMEOUT_SEC * 1000); request.setWriteTimeout(this.writeTimeout); LoggingHttpBackOffHandler loggingHttpBackOffHandler = new LoggingHttpBackOffHandler( sleeper, // Back off on retryable http errors and IOExceptions. // A back-off multiplier of 2 raises the maximum request retrying time // to approximately 5 minutes (keeping other back-off parameters to // their default values). new ExponentialBackOff.Builder().setNanoClock(nanoClock).setMultiplier(2).build(), new ExponentialBackOff.Builder().setNanoClock(nanoClock).setMultiplier(2).build(), ignoredResponseCodes); request.setUnsuccessfulResponseHandler(loggingHttpBackOffHandler); request.setIOExceptionHandler(loggingHttpBackOffHandler); // Set response initializer if (responseInterceptor != null) { request.setResponseInterceptor(responseInterceptor); } }
/** * Returns {@link BackOff} instance used for implementing exponential back off for failed * requests. */ @Override public BackOff createBackOffInstance() { return new ExponentialBackOff.Builder() .setInitialIntervalMillis(INITIAL_DELAY_SECONDS * 1000) .setMultiplier(MULTIPLIER) .build(); } }
public BackOffUtil(boolean isExponential) { if (isExponential) { // aggressive backOff = new ExponentialBackOff.Builder() .setInitialIntervalMillis(2) .setMaxElapsedTimeMillis(Integer.MAX_VALUE) .setMaxIntervalMillis(Integer.MAX_VALUE) .setMultiplier(1.5) .setRandomizationFactor(0) .build(); } else { // conservative backOff = new FixedBackOff(); } }