com.amazonaws.mturk.filter
Class RetryFilter

java.lang.Object
  extended by com.amazonaws.mturk.filter.Filter
      extended by com.amazonaws.mturk.filter.RetryFilter

public class RetryFilter
extends Filter

Default Filter implementation which handles retry of operation on receiving certain retriable errors which can be configured in the SDK configuration (retriable_errors)


Constructor Summary
RetryFilter()
          Use this constructor if you do not want to retry any error
RetryFilter(java.util.Set<java.lang.String> retriableErrorSet, int retryMaxAttempts, long retryDelayMillis)
           
 
Method Summary
 void addRetriableError(java.lang.String error)
           
 Reply execute(Message m)
          Calls the next filter and catches ServiceException.
protected  long getDelay(int retry)
          Calculates the delay during retries including a jitter
 java.util.Set<java.lang.String> getRetriableErrors()
           
 long getRetryDelayMillis()
           
 int getRetryMaxAttempts()
           
 void setRetriableErrors(java.util.Set<java.lang.String> retriableErrors)
           
 void setRetryDelayMillis(long retryDelayMillis)
           
 void setRetryMaxAttempts(int retryMaxAttempts)
           
protected  boolean shouldRetry(ServiceException e, java.lang.Object requests)
           
 
Methods inherited from class com.amazonaws.mturk.filter.Filter
isRemovable, linkFilters, passMessage
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RetryFilter

public RetryFilter()
Use this constructor if you do not want to retry any error


RetryFilter

public RetryFilter(java.util.Set<java.lang.String> retriableErrorSet,
                   int retryMaxAttempts,
                   long retryDelayMillis)
Parameters:
retriableErrorSet - - set of errors which should be retried
retryMaxAttempts - - maximum number of retry attempts
retryDelayMillis - - delay between retry attempts
Method Detail

getRetriableErrors

public java.util.Set<java.lang.String> getRetriableErrors()

setRetriableErrors

public void setRetriableErrors(java.util.Set<java.lang.String> retriableErrors)
Parameters:
retriableErrors - - sets retriable errors set

addRetriableError

public void addRetriableError(java.lang.String error)
Parameters:
error - - error code for adding to the set of retriable errors

getRetryMaxAttempts

public int getRetryMaxAttempts()

setRetryMaxAttempts

public void setRetryMaxAttempts(int retryMaxAttempts)

getRetryDelayMillis

public long getRetryDelayMillis()

setRetryDelayMillis

public void setRetryDelayMillis(long retryDelayMillis)

execute

public Reply execute(Message m)
              throws ServiceException
Calls the next filter and catches ServiceException. Checks if error is one of the retriable errors and retries. throws ServiceException if it retry fails or not retriable

Specified by:
execute in class Filter
Parameters:
m - - request message got from previous filter
Returns:
result of the execution of this filter throws ServiceException on errors
Throws:
ServiceException

shouldRetry

protected boolean shouldRetry(ServiceException e,
                              java.lang.Object requests)
Parameters:
e - - exception caught
requests - - the requests which caused the exception
Returns:
true if the request can be retried. i.e. check the retriable error set

getDelay

protected long getDelay(int retry)
Calculates the delay during retries including a jitter