|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.camel.support.ServiceSupport org.apache.camel.support.ChildServiceSupport org.apache.camel.processor.ErrorHandlerSupport org.apache.camel.processor.RedeliveryErrorHandler
public abstract class RedeliveryErrorHandler
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.
Nested Class Summary | |
---|---|
protected class |
RedeliveryErrorHandler.RedeliveryData
Contains the current redelivery data |
Field Summary | |
---|---|
protected CamelContext |
camelContext
|
protected Processor |
deadLetter
|
protected String |
deadLetterUri
|
protected ExchangeFormatter |
exchangeFormatter
|
protected ScheduledExecutorService |
executorService
|
protected CamelLogger |
logger
|
protected Processor |
output
|
protected AsyncProcessor |
outputAsync
|
protected boolean |
preparingShutdown
|
protected boolean |
redeliveryEnabled
|
protected RedeliveryPolicy |
redeliveryPolicy
|
protected Processor |
redeliveryProcessor
|
protected Predicate |
retryWhilePolicy
|
protected boolean |
useOriginalMessagePolicy
|
Fields inherited from class org.apache.camel.processor.ErrorHandlerSupport |
---|
exceptionPolicies, exceptionPolicy, log |
Fields inherited from class org.apache.camel.support.ServiceSupport |
---|
shutdown, shuttingdown, started, starting, stopped, stopping, suspended, suspending |
Constructor Summary | |
---|---|
RedeliveryErrorHandler(CamelContext camelContext,
Processor output,
CamelLogger logger,
Processor redeliveryProcessor,
RedeliveryPolicy redeliveryPolicy,
Processor deadLetter,
String deadLetterUri,
boolean useOriginalMessagePolicy,
Predicate retryWhile,
ScheduledExecutorService executorService)
|
Method Summary | |
---|---|
protected Exchange |
defensiveCopyExchangeIfNeeded(Exchange exchange)
Performs a defensive copy of the exchange if needed |
protected boolean |
deliverToFailureProcessor(Processor processor,
boolean isDeadLetterChannel,
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 long |
determineRedeliveryDelay(Exchange exchange,
RedeliveryPolicy redeliveryPolicy,
long redeliveryDelay,
int redeliveryCounter)
Determines the redelivery delay time by first inspecting the Message header Exchange.REDELIVERY_DELAY
and if not present, defaulting to RedeliveryPolicy.calculateRedeliveryDelay(long, int) |
protected void |
doShutdown()
Implementations override this method to perform customized shutdown. |
protected void |
doStart()
Implementations override this method to support customized start/stop. |
protected void |
doStop()
Implementations override this method to support customized start/stop. |
Processor |
getDeadLetter()
Returns the dead letter that message exchanges will be sent to if the redelivery attempts fail |
String |
getDeadLetterUri()
|
protected Predicate |
getDefaultHandledPredicate()
|
CamelLogger |
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 |
protected boolean |
isRedeliveryAllowed(RedeliveryErrorHandler.RedeliveryData data)
|
protected boolean |
isRunAllowed(RedeliveryErrorHandler.RedeliveryData data)
|
protected boolean |
isRunAllowedOnPreparingShutdown()
|
boolean |
isUseOriginalMessagePolicy()
|
protected void |
prepareExchangeAfterFailure(Exchange exchange,
RedeliveryErrorHandler.RedeliveryData data,
boolean shouldHandle,
boolean shouldContinue)
|
protected void |
prepareExchangeForContinue(Exchange exchange,
RedeliveryErrorHandler.RedeliveryData data)
|
protected void |
prepareExchangeForRedelivery(Exchange exchange,
RedeliveryErrorHandler.RedeliveryData data)
|
void |
prepareShutdown(boolean forced)
Prepares for shutdown. |
void |
process(Exchange exchange)
Processes the message exchange |
boolean |
process(Exchange exchange,
AsyncCallback callback)
Process the exchange using redelivery error handling. |
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 |
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, getExceptionPolicy, isDeadLetterChannel, setExceptionPolicy |
Methods inherited from class org.apache.camel.support.ChildServiceSupport |
---|
addChildService, removeChildService, shutdown, start, start, stop |
Methods inherited from class org.apache.camel.support.ServiceSupport |
---|
doResume, doSuspend, getStatus, getVersion, isRunAllowed, isStarted, isStarting, isStopped, isStopping, isStoppingOrStopped, isSuspended, isSuspending, resume, suspend |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected ScheduledExecutorService executorService
protected final CamelContext camelContext
protected final Processor deadLetter
protected final String deadLetterUri
protected final Processor output
protected final AsyncProcessor outputAsync
protected final Processor redeliveryProcessor
protected final RedeliveryPolicy redeliveryPolicy
protected final Predicate retryWhilePolicy
protected final CamelLogger logger
protected final boolean useOriginalMessagePolicy
protected boolean redeliveryEnabled
protected volatile boolean preparingShutdown
protected final ExchangeFormatter exchangeFormatter
Constructor Detail |
---|
public RedeliveryErrorHandler(CamelContext camelContext, Processor output, CamelLogger logger, Processor redeliveryProcessor, RedeliveryPolicy redeliveryPolicy, Processor deadLetter, String deadLetterUri, boolean useOriginalMessagePolicy, Predicate retryWhile, ScheduledExecutorService executorService)
Method Detail |
---|
public boolean supportTransacted()
ErrorHandlerSupport
supportTransacted
in class ErrorHandlerSupport
protected boolean isRunAllowed(RedeliveryErrorHandler.RedeliveryData data)
protected boolean isRunAllowedOnPreparingShutdown()
protected boolean isRedeliveryAllowed(RedeliveryErrorHandler.RedeliveryData data)
public void prepareShutdown(boolean forced)
ShutdownPrepared
ShutdownStrategy
supports preparing for shutdown using two steps.
First a regular preparation, where the given forced parameter will be false.
And if the shutdown times out, then the ShutdownStrategy
performs a more aggressive
shutdown, calling this method a second time with true for the given forced parameter.
For example by graceful stopping any threads or the likes.
For forced shutdown, then the service is expected to aggressively shutdown any child services, such
as thread pools etc. This is the last chance it has to perform such duties.
prepareShutdown
in interface ShutdownPrepared
forced
- true is forcing a more aggressive shutdown, false is for preparing to shutdown.public void process(Exchange exchange) throws Exception
Processor
process
in interface Processor
exchange
- the message exchange
Exception
- if an internal processing error has occurred.public boolean process(Exchange exchange, AsyncCallback callback)
process
in interface AsyncProcessor
exchange
- the message exchangecallback
- 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.
protected long determineRedeliveryDelay(Exchange exchange, RedeliveryPolicy redeliveryPolicy, long redeliveryDelay, int redeliveryCounter)
Determines the redelivery delay time by first inspecting the Message header Exchange.REDELIVERY_DELAY
and if not present, defaulting to RedeliveryPolicy.calculateRedeliveryDelay(long, int)
In order to prevent manipulation of the RedeliveryData state, the values of RedeliveryErrorHandler.RedeliveryData.redeliveryDelay
and RedeliveryErrorHandler.RedeliveryData.redeliveryCounter
are copied in.
exchange
- The current exchange in question.redeliveryPolicy
- The RedeliveryPolicy to use in the calculation.redeliveryDelay
- The default redelivery delay from RedeliveryDataredeliveryCounter
- The redeliveryCounter
protected void processAsyncErrorHandler(Exchange exchange, AsyncCallback callback, RedeliveryErrorHandler.RedeliveryData data)
protected Exchange defensiveCopyExchangeIfNeeded(Exchange exchange)
exchange
- the exchange
protected boolean shouldHandleException(Exchange exchange)
protected boolean isDone(Exchange exchange)
protected boolean isCancelledOrInterrupted(Exchange exchange)
public Processor getOutput()
getOutput
in class ErrorHandlerSupport
public Processor getDeadLetter()
public String getDeadLetterUri()
public boolean isUseOriginalMessagePolicy()
public RedeliveryPolicy getRedeliveryPolicy()
public CamelLogger getLogger()
protected Predicate getDefaultHandledPredicate()
protected void prepareExchangeForContinue(Exchange exchange, RedeliveryErrorHandler.RedeliveryData data)
protected void prepareExchangeForRedelivery(Exchange exchange, RedeliveryErrorHandler.RedeliveryData data)
protected void handleException(Exchange exchange, RedeliveryErrorHandler.RedeliveryData data)
protected void deliverToOnRedeliveryProcessor(Exchange exchange, RedeliveryErrorHandler.RedeliveryData data)
protected boolean deliverToFailureProcessor(Processor processor, boolean isDeadLetterChannel, Exchange exchange, RedeliveryErrorHandler.RedeliveryData data, AsyncCallback callback)
protected void prepareExchangeAfterFailure(Exchange exchange, RedeliveryErrorHandler.RedeliveryData data, boolean shouldHandle, boolean shouldContinue)
protected void doStart() throws Exception
ServiceSupport
ServiceSupport.doStop()
for more details.
doStart
in class ServiceSupport
Exception
ServiceSupport.doStop()
protected void doStop() throws Exception
ServiceSupport
ServiceSupport.doStop()
method when
the service is being stopped. This method will also be invoked
if the service is still in uninitialized state (eg has not
been started). The method is always called to allow the service
to do custom logic when the service is being stopped, such as when
CamelContext
is shutting down.
doStop
in class ServiceSupport
Exception
ServiceSupport.doStart()
protected void doShutdown() throws Exception
ServiceSupport
doShutdown
in class ServiceSupport
Exception
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |