org.apache.camel.processor
Class RedeliveryErrorHandler

java.lang.Object
  extended by org.apache.camel.impl.ServiceSupport
      extended by org.apache.camel.processor.ErrorHandlerSupport
          extended by org.apache.camel.processor.RedeliveryErrorHandler
All Implemented Interfaces:
AsyncProcessor, Processor, ErrorHandler, Service, ShutdownableService
Direct Known Subclasses:
DeadLetterChannel, DefaultErrorHandler, TransactionErrorHandler

public abstract class RedeliveryErrorHandler
extends ErrorHandlerSupport
implements AsyncProcessor

Base redeliverable error handler that also supports a final dead letter queue in case all redelivery attempts fail.

This implementation should contain all the error handling logic and the sub classes should only configure it according to what they support.

Version:
$Revision: 21784 $

Nested Class Summary
protected  class RedeliveryErrorHandler.RedeliveryData
          Contains the current redelivery data
 
Field Summary
protected  CamelContext camelContext
           
protected  Processor deadLetter
           
protected  String deadLetterUri
           
protected  Predicate handledPolicy
           
protected  Logger logger
           
protected  Processor output
           
protected  AsyncProcessor outputAsync
           
protected  RedeliveryPolicy redeliveryPolicy
           
protected  Processor redeliveryProcessor
           
protected  Predicate retryWhilePolicy
           
protected  boolean useOriginalMessagePolicy
           
 
Fields inherited from class org.apache.camel.processor.ErrorHandlerSupport
log
 
Constructor Summary
RedeliveryErrorHandler(CamelContext camelContext, Processor output, Logger logger, Processor redeliveryProcessor, RedeliveryPolicy redeliveryPolicy, Predicate handledPolicy, Processor deadLetter, String deadLetterUri, boolean useOriginalMessagePolicy, Predicate retryWhile)
           
 
Method Summary
protected  boolean deliverToFailureProcessor(Processor processor, Exchange exchange, RedeliveryErrorHandler.RedeliveryData data, AsyncCallback callback)
          All redelivery attempts failed so move the exchange to the dead letter queue
protected  void deliverToOnRedeliveryProcessor(Exchange exchange, RedeliveryErrorHandler.RedeliveryData data)
          Gives an optional configure redelivery processor a chance to process before the Exchange will be redelivered.
protected  void doStart()
           
protected  void doStop()
           
 Processor getDeadLetter()
          Returns the dead letter that message exchanges will be sent to if the redelivery attempts fail
 String getDeadLetterUri()
           
 Logger getLogger()
           
 Processor getOutput()
          Returns the output processor
 RedeliveryPolicy getRedeliveryPolicy()
           
protected  void handleException(Exchange exchange, RedeliveryErrorHandler.RedeliveryData data)
           
protected  boolean isCancelledOrInterrupted(Exchange exchange)
          Strategy to determine if the exchange was cancelled or interrupted
protected  boolean isDone(Exchange exchange)
          Strategy to determine if the exchange is done so we can continue
 boolean isUseOriginalMessagePolicy()
           
protected  void prepareExchangeAfterFailure(Exchange exchange, RedeliveryErrorHandler.RedeliveryData data)
           
protected  void prepareExchangeForContinue(Exchange exchange, RedeliveryErrorHandler.RedeliveryData data)
           
protected  void prepareExchangeForRedelivery(Exchange exchange)
           
 void process(Exchange exchange)
          Processes the message exchange
 boolean process(Exchange exchange, AsyncCallback callback)
          Processes the message exchange.
protected  void processAsyncErrorHandler(Exchange exchange, AsyncCallback callback, RedeliveryErrorHandler.RedeliveryData data)
          This logic is only executed if we have to retry redelivery asynchronously, which have to be done from the callback.
protected  boolean processErrorHandler(Exchange exchange, AsyncCallback callback, RedeliveryErrorHandler.RedeliveryData data)
          Process the exchange using redelivery error handling.
protected  boolean shouldHandleException(Exchange exchange)
          Strategy whether the exchange has an exception that we should try to handle.
 boolean supportTransacted()
          Whether this error handler supports transacted exchanges or not.
 
Methods inherited from class org.apache.camel.processor.ErrorHandlerSupport
addExceptionPolicy, createDefaultExceptionPolicyStrategy, customProcessorForException, getExceptionPolicy, setExceptionPolicy
 
Methods inherited from class org.apache.camel.impl.ServiceSupport
addChildService, doResume, doShutdown, doSuspend, getStatus, getVersion, isRunAllowed, isStarted, isStarting, isStopped, isStopping, isSuspended, isSuspending, removeChildService, resume, shutdown, start, start, stop, suspend
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

camelContext

protected final CamelContext camelContext

deadLetter

protected final Processor deadLetter

deadLetterUri

protected final String deadLetterUri

output

protected final Processor output

outputAsync

protected final AsyncProcessor outputAsync

redeliveryProcessor

protected final Processor redeliveryProcessor

