Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2012-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License"). You may not
   * use this file except in compliance with the License. A copy of the License is
   * located at
   * 
   * http://aws.amazon.com/apache2.0
   * 
  * or in the "license" file accompanying this file. This file is distributed on
  * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
  * express or implied. See the License for the specific language governing
  * permissions and limitations under the License.
  */
 package com.amazonaws.services.simpleworkflow.flow.interceptors;
 
 import java.util.Date;
 
 
 public class ExponentialRetryPolicy extends RetryPolicyBase {
 
     private final long initialRetryIntervalSeconds;
 
 
 
 
 
     public ExponentialRetryPolicy(long initialRetryIntervalSeconds) {
         this. = initialRetryIntervalSeconds;
     }
 
     public long getInitialRetryIntervalSeconds() {
         return ;
     }
 
     public long getMaximumRetryIntervalSeconds() {
         return ;
     }

    
Set the upper limit of retry interval. No limit by default.
 
     public void setMaximumRetryIntervalSeconds(long maximumRetryIntervalSeconds) {
         this. = maximumRetryIntervalSeconds;
     }
 
     public ExponentialRetryPolicy withMaximumRetryIntervalSeconds(long maximumRetryIntervalSeconds) {
         this. = maximumRetryIntervalSeconds;
         return this;
     }
 
     public long getRetryExpirationIntervalSeconds() {
         return ;
     }

    
Stop retrying after the specified interval.
 
     public void setRetryExpirationIntervalSeconds(long retryExpirationIntervalSeconds) {
         this. = retryExpirationIntervalSeconds;
     }
 
     public ExponentialRetryPolicy withRetryExpirationIntervalSeconds(long retryExpirationIntervalSeconds) {
         this. = retryExpirationIntervalSeconds;
         return this;
     }
 
     public double getBackoffCoefficient() {
         return ;
     }

    
Coefficient used to calculate the next retry interval. The following formula is used: initialRetryIntervalSeconds * Math.pow(backoffCoefficient, numberOfTries - 2)
 
     public void setBackoffCoefficient(double backoffCoefficient) {
         this. = backoffCoefficient;
     }
 
     public ExponentialRetryPolicy withBackoffCoefficient(double backoffCoefficient) {
         this. = backoffCoefficient;
         return this;
     }
 
     public int getMaximumAttempts() {
         return ;
     }

    
Maximum number of attempts. The first retry is second attempt.
 
    public void setMaximumAttempts(int maximumAttempts) {
        this. = maximumAttempts;
    }
    public ExponentialRetryPolicy withMaximumAttempts(int maximumAttempts) {
        this. = maximumAttempts;
        return this;
    }

    
The exception types that cause operation being retried. Subclasses of the specified types are also included. Default is Throwable.class which means retry any exceptions.
    @Override
    public ExponentialRetryPolicy withExceptionsToRetry(Collection<Class<? extends Throwable>> exceptionsToRetry) {
        super.withExceptionsToRetry(exceptionsToRetry);
        return this;
    }

    
The exception types that should not be retried. Subclasses of the specified types are also not retried. Default is empty list.
    @Override
    public ExponentialRetryPolicy withExceptionsToExclude(Collection<Class<? extends Throwable>> exceptionsToRetry) {
        super.withExceptionsToExclude(exceptionsToRetry);
        return this;
    }
    @Override
    public long nextRetryDelaySeconds(Date firstAttemptDate recordedFailureint numberOfTries) {
        if (numberOfTries < 2) {
            throw new IllegalArgumentException("attempt is less then 2: " + numberOfTries);
        }
        if ( > . && numberOfTries > ) {
            return .;
        }
        long result = (long) ( * Math.pow(numberOfTries - 2));
        result =  > . ? Math.min(result) : result;
        int secondsSinceFirstAttempt = (int) ((recordedFailure.getTime() - firstAttempt.getTime()) / 1000);
                && secondsSinceFirstAttempt + result >= ) {
            return .;
        }
        return result;
    }

    
Performs the following three validation checks for ExponentialRetry Policy: 1) initialRetryIntervalSeconds is not greater than maximumRetryIntervalSeconds 2) initialRetryIntervalSeconds is not greater than retryExpirationIntervalSeconds
    public void validate() throws IllegalStateException {
            throw new IllegalStateException(
                    "ExponentialRetryPolicy requires maximumRetryIntervalSeconds to have a value larger than initialRetryIntervalSeconds.");
        }
            throw new IllegalStateException(
                    "ExponentialRetryPolicy requires retryExpirationIntervalSeconds to have a value larger than initialRetryIntervalSeconds.");
        }
    }
New to GrepCode? Check out our FAQ X