org.apache.camel.processor
Class RedeliveryPolicy

java.lang.Object
  extended by org.apache.camel.processor.RedeliveryPolicy
All Implemented Interfaces:
Serializable, Cloneable

public class RedeliveryPolicy
extends Object
implements Cloneable, Serializable

The policy used to decide how many times to redeliver and the time between the redeliveries before being sent to a Dead Letter Channel

The default values are:

Setting the maximumRedeliveries to a negative value such as -1 will then always redeliver (unlimited). Setting the maximumRedeliveries to 0 will disable redelivery.

This policy can be configured either by one of the following two settings:

Note: If using delay patterns then the following options is not used (delay, backOffMultiplier, useExponentialBackOff, useCollisionAvoidance)

Using delay pattern:
The delay pattern syntax is: limit:delay;limit 2:delay 2;limit 3:delay 3;...;limit N:delay N.

How it works is best illustrate with an example with this pattern: delayPattern=5:1000;10:5000:20:20000
The delays will be for attempt in range 0..4 = 0 millis, 5..9 = 1000 millis, 10..19 = 5000 millis, >= 20 = 20000 millis.

If you want to set a starting delay, then use 0 as the first limit, eg: 0:1000;5:5000 will use 1 sec delay until attempt number 5 where it will use 5 seconds going forward.

Version:
$Revision: 17666 $
See Also:
Serialized Form

Field Summary
protected  double backOffMultiplier
           
protected  double collisionAvoidanceFactor
           
protected  String delayPattern
           
protected  boolean logRetryStackTrace
           
protected  boolean logStackTrace
           
protected  int maximumRedeliveries
           
protected  long maximumRedeliveryDelay
           
protected static Random randomNumberGenerator
           
protected  long redeliverDelay
           
protected  LoggingLevel retriesExhaustedLogLevel
           
protected  LoggingLevel retryAttemptedLogLevel
           
protected  boolean useCollisionAvoidance
           
protected  boolean useExponentialBackOff
           
 
Constructor Summary
RedeliveryPolicy()
           
 
Method Summary
 RedeliveryPolicy backOffMultiplier(double multiplier)
          Enables exponential backoff and sets the multiplier used to increase the delay between redeliveries
protected static long calculateRedeliverDelayUsingPattern(String delayPattern, int redeliveryCounter)
          Calculates the delay using the delay pattern
protected  long calculateRedeliveryDelay(long previousDelay, int redeliveryCounter)
           
 RedeliveryPolicy collisionAvoidancePercent(double collisionAvoidancePercent)
          Enables collision avoidance and sets the percentage used
 RedeliveryPolicy copy()
           
 RedeliveryPolicy delayPattern(String delayPattern)
          Sets the delay pattern with delay intervals.
 RedeliveryPolicy disableRedelivery()
          Disables redelivery by setting maximum redeliveries to 0.
 double getBackOffMultiplier()
           
 double getCollisionAvoidanceFactor()
           
 long getCollisionAvoidancePercent()
           
 String getDelayPattern()
           
 int getMaximumRedeliveries()
           
 long getMaximumRedeliveryDelay()
           