redeliveryPolicy

protected final RedeliveryPolicy redeliveryPolicy

handledPolicy

protected final Predicate handledPolicy

retryWhilePolicy

protected final Predicate retryWhilePolicy

logger

protected final Logger logger

useOriginalMessagePolicy

protected final boolean useOriginalMessagePolicy
Constructor Detail

RedeliveryErrorHandler

public RedeliveryErrorHandler(CamelContext camelContext,
                              Processor output,
                              Logger logger,
                              Processor redeliveryProcessor,
                              RedeliveryPolicy redeliveryPolicy,
                              Predicate handledPolicy,
                              Processor deadLetter,
                              String deadLetterUri,
                              boolean useOriginalMessagePolicy,
                              Predicate retryWhile)
Method Detail

supportTransacted

public boolean supportTransacted()
Description copied from class: ErrorHandlerSupport
Whether this error handler supports transacted exchanges or not.

Specified by:
supportTransacted in class ErrorHandlerSupport

process

public void process(Exchange exchange)
             throws Exception
Description copied from interface: Processor
Processes the message exchange

Specified by:
process in interface Processor
Parameters:
exchange - the message exchange
Throws:
Exception - if an internal processing error has occurred.

process

public boolean process(Exchange exchange,
                       AsyncCallback callback)
Description copied from interface: AsyncProcessor
Processes the message exchange. Similar to Processor.process(org.apache.camel.Exchange), but the caller supports having the exchange asynchronously processed.

If there was a failure processing then the caused Exception would be set on the Exchange.

Specified by:
process in interface AsyncProcessor
Parameters:
exchange - the message exchange
callback - the AsyncCallback will be invoked when the processing of the exchange is completed. If the exchange is completed synchronously, then the callback is also invoked synchronously. The callback should therefore be careful of starting recursive loop.
Returns:
(doneSync) true to continue execute synchronously, false to continue being executed asynchronously
See Also:
AsyncProcessorHelper.process(AsyncProcessor, Exchange, AsyncCallback)

processErrorHandler

protected boolean processErrorHandler(Exchange exchange,
                                      AsyncCallback callback,
                                      RedeliveryErrorHandler.RedeliveryData data)
Process the exchange using redelivery error handling.


processAsyncErrorHandler

protected void processAsyncErrorHandler(Exchange exchange,
                                        AsyncCallback callback,
                                        RedeliveryErrorHandler.RedeliveryData data)
This logic is only executed if we have to retry redelivery asynchronously, which have to be done from the callback.

And therefore the logic is a bit different than the synchronous processErrorHandler method which can use a loop based redelivery technique. However this means that these two methods in overall have to be in sync in terms of logic.


shouldHandleException

protected boolean shouldHandleException(Exchange exchange)
Strategy whether the exchange has an exception that we should try to handle.

Standard implementations should just look for an exception.


isDone

protected boolean isDone(Exchange exchange)
Strategy to determine if the exchange is done so we can continue


isCancelledOrInterrupted

protected boolean isCancelledOrInterrupted(Exchange exchange)
Strategy to determine if the exchange was cancelled or interrupted


getOutput

public Processor getOutput()
Returns the output processor

Specified by:
getOutput in class ErrorHandlerSupport

getDeadLetter

public Processor getDeadLetter()
Returns the dead letter that message exchanges will be sent to if the redelivery attempts fail


getDeadLetterUri

public String getDeadLetterUri()

isUseOriginalMessagePolicy

public boolean isUseOriginalMessagePolicy()

getRedeliveryPolicy

public RedeliveryPolicy getRedeliveryPolicy()

getLogger

public Logger getLogger()

prepareExchangeForContinue

protected void prepareExchangeForContinue(Exchange exchange,
                                          RedeliveryErrorHandler.RedeliveryData data)

prepareExchangeForRedelivery

protected void prepareExchangeForRedelivery(Exchange exchange)

handleException

protected void handleException(Exchange exchange,
                               RedeliveryErrorHandler.RedeliveryData data)

deliverToOnRedeliveryProcessor

protected void deliverToOnRedeliveryProcessor(Exchange exchange,
                                              RedeliveryErrorHandler.RedeliveryData data)
Gives an optional configure redelivery processor a chance to process before the Exchange will be redelivered. This can be used to alter the Exchange.


deliverToFailureProcessor

protected boolean deliverToFailureProcessor(Processor processor,
                                            Exchange exchange,
                                            RedeliveryErrorHandler.RedeliveryData data,
                                            AsyncCallback callback)
All redelivery attempts failed so move the exchange to the dead letter queue


prepareExchangeAfterFailure

protected void prepareExchangeAfterFailure(Exchange exchange,
                                           RedeliveryErrorHandler.RedeliveryData data)

doStart

protected void doStart()
                throws Exception
Specified by:
doStart in class ServiceSupport
Throws:
Exception

doStop

protected void doStop()
               throws Exception
Specified by:
doStop in class ServiceSupport
Throws:
Exception


Apache CAMEL