org.multiverse.api.backoff
Class ExponentialBackoffPolicy

java.lang.Object
  extended by org.multiverse.api.backoff.ExponentialBackoffPolicy
All Implemented Interfaces:
BackoffPolicy

public final class ExponentialBackoffPolicy
extends Object
implements BackoffPolicy

A BackoffPolicy that does an exponential backoff. So each next attempt, the delay is doubled until a configurable maximum delay has been reached.

The exponential growth of delay can be truncated by providing a maxDelay. If no max delay is provided, the maximum delay would be 10.000.000.000 seconds (292 years). So be careful with not using an acceptable maximum delay.

Author:
Peter Veentjer.

Field Summary
static ExponentialBackoffPolicy INSTANCE_100_MS_MAX
           
 
Constructor Summary
ExponentialBackoffPolicy()
          Creates an ExponentialBackoffPolicy with 100 nanoseconds as minimal delay and 100 milliseconds as maximum delay.
ExponentialBackoffPolicy(long minDelayNs, long maxDelay, TimeUnit unit)
          Creates an ExponentialBackoffPolicy with given maximum delay.
 
Method Summary
protected  long calcDelayNs(Transaction tx)
           
 void delay(Transaction t)
          Executes the delay.
 void delayedUninterruptible(Transaction t)
          Executes the delay without the possibility of being interrupted.
 long getMaxDelayNs()
          Returns the maximum delay in nanoseconds.
 long getMinDelayNs()
          Returns the minimum delay in nanoseconds.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INSTANCE_100_MS_MAX

public static final ExponentialBackoffPolicy INSTANCE_100_MS_MAX
Constructor Detail

ExponentialBackoffPolicy

public ExponentialBackoffPolicy()
Creates an ExponentialBackoffPolicy with 100 nanoseconds as minimal delay and 100 milliseconds as maximum delay.


ExponentialBackoffPolicy

public ExponentialBackoffPolicy(long minDelayNs,
                                long maxDelay,
                                TimeUnit unit)
Creates an ExponentialBackoffPolicy with given maximum delay.

Parameters:
minDelayNs - the minimum delay in nanoseconds to wait. If a negative or zero value provided, it will be interpreted that no external minimal value is needed.
maxDelay - the maximum delay.
unit - the unit of maxDelay.
Throws:
NullPointerException - if unit is null.
Method Detail

getMaxDelayNs

public long getMaxDelayNs()
Returns the maximum delay in nanoseconds. A negative or zero delay indicates that there is no max.

Returns:
the maximum delay in nanosecond.

getMinDelayNs

public long getMinDelayNs()
Returns the minimum delay in nanoseconds. A negative or zero value indicates that there is no minimal delay.

Returns:
the minimum delay in nanoseconds.

delay

public void delay(Transaction t)
           throws InterruptedException
Description copied from interface: BackoffPolicy
Executes the delay. This call is interruptible.

Specified by:
delay in interface BackoffPolicy
Parameters:
t - the transaction that is going to be restarted. The transaction should never be null, but it depends on the implementation if this is checked.
Throws:
InterruptedException - if the delay is interrupted.

delayedUninterruptible

public void delayedUninterruptible(Transaction t)
Description copied from interface: BackoffPolicy
Executes the delay without the possibility of being interrupted.

Specified by:
delayedUninterruptible in interface BackoffPolicy
Parameters:
t - the transaction that is going to be restarted. The transaction should never be null, but it depends on the implementation if this is checked.

calcDelayNs

protected long calcDelayNs(Transaction tx)


Copyright © 2008-2010 Multiverse. All Rights Reserved.