Package org.apache.camel.processor
Class ConcurrentRequestsThrottler
java.lang.Object
org.apache.camel.support.service.BaseService
org.apache.camel.support.service.ServiceSupport
org.apache.camel.support.AsyncProcessorSupport
org.apache.camel.processor.AbstractThrottler
org.apache.camel.processor.ConcurrentRequestsThrottler
- All Implemented Interfaces:
AutoCloseable,org.apache.camel.AsyncProcessor,org.apache.camel.Processor,Throttler,org.apache.camel.Service,org.apache.camel.ShutdownableService,org.apache.camel.spi.HasId,org.apache.camel.spi.IdAware,org.apache.camel.spi.RouteIdAware,org.apache.camel.StatefulService,org.apache.camel.SuspendableService,org.apache.camel.Traceable
A Throttler will set a limit on the maximum number of message
exchanges which can be sent to a processor concurrently.
This pattern can be extremely useful if you have some external system which meters access; such as only allowing 10
concurrent requests; or if huge load can cause a particular system to malfunction or to reduce its throughput you
might want to introduce some throttling.
This throttle implementation is thread-safe and is therefore safe to be used by multiple concurrent threads in a
single route.
The throttling mechanism is a Semaphore with maxConcurrentRequests permits on it. Callers trying to acquire a permit
will block if necessary when maxConcurrentRequests permits have been acquired.
-
Nested Class Summary
Nested Classes -
Field Summary
Fields inherited from class org.apache.camel.processor.AbstractThrottler
asyncDelayed, asyncExecutor, callerRunsWhenRejected, camelContext, correlationExpression, id, maxRequestsExpression, PROPERTY_EXCHANGE_QUEUED_TIMESTAMP, rejectExecution, routeId, shutdownAsyncExecutorFields 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
ConstructorsConstructorDescriptionConcurrentRequestsThrottler(org.apache.camel.CamelContext camelContext, org.apache.camel.Expression maxRequestsExpression, ScheduledExecutorService asyncExecutor, boolean shutdownAsyncExecutor, boolean rejectExecution, org.apache.camel.Expression correlation) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidprotected voiddoStart()intGets the current maximum request.getMode()booleanprocess(org.apache.camel.Exchange exchange, org.apache.camel.AsyncCallback callback) protected booleanprocessAsynchronously(org.apache.camel.Exchange exchange, org.apache.camel.AsyncCallback callback, ConcurrentRequestsThrottler.ThrottlingState throttlingState) Delegate blocking to an asyncExecutor.toString()Methods inherited from class org.apache.camel.processor.AbstractThrottler
getId, getMaximumRequestsExpression, getRouteId, handleException, handleInterrupt, isAsyncDelayed, isCallerRunsWhenRejected, isRejectExecution, setAsyncDelayed, setCallerRunsWhenRejected, setId, setMaximumRequestsExpression, setRejectExecution, setRouteIdMethods inherited from class org.apache.camel.support.AsyncProcessorSupport
process, processAsyncMethods inherited from class org.apache.camel.support.service.BaseService
build, doBuild, doFail, doInit, doLifecycleChange, doResume, doStop, doSuspend, fail, getInternalLock, getStatus, init, isBuild, isInit, isNew, isRunAllowed, isShutdown, isStarted, isStarting, isStartingOrStarted, isStopped, isStopping, isStoppingOrStopped, isSuspended, isSuspending, isSuspendingOrSuspended, resume, shutdown, start, stop, suspendMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.camel.spi.IdAware
setGeneratedIdMethods inherited from interface org.apache.camel.Processor
processMethods 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, isRunAllowed, isStarted, isStarting, isStopped, isStopping, isSuspendingMethods inherited from interface org.apache.camel.SuspendableService
isSuspended, resume, suspend
-
Constructor Details
-
ConcurrentRequestsThrottler
public ConcurrentRequestsThrottler(org.apache.camel.CamelContext camelContext, org.apache.camel.Expression maxRequestsExpression, ScheduledExecutorService asyncExecutor, boolean shutdownAsyncExecutor, boolean rejectExecution, org.apache.camel.Expression correlation)
-
-
Method Details
-
process
public boolean process(org.apache.camel.Exchange exchange, org.apache.camel.AsyncCallback callback) -
processAsynchronously
protected boolean processAsynchronously(org.apache.camel.Exchange exchange, org.apache.camel.AsyncCallback callback, ConcurrentRequestsThrottler.ThrottlingState throttlingState) Delegate blocking to an asyncExecutor. Except if the executor rejects the submission and isCallerRunsWhenRejected() is enabled, then this method will delegate back to process(), but not before changing the exchange state to stop any recursion. -
doStart
- Overrides:
doStartin classorg.apache.camel.support.service.BaseService- Throws:
Exception
-
doShutdown
- Overrides:
doShutdownin classorg.apache.camel.support.service.BaseService- Throws:
Exception
-
getMode
- Specified by:
getModein interfaceThrottler- Specified by:
getModein classAbstractThrottler
-
getCurrentMaximumRequests
public int getCurrentMaximumRequests()Gets the current maximum request. If it is grouped throttling applied with correlationExpression then the max within the group will return -
getTraceLabel
-
toString
-