org.apache.camel.impl
Class ScheduledBatchPollingConsumer
java.lang.Object
org.apache.camel.support.ServiceSupport
org.apache.camel.impl.DefaultConsumer
org.apache.camel.impl.ScheduledPollConsumer
org.apache.camel.impl.ScheduledBatchPollingConsumer
- All Implemented Interfaces:
- Runnable, BatchConsumer, Consumer, PollingConsumerPollingStrategy, Service, ShutdownableService, ShutdownAware, ShutdownPrepared, StatefulService, SuspendableService
- Direct Known Subclasses:
- GenericFileConsumer
public abstract class ScheduledBatchPollingConsumer
- extends ScheduledPollConsumer
- implements BatchConsumer, ShutdownAware
A useful base class for any consumer which is polling batch based
Methods inherited from class org.apache.camel.impl.ScheduledPollConsumer |
afterPoll, beforePoll, doShutdown, doStart, doStop, doSuspend, getDelay, getInitialDelay, getPollStrategy, getRunLoggingLevel, getScheduledExecutorService, getTimeUnit, isGreedy, isPollAllowed, isPolling, isSchedulerStarted, isSendEmptyMessageWhenIdle, isStartScheduler, isUseFixedDelay, onInit, poll, run, setDelay, setGreedy, setInitialDelay, setPollStrategy, setRunLoggingLevel, setScheduledExecutorService, setSendEmptyMessageWhenIdle, setStartScheduler, setTimeUnit, setUseFixedDelay, startScheduler |
Methods inherited from class org.apache.camel.support.ServiceSupport |
doResume, getStatus, getVersion, isRunAllowed, isStarted, isStarting, isStopped, isStopping, isStoppingOrStopped, isSuspended, isSuspending, resume, shutdown, start, stop, suspend |
shutdownRunningTask
protected volatile ShutdownRunningTask shutdownRunningTask
pendingExchanges
protected volatile int pendingExchanges
maxMessagesPerPoll
protected int maxMessagesPerPoll
ScheduledBatchPollingConsumer
public ScheduledBatchPollingConsumer(Endpoint endpoint,
Processor processor)
ScheduledBatchPollingConsumer
public ScheduledBatchPollingConsumer(Endpoint endpoint,
Processor processor,
ScheduledExecutorService executor)
deferShutdown
public boolean deferShutdown(ShutdownRunningTask shutdownRunningTask)
- Description copied from interface:
ShutdownAware
- To defer shutdown during first phase of shutdown. This allows any pending exchanges to be completed
and therefore ensure a graceful shutdown without loosing messages. At the very end when there are no
more inflight and pending messages the consumer could then safely be shutdown.
This is needed by
SedaConsumer
.
- Specified by:
deferShutdown
in interface ShutdownAware
- Parameters:
shutdownRunningTask
- the configured option for how to act when shutting down running tasks.
- Returns:
- true to defer shutdown to very last.
getPendingExchangesSize
public int getPendingExchangesSize()
- Description copied from interface:
ShutdownAware
- Gets the number of pending exchanges.
Some consumers has internal queues with
Exchange
which are pending.
For example the SedaConsumer
.
Return zero to indicate no pending exchanges and therefore ready to shutdown.
- Specified by:
getPendingExchangesSize
in interface ShutdownAware
- Returns:
- number of pending exchanges
prepareShutdown
public void prepareShutdown(boolean forced)
- Description copied from interface:
ShutdownPrepared
- Prepares for shutdown.
The
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.
- Specified by:
prepareShutdown
in interface ShutdownPrepared
- Parameters:
forced
- true is forcing a more aggressive shutdown, false is for preparing to shutdown.
setMaxMessagesPerPoll
public void setMaxMessagesPerPoll(int maxMessagesPerPoll)
- Description copied from interface:
BatchConsumer
- Sets a maximum number of messages as a limit to poll at each polling.
Can be used to limit e.g. to 100 to avoid reading thousands or more
messages within the first polling at startup.
Is default unlimited, but use 0 or negative number to disable it as unlimited.
- Specified by:
setMaxMessagesPerPoll
in interface BatchConsumer
- Parameters:
maxMessagesPerPoll
- maximum messages to poll.
getMaxMessagesPerPoll
public int getMaxMessagesPerPoll()
- Gets the maximum number of messages as a limit to poll at each polling.
Is default unlimited, but use 0 or negative number to disable it as unlimited.
- Returns:
- max messages to poll
isBatchAllowed
public boolean isBatchAllowed()
- Description copied from interface:
BatchConsumer
- Whether processing the batch is still allowed.
This is used during shutdown to indicate whether to complete the pending
exchanges or stop after the current exchange has been processed.
- Specified by:
isBatchAllowed
in interface BatchConsumer
- Returns:
- true to continue processing from the batch, or false to stop.
- See Also:
ShutdownRunningTask
processEmptyMessage
protected void processEmptyMessage()
throws Exception
- Description copied from class:
ScheduledPollConsumer
- No messages to poll so send an empty message instead.
- Overrides:
processEmptyMessage
in class ScheduledPollConsumer
- Throws:
Exception
- is thrown if error processing the empty message.
Apache Camel