Package org.apache.camel.throttling
Class ThrottlingInflightRoutePolicy
java.lang.Object
org.apache.camel.support.service.BaseService
org.apache.camel.support.service.ServiceSupport
org.apache.camel.support.RoutePolicySupport
org.apache.camel.throttling.ThrottlingInflightRoutePolicy
- All Implemented Interfaces:
AutoCloseable,org.apache.camel.CamelContextAware,org.apache.camel.Service,org.apache.camel.ShutdownableService,org.apache.camel.spi.RoutePolicy,org.apache.camel.StatefulService,org.apache.camel.SuspendableService
public class ThrottlingInflightRoutePolicy
extends RoutePolicySupport
implements org.apache.camel.CamelContextAware
A throttle based
RoutePolicy which is capable of dynamic throttling a route based on
number of current inflight exchanges.
This implementation supports two scopes ThrottlingInflightRoutePolicy.ThrottlingScope.Context and ThrottlingInflightRoutePolicy.ThrottlingScope.Route (is
default). If context scope is selected then this implementation will use a EventNotifier
to listen for events when Exchanges is done, and trigger the
throttle(org.apache.camel.Route, org.apache.camel.Exchange) method. If the route scope is selected then
no EventNotifier is in use, as there is already a
Synchronization callback on the current Exchange which triggers the
throttle(org.apache.camel.Route, org.apache.camel.Exchange) when the current Exchange is done.-
Nested Class Summary
Nested Classes -
Field Summary
Fields inherited from class org.apache.camel.support.service.BaseService
BUILT, FAILED, INITIALIZED, INITIALIZING, NEW, SHUTDOWN, SHUTTING_DOWN, STARTED, STARTING, status, STOPPED, STOPPING, SUSPENDED, SUSPENDING -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected org.apache.camel.spi.CamelLoggerprotected voiddoStart()protected voiddoStop()org.apache.camel.CamelContextorg.apache.camel.spi.CamelLoggerorg.apache.camel.LoggingLevelintintgetScope()voidonExchangeDone(org.apache.camel.Route route, org.apache.camel.Exchange exchange) voidonInit(org.apache.camel.Route route) voidsetCamelContext(org.apache.camel.CamelContext camelContext) voidsetLogger(org.apache.camel.spi.CamelLogger logger) Sets the logger to use for logging throttling activity.voidsetLoggingLevel(org.apache.camel.LoggingLevel loggingLevel) Sets the logging level to report the throttling activity.voidsetMaxInflightExchanges(int maxInflightExchanges) Sets the upper limit of number of concurrent inflight exchanges at which point reached the throttler should suspend the route.voidsetResumePercentOfMax(int resumePercentOfMax) Sets at which percentage of the max the throttler should start resuming the route.voidSets which scope the throttling should be based upon, either route or total scoped.protected voidthrottle(org.apache.camel.Route route, org.apache.camel.Exchange exchange) Throttles the route whenExchanges is done.toString()Methods inherited from class org.apache.camel.support.RoutePolicySupport
controller, getExceptionHandler, handleException, onExchangeBegin, onRemove, onResume, onStart, onStop, onSuspend, resumeOrStartConsumer, resumeRoute, setExceptionHandler, startConsumer, startRoute, stopConsumer, stopRoute, stopRoute, stopRouteAsync, suspendOrStopConsumer, suspendRoute, suspendRouteMethods inherited from class org.apache.camel.support.service.BaseService
build, doBuild, doFail, doInit, doLifecycleChange, doResume, doShutdown, doSuspend, fail, 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.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
-
ThrottlingInflightRoutePolicy
public ThrottlingInflightRoutePolicy()
-
-
Method Details
-
toString
-
getCamelContext
public org.apache.camel.CamelContext getCamelContext()- Specified by:
getCamelContextin interfaceorg.apache.camel.CamelContextAware
-
setCamelContext
public void setCamelContext(org.apache.camel.CamelContext camelContext) - Specified by:
setCamelContextin interfaceorg.apache.camel.CamelContextAware
-
onInit
public void onInit(org.apache.camel.Route route) - Specified by:
onInitin interfaceorg.apache.camel.spi.RoutePolicy- Overrides:
onInitin classRoutePolicySupport
-
onExchangeDone
public void onExchangeDone(org.apache.camel.Route route, org.apache.camel.Exchange exchange) - Specified by:
onExchangeDonein interfaceorg.apache.camel.spi.RoutePolicy- Overrides:
onExchangeDonein classRoutePolicySupport
-
throttle
protected void throttle(org.apache.camel.Route route, org.apache.camel.Exchange exchange) Throttles the route whenExchanges is done.- Parameters:
route- the routeexchange- the exchange
-
getMaxInflightExchanges
public int getMaxInflightExchanges() -
setMaxInflightExchanges
public void setMaxInflightExchanges(int maxInflightExchanges) Sets the upper limit of number of concurrent inflight exchanges at which point reached the throttler should suspend the route. Is default 1000.- Parameters:
maxInflightExchanges- the upper limit of concurrent inflight exchanges
-
getResumePercentOfMax
public int getResumePercentOfMax() -
setResumePercentOfMax
public void setResumePercentOfMax(int resumePercentOfMax) Sets at which percentage of the max the throttler should start resuming the route. Will by default use 70%.- Parameters:
resumePercentOfMax- the percentage must be between 0 and 100
-
getScope
-
setScope
Sets which scope the throttling should be based upon, either route or total scoped.- Parameters:
scope- the scope
-
getLoggingLevel
public org.apache.camel.LoggingLevel getLoggingLevel() -
getLogger
public org.apache.camel.spi.CamelLogger getLogger() -
setLogger
public void setLogger(org.apache.camel.spi.CamelLogger logger) Sets the logger to use for logging throttling activity.- Parameters:
logger- the logger
-
setLoggingLevel
public void setLoggingLevel(org.apache.camel.LoggingLevel loggingLevel) Sets the logging level to report the throttling activity. Is default INFO level.- Parameters:
loggingLevel- the logging level
-
createLogger
protected org.apache.camel.spi.CamelLogger createLogger() -
doStart
- Overrides:
doStartin classRoutePolicySupport- Throws:
Exception
-
doStop
- Overrides:
doStopin classRoutePolicySupport- Throws:
Exception
-