protected static Random getRandomNumberGenerator()
           
 long getRedeliverDelay()
           
 LoggingLevel getRetriesExhaustedLogLevel()
           
 LoggingLevel getRetryAttemptedLogLevel()
           
 boolean isLogRetryStackTrace()
           
 boolean isLogStackTrace()
           
 boolean isUseCollisionAvoidance()
           
 boolean isUseExponentialBackOff()
           
 RedeliveryPolicy logRetryStackTrace(boolean logRetryStackTrace)
          Sets whether to log stacktrace for failed redelivery attempts
 RedeliveryPolicy logStackTrace(boolean logStackTrace)
          Sets whether to log stacktraces for failed messages.
 RedeliveryPolicy maximumRedeliveries(int maximumRedeliveries)
          Sets the maximum number of times a message exchange will be redelivered
 RedeliveryPolicy maximumRedeliveryDelay(long maximumRedeliveryDelay)
          Sets the maximum redelivery delay if using exponential back off.
 RedeliveryPolicy redeliverDelay(long delay)
          Sets the delay in milliseconds
 RedeliveryPolicy retriesExhaustedLogLevel(LoggingLevel retriesExhaustedLogLevel)
          Sets the logging level to use for log messages when retries have been exhausted.
 RedeliveryPolicy retryAttemptedLogLevel(LoggingLevel retryAttemptedLogLevel)
          Sets the logging level to use for log messages when retries are attempted.
 void setBackOffMultiplier(double backOffMultiplier)
          Sets the multiplier used to increase the delay between redeliveries if setUseExponentialBackOff(boolean) is enabled
 void setCollisionAvoidanceFactor(double collisionAvoidanceFactor)
          Sets the factor used for collision avoidance if enabled via setUseCollisionAvoidance(boolean)
 void setCollisionAvoidancePercent(double collisionAvoidancePercent)
          Sets the percentage used for collision avoidance if enabled via setUseCollisionAvoidance(boolean)
 void setDelayPattern(String delayPattern)
          Sets an optional delay pattern to use instead of fixed delay.
 void setLogRetryStackTrace(boolean logRetryStackTrace)
          Sets whether stack traces should be logged or not
 void setLogStackTrace(boolean logStackTrace)
          Sets whether stack traces should be logged or not
 void setMaximumRedeliveries(int maximumRedeliveries)
          Sets the maximum number of times a message exchange will be redelivered.
 void setMaximumRedeliveryDelay(long maximumRedeliveryDelay)
          Sets the maximum redelivery delay.
 void setRedeliverDelay(long redeliverDelay)
          Sets the delay in milliseconds
 void setRetriesExhaustedLogLevel(LoggingLevel retriesExhaustedLogLevel)
          Sets the logging level to use for log messages when retries have been exhausted.
 void setRetryAttemptedLogLevel(LoggingLevel retryAttemptedLogLevel)
          Sets the logging level to use for log messages when retries are attempted.
 void setUseCollisionAvoidance(boolean useCollisionAvoidance)
          Enables/disables collision avoidance which adds some randomization to the backoff timings to reduce contention probability
 void setUseExponentialBackOff(boolean useExponentialBackOff)
          Enables/disables exponential backoff using the getBackOffMultiplier() to increase the time between retries
 boolean shouldRedeliver(Exchange exchange, int redeliveryCounter, Predicate retryUntil)
          Returns true if the policy decides that the message exchange should be redelivered.
 long sleep(long redeliveryDelay, int redeliveryCounter)
          Calculates the new redelivery delay based on the last one then sleeps for the necessary amount of time
 String toString()
           
 RedeliveryPolicy useCollisionAvoidance()
          Enables collision avoidance which adds some randomization to the backoff timings to reduce contention probability
 RedeliveryPolicy useExponentialBackOff()
          Enables exponential backoff using the getBackOffMultiplier() to increase the time between retries
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

randomNumberGenerator

protected static transient Random randomNumberGenerator

redeliverDelay

protected long redeliverDelay

maximumRedeliveries

protected int maximumRedeliveries

maximumRedeliveryDelay

protected long maximumRedeliveryDelay

backOffMultiplier

protected double backOffMultiplier

useExponentialBackOff

protected boolean useExponentialBackOff

collisionAvoidanceFactor

protected double collisionAvoidanceFactor

useCollisionAvoidance

protected boolean useCollisionAvoidance

retriesExhaustedLogLevel

protected LoggingLevel retriesExhaustedLogLevel

retryAttemptedLogLevel

protected LoggingLevel retryAttemptedLogLevel

logStackTrace

protected boolean logStackTrace

logRetryStackTrace

protected boolean logRetryStackTrace

delayPattern

protected String delayPattern
Constructor Detail

RedeliveryPolicy

public RedeliveryPolicy()
Method Detail

toString

public String toString()
Overrides:
toString in class Object

copy

public RedeliveryPolicy copy()

shouldRedeliver

public boolean shouldRedeliver(Exchange exchange,
                               int redeliveryCounter,
                               Predicate retryUntil)
Returns true if the policy decides that the message exchange should be redelivered.

Parameters:
exchange - the current exchange
redeliveryCounter - the current retry counter
retryUntil - an optional predicate to determine if we should redeliver or not
Returns:
true to redeliver, false to stop

sleep

public long sleep(long redeliveryDelay,
                  int redeliveryCounter)
           throws InterruptedException
Calculates the new redelivery delay based on the last one then sleeps for the necessary amount of time

Parameters:
redeliveryDelay - previous redelivery delay
redeliveryCounter - number of previous redelivery attempts
Returns:
the calculate delay
Throws:
InterruptedException - is thrown if the sleep is interrupted likely because of shutdown

calculateRedeliveryDelay

protected long calculateRedeliveryDelay(long previousDelay,
                                        int redeliveryCounter)

calculateRedeliverDelayUsingPattern

protected static long calculateRedeliverDelayUsingPattern(String delayPattern,
                                                          int redeliveryCounter)
Calculates the delay using the delay pattern


redeliverDelay

public RedeliveryPolicy redeliverDelay(long delay)
Sets the delay in milliseconds


maximumRedeliveries

public RedeliveryPolicy maximumRedeliveries(int maximumRedeliveries)
Sets the maximum number of times a message exchange will be redelivered


useCollisionAvoidance

public RedeliveryPolicy useCollisionAvoidance()
Enables collision avoidance which adds some randomization to the backoff timings to reduce contention probability


useExponentialBackOff

public RedeliveryPolicy useExponentialBackOff()
Enables exponential backoff using the getBackOffMultiplier() to increase the time between retries


backOffMultiplier

public RedeliveryPolicy backOffMultiplier(double multiplier)
Enables exponential backoff and sets the multiplier used to increase the delay between redeliveries


collisionAvoidancePercent

public RedeliveryPolicy collisionAvoidancePercent(double collisionAvoidancePercent)
Enables collision avoidance and sets the percentage used


maximumRedeliveryDelay

public RedeliveryPolicy maximumRedeliveryDelay(long maximumRedeliveryDelay)
Sets the maximum redelivery delay if using exponential back off. Use -1 if you wish to have no maximum


retriesExhaustedLogLevel

public RedeliveryPolicy retriesExhaustedLogLevel(LoggingLevel retriesExhaustedLogLevel)
Sets the logging level to use for log messages when retries have been exhausted.


retryAttemptedLogLevel

public RedeliveryPolicy retryAttemptedLogLevel(LoggingLevel retryAttemptedLogLevel)
Sets the logging level to use for log messages when retries are attempted.


logStackTrace

public RedeliveryPolicy logStackTrace(boolean logStackTrace)
Sets whether to log stacktraces for failed messages.


logRetryStackTrace

public RedeliveryPolicy logRetryStackTrace(boolean logRetryStackTrace)
Sets whether to log stacktrace for failed redelivery attempts


delayPattern

public RedeliveryPolicy delayPattern(String delayPattern)
Sets the delay pattern with delay intervals.


disableRedelivery

public RedeliveryPolicy disableRedelivery()
Disables redelivery by setting maximum redeliveries to 0.


getRedeliverDelay

public long getRedeliverDelay()

setRedeliverDelay

public void setRedeliverDelay(long redeliverDelay)
Sets the delay in milliseconds


getBackOffMultiplier

public double getBackOffMultiplier()

setBackOffMultiplier

public void setBackOffMultiplier(double backOffMultiplier)
Sets the multiplier used to increase the delay between redeliveries if setUseExponentialBackOff(boolean) is enabled


getCollisionAvoidancePercent

public long getCollisionAvoidancePercent()

setCollisionAvoidancePercent

public void setCollisionAvoidancePercent(double collisionAvoidancePercent)
Sets the percentage used for collision avoidance if enabled via setUseCollisionAvoidance(boolean)


getCollisionAvoidanceFactor

public double getCollisionAvoidanceFactor()

setCollisionAvoidanceFactor

public void setCollisionAvoidanceFactor(double collisionAvoidanceFactor)
Sets the factor used for collision avoidance if enabled via setUseCollisionAvoidance(boolean)


getMaximumRedeliveries

public int getMaximumRedeliveries()

setMaximumRedeliveries

public void setMaximumRedeliveries(int maximumRedeliveries)
Sets the maximum number of times a message exchange will be redelivered. Setting a negative value will retry forever.


getMaximumRedeliveryDelay

public long getMaximumRedeliveryDelay()

setMaximumRedeliveryDelay

public void setMaximumRedeliveryDelay(long maximumRedeliveryDelay)
Sets the maximum redelivery delay. Use -1 if you wish to have no maximum


isUseCollisionAvoidance

public boolean isUseCollisionAvoidance()

setUseCollisionAvoidance

public void setUseCollisionAvoidance(boolean useCollisionAvoidance)
Enables/disables collision avoidance which adds some randomization to the backoff timings to reduce contention probability


isUseExponentialBackOff

public boolean isUseExponentialBackOff()

setUseExponentialBackOff

public void setUseExponentialBackOff(boolean useExponentialBackOff)
Enables/disables exponential backoff using the getBackOffMultiplier() to increase the time between retries


getRandomNumberGenerator

protected static Random getRandomNumberGenerator()

setRetriesExhaustedLogLevel

public void setRetriesExhaustedLogLevel(LoggingLevel retriesExhaustedLogLevel)
Sets the logging level to use for log messages when retries have been exhausted.


getRetriesExhaustedLogLevel

public LoggingLevel getRetriesExhaustedLogLevel()

setRetryAttemptedLogLevel

public void setRetryAttemptedLogLevel(LoggingLevel retryAttemptedLogLevel)
Sets the logging level to use for log messages when retries are attempted.


getRetryAttemptedLogLevel

public LoggingLevel getRetryAttemptedLogLevel()

getDelayPattern

public String getDelayPattern()

setDelayPattern

public void setDelayPattern(String delayPattern)
Sets an optional delay pattern to use instead of fixed delay.


isLogStackTrace

public boolean isLogStackTrace()

setLogStackTrace

public void setLogStackTrace(boolean logStackTrace)
Sets whether stack traces should be logged or not


isLogRetryStackTrace

public boolean isLogRetryStackTrace()

setLogRetryStackTrace

public void setLogRetryStackTrace(boolean logRetryStackTrace)
Sets whether stack traces should be logged or not



Copyright © 2007-2010 IONA Open Source Community. All Rights Reserved.