Package org.apache.camel.processor
Class DelayProcessorSupport
- java.lang.Object
-
- org.apache.camel.support.service.BaseService
-
- org.apache.camel.support.service.ServiceSupport
-
- org.apache.camel.support.AsyncProcessorSupport
-
- org.apache.camel.support.processor.DelegateAsyncProcessor
-
- org.apache.camel.processor.DelayProcessorSupport
-
- All Implemented Interfaces:
AutoCloseable
,org.apache.camel.AsyncProcessor
,org.apache.camel.DelegateProcessor
,org.apache.camel.Navigate<org.apache.camel.Processor>
,org.apache.camel.Processor
,org.apache.camel.Service
,org.apache.camel.ShutdownableService
,org.apache.camel.spi.ShutdownAware
,org.apache.camel.spi.ShutdownPrepared
,org.apache.camel.StatefulService
,org.apache.camel.SuspendableService
- Direct Known Subclasses:
Delayer
public abstract class DelayProcessorSupport extends org.apache.camel.support.processor.DelegateAsyncProcessor implements org.apache.camel.spi.ShutdownAware
A useful base class for any processor which provides some kind of throttling or delayed processing. This implementation will block while waiting.
-
-
Constructor Summary
Constructors Constructor Description DelayProcessorSupport(org.apache.camel.CamelContext camelContext, org.apache.camel.Processor processor)
DelayProcessorSupport(org.apache.camel.CamelContext camelContext, org.apache.camel.Processor processor, ScheduledExecutorService executorService, boolean shutdownExecutorService)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract long
calculateDelay(org.apache.camel.Exchange exchange)
protected long
currentSystemTime()
boolean
deferShutdown(org.apache.camel.ShutdownRunningTask shutdownRunningTask)
protected void
delay(long delay, org.apache.camel.Exchange exchange)
Delays the given time before continuing.protected void
doShutdown()
protected void
doStart()
int
getDelayedCount()
Gets the current number ofExchange
s being delayed (hold back due throttle limit hit)int
getPendingExchangesSize()
protected void
handleSleepInterruptedException(InterruptedException e, org.apache.camel.Exchange exchange)
Called when a sleep is interrupted; allows derived classes to handle this case differentlyboolean
isAsyncDelayed()
boolean
isCallerRunsWhenRejected()
void
prepareShutdown(boolean suspendOnly, boolean forced)
boolean
process(org.apache.camel.Exchange exchange, org.apache.camel.AsyncCallback callback)
protected boolean
processDelay(org.apache.camel.Exchange exchange, org.apache.camel.AsyncCallback callback, long delay)
void
setAsyncDelayed(boolean asyncDelayed)
void
setCallerRunsWhenRejected(boolean callerRunsWhenRejected)
-
Methods inherited from class org.apache.camel.support.processor.DelegateAsyncProcessor
doStop, getProcessor, hasNext, next, setProcessor, setProcessor, toString
-
Methods inherited from class org.apache.camel.support.service.BaseService
build, doBuild, doFail, doInit, doLifecycleChange, doResume, doSuspend, fail, getStatus, init, isBuild, isInit, isNew, isRunAllowed, isShutdown, isStarted, isStarting, isStartingOrStarted, isStopped, isStopping, isStoppingOrStopped, isSuspended, isSuspending, isSuspendingOrSuspended, resume, shutdown, start, stop, suspend
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
-
-
-
Constructor Detail
-
DelayProcessorSupport
public DelayProcessorSupport(org.apache.camel.CamelContext camelContext, org.apache.camel.Processor processor)
-
DelayProcessorSupport
public DelayProcessorSupport(org.apache.camel.CamelContext camelContext, org.apache.camel.Processor processor, ScheduledExecutorService executorService, boolean shutdownExecutorService)
-
-
Method Detail
-
processDelay
protected boolean processDelay(org.apache.camel.Exchange exchange, org.apache.camel.AsyncCallback callback, long delay)
-
process
public boolean process(org.apache.camel.Exchange exchange, org.apache.camel.AsyncCallback callback)
- Specified by:
process
in interfaceorg.apache.camel.AsyncProcessor
- Overrides:
process
in classorg.apache.camel.support.processor.DelegateAsyncProcessor
-
isAsyncDelayed
public boolean isAsyncDelayed()
-
setAsyncDelayed
public void setAsyncDelayed(boolean asyncDelayed)
-
isCallerRunsWhenRejected
public boolean isCallerRunsWhenRejected()
-
setCallerRunsWhenRejected
public void setCallerRunsWhenRejected(boolean callerRunsWhenRejected)
-
calculateDelay
protected abstract long calculateDelay(org.apache.camel.Exchange exchange)
-
getDelayedCount
public int getDelayedCount()
Gets the current number ofExchange
s being delayed (hold back due throttle limit hit)
-
delay
protected void delay(long delay, org.apache.camel.Exchange exchange) throws InterruptedException
Delays the given time before continuing. This implementation will block while waiting- Parameters:
delay
- the delay time in millisexchange
- the exchange being processed- Throws:
InterruptedException
-
handleSleepInterruptedException
protected void handleSleepInterruptedException(InterruptedException e, org.apache.camel.Exchange exchange) throws InterruptedException
Called when a sleep is interrupted; allows derived classes to handle this case differently- Throws:
InterruptedException
-
currentSystemTime
protected long currentSystemTime()
-
doStart
protected void doStart() throws Exception
- Overrides:
doStart
in classorg.apache.camel.support.processor.DelegateAsyncProcessor
- Throws:
Exception
-
doShutdown
protected void doShutdown() throws Exception
- Overrides:
doShutdown
in classorg.apache.camel.support.processor.DelegateAsyncProcessor
- Throws:
Exception
-
deferShutdown
public boolean deferShutdown(org.apache.camel.ShutdownRunningTask shutdownRunningTask)
- Specified by:
deferShutdown
in interfaceorg.apache.camel.spi.ShutdownAware
-
getPendingExchangesSize
public int getPendingExchangesSize()
- Specified by:
getPendingExchangesSize
in interfaceorg.apache.camel.spi.ShutdownAware
-
prepareShutdown
public void prepareShutdown(boolean suspendOnly, boolean forced)
- Specified by:
prepareShutdown
in interfaceorg.apache.camel.spi.ShutdownPrepared
-
-