Class SedaConsumer
java.lang.Object
org.apache.camel.support.service.BaseService
org.apache.camel.support.service.ServiceSupport
org.apache.camel.support.DefaultConsumer
org.apache.camel.component.seda.SedaConsumer
- All Implemented Interfaces:
AutoCloseable, Runnable, org.apache.camel.Consumer, org.apache.camel.EndpointAware, org.apache.camel.health.HealthCheckAware, org.apache.camel.RouteAware, org.apache.camel.Service, org.apache.camel.ShutdownableService, org.apache.camel.spi.HostedService, org.apache.camel.spi.RouteIdAware, org.apache.camel.spi.ShutdownAware, org.apache.camel.spi.ShutdownPrepared, org.apache.camel.StatefulService, org.apache.camel.Suspendable, org.apache.camel.SuspendableService
- Direct Known Subclasses:
ThreadPerTaskSedaConsumer
public class SedaConsumer
extends org.apache.camel.support.DefaultConsumer
implements Runnable, org.apache.camel.spi.ShutdownAware, org.apache.camel.Suspendable
A Consumer for the SEDA component.
In this implementation there is a little slack period when you suspend/stop the consumer, by which the
consumer may pickup a newly arrived messages and process it. That period is up till 1 second.
-
Field Summary
FieldsFields inherited from class org.apache.camel.support.service.BaseService
BUILT, FAILED, INITIALIZED, INITIALIZING, lock, NEW, SHUTDOWN, SHUTTING_DOWN, STARTED, STARTING, status, STOPPED, STOPPING, SUSPENDED, SUSPENDING -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidHook called when poll returned no exchange.protected booleanHook called before polling the queue.protected ExecutorServicecreateExecutor(int poolSize) Creates the executor service used for consumer threads.booleandeferShutdown(org.apache.camel.ShutdownRunningTask shutdownRunningTask) protected voiddoResume()protected voiddoRun()protected voidprotected voiddoStart()protected voiddoStop()protected voidintprotected intbooleanprotected booleanprotected voidonProcessingDone(org.apache.camel.Exchange original, org.apache.camel.Exchange prepared) Strategy to invoke when the exchange is done being processed.protected org.apache.camel.ExchangeprepareExchange(org.apache.camel.Exchange exchange) Strategy to prepare exchange for being processed by this consumervoidprepareShutdown(boolean suspendOnly, boolean forced) protected voidprocessPolledExchange(org.apache.camel.Exchange exchange) Process a polled exchange.voidrun()protected voidsendToConsumers(org.apache.camel.Exchange exchange, org.apache.camel.AsyncCallback callback) Send the givenExchangeto the consumer(s).protected voidsetShutdownPending(boolean shutdownPending) protected voidSetup the thread pool and ensures tasks gets executed (if needed)protected voidShuts down the executor service.Methods inherited from class org.apache.camel.support.DefaultConsumer
createExchange, createUoW, defaultConsumerCallback, doBuild, doInit, doneUoW, getAsyncProcessor, getExceptionHandler, getHealthCheck, getProcessor, getRoute, getRouteId, handleException, handleException, handleException, isHostedService, releaseExchange, setExceptionHandler, setHealthCheck, setRoute, setRouteId, toStringMethods inherited from class org.apache.camel.support.service.BaseService
build, doFail, doLifecycleChange, fail, getInternalLock, getStatus, init, isBuild, isInit, isNew, isShutdown, isStarted, isStarting, isStartingOrStarted, isStopped, isStopping, isStoppingOrStopped, isSuspended, isSuspending, isSuspendingOrSuspended, resume, shutdown, start, stop, suspendMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.camel.Service
build, close, init, start, stopMethods inherited from interface org.apache.camel.ShutdownableService
shutdownMethods inherited from interface org.apache.camel.StatefulService
getStatus, isStarted, isStarting, isStopped, isStopping, isSuspendingMethods inherited from interface org.apache.camel.SuspendableService
isSuspended, resume, suspend
-
Field Details
-
pollTimeout
protected final int pollTimeout
-
-
Constructor Details
-
SedaConsumer
-
-
Method Details
-
getPollTimeout
protected int getPollTimeout() -
isShutdownPending
protected boolean isShutdownPending() -
setShutdownPending
protected void setShutdownPending(boolean shutdownPending) -
getEndpoint
- Specified by:
getEndpointin interfaceorg.apache.camel.EndpointAware- Overrides:
getEndpointin classorg.apache.camel.support.DefaultConsumer
-
deferShutdown
public boolean deferShutdown(org.apache.camel.ShutdownRunningTask shutdownRunningTask) - Specified by:
deferShutdownin interfaceorg.apache.camel.spi.ShutdownAware
-
getPendingExchangesSize
public int getPendingExchangesSize()- Specified by:
getPendingExchangesSizein interfaceorg.apache.camel.spi.ShutdownAware
-
prepareShutdown
public void prepareShutdown(boolean suspendOnly, boolean forced) - Specified by:
prepareShutdownin interfaceorg.apache.camel.spi.ShutdownPrepared
-
isRunAllowed
public boolean isRunAllowed()- Specified by:
isRunAllowedin interfaceorg.apache.camel.StatefulService- Overrides:
isRunAllowedin classorg.apache.camel.support.service.BaseService
-
run
-
doRun
protected void doRun() -
beforePoll
Hook called before polling the queue. Subclasses can override to acquire resources (e.g., permits).- Returns:
- true to proceed with polling, false to skip this poll iteration
- Throws:
InterruptedException- if interrupted while acquiring resources
-
afterPollEmpty
protected void afterPollEmpty()Hook called when poll returned no exchange. Subclasses can override to release resources (e.g., permits). -
processPolledExchange
protected void processPolledExchange(org.apache.camel.Exchange exchange) Process a polled exchange. Subclasses can override to dispatch to another thread.- Parameters:
exchange- the exchange to process
-
onProcessingDone
protected void onProcessingDone(org.apache.camel.Exchange original, org.apache.camel.Exchange prepared) Strategy to invoke when the exchange is done being processed. This method is meant to be overridden by subclasses to be able to mimic the behavior of the legacy component camel-vm, that is why the parameterpreparedis not used by default.- Parameters:
original- the exchange before being processedprepared- the exchange processed
-
prepareExchange
protected org.apache.camel.Exchange prepareExchange(org.apache.camel.Exchange exchange) Strategy to prepare exchange for being processed by this consumer This method is meant to be overridden by subclasses to be able to mimic the behavior of the legacy component camel-vm, that is why the prepared exchange is returned.- Parameters:
exchange- the exchange- Returns:
- the exchange to process by this consumer
-
sendToConsumers
protected void sendToConsumers(org.apache.camel.Exchange exchange, org.apache.camel.AsyncCallback callback) throws Exception Send the givenExchangeto the consumer(s). If multiple consumers then they will each receive a copy of the Exchange. A multicast processor will send the exchange in parallel to the multiple consumers. If there is only a single consumer then its dispatched directly to it using same thread.- Parameters:
exchange- the exchangecallback- exchange callback to continue routing- Throws:
Exception- can be thrown if processing of the exchange failed
-
doStart
-
doSuspend
-
doResume
-
doStop
-
doShutdown
-
shutdownExecutor
protected void shutdownExecutor()Shuts down the executor service. -
createExecutor
Creates the executor service used for consumer threads. Subclasses can override this method to provide a different executor, such as one using virtual threads.- Parameters:
poolSize- the number of concurrent consumers- Returns:
- the executor service
-
setupTasks
protected void setupTasks()Setup the thread pool and ensures tasks gets executed (if needed)
-