org.springframework.batch.retry.backoff
Class ExponentialBackOffPolicy

java.lang.Object
  extended by org.springframework.batch.retry.backoff.ExponentialBackOffPolicy
All Implemented Interfaces:
BackOffPolicy

public class ExponentialBackOffPolicy
extends Object
implements BackOffPolicy

Implementation of BackOffPolicy that increases the back off period for each retry attempt in a given set using the exponential function.

This implementation is thread-safe and suitable for concurrent access. Modifications to the configuration do not affect any retry sets that are already in progress.

The setInitialInterval(long) property controls the initial value passed to Math.exp(double) and the setMultiplier(double) property controls by how much this value is increased for each subsequent attempt.

Author:
Rob Harrop, Dave Syer

Field Summary
static long DEFAULT_INITIAL_INTERVAL
          The default 'initialInterval' value - 100 millisecs.
static long DEFAULT_MAX_INTERVAL
          The default maximum backoff time (30 seconds).
static double DEFAULT_MULTIPLIER
          The default 'multiplier' value - value 2 (100% increase per backoff).
 
Constructor Summary
ExponentialBackOffPolicy()
           
 
Method Summary
 void backOff(BackOffContext backOffContext)
          Pause for a length of time equal to 'exp(backOffContext.expSeed)'.
 void setInitialInterval(long initialInterval)
          Set the initial sleep interval value.
 void setMaxInterval(long maxInterval)
          Setter for maximum back off period.
 void setMultiplier(double multiplier)
          Set the multiplier value.
 void setSleeper(Sleeper sleeper)
          Public setter for the Sleeper strategy.
 BackOffContext start(RetryContext context)
          Returns a new instance of BackOffContext configured with the 'expSeed' and 'increment' values.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_INITIAL_INTERVAL

public static final long DEFAULT_INITIAL_INTERVAL
The default 'initialInterval' value - 100 millisecs. Coupled with the default 'multiplier' value this gives a useful initial spread of pauses for 1-5 retries.

See Also:
Constant Field Values

DEFAULT_MAX_INTERVAL

public static final long DEFAULT_MAX_INTERVAL
The default maximum backoff time (30 seconds).

See Also:
Constant Field Values

DEFAULT_MULTIPLIER

public static final double DEFAULT_MULTIPLIER
The default 'multiplier' value - value 2 (100% increase per backoff).

See Also:
Constant Field Values
Constructor Detail

ExponentialBackOffPolicy

public ExponentialBackOffPolicy()
Method Detail

setSleeper

public void setSleeper(Sleeper sleeper)
Public setter for the Sleeper strategy.

Parameters:
sleeper - the sleeper to set defaults to ObjectWaitSleeper.

setInitialInterval

public void setInitialInterval(long initialInterval)
Set the initial sleep interval value. Default is 1 millisecond. Cannot be set to a value less than one.


setMultiplier

public void setMultiplier(double multiplier)
Set the multiplier value. Default is '1.0'.


setMaxInterval

public void setMaxInterval(long maxInterval)
Setter for maximum back off period. Default is 30000 (30 seconds). the value will be reset to 1 if this method is called with a value less than 1.

Parameters:
maxInterval - in milliseconds.

start

public BackOffContext start(RetryContext context)
Returns a new instance of BackOffContext configured with the 'expSeed' and 'increment' values.

Specified by:
start in interface BackOffPolicy
Parameters:
context - the current retry context, which might contain information that we can use to decide how to proceed.
Returns:
the implementation-specific BackOffContext or 'null'.

backOff

public void backOff(BackOffContext backOffContext)
             throws BackOffInterruptedException
Pause for a length of time equal to 'exp(backOffContext.expSeed)'.

Specified by:
backOff in interface BackOffPolicy
Throws:
BackOffInterruptedException - if the attempt at back off is interrupted.

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2009 SpringSource. All Rights Reserved.