public class ThrottlingInflightRoutePolicy extends RoutePolicySupport implements org.apache.camel.CamelContextAware
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 Exchange
s 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.Modifier and Type | Class and Description |
---|---|
static class |
ThrottlingInflightRoutePolicy.ThrottlingScope |
Constructor and Description |
---|
ThrottlingInflightRoutePolicy() |
Modifier and Type | Method and Description |
---|---|
protected org.apache.camel.spi.CamelLogger |
createLogger() |
protected void |
doStart() |
protected void |
doStop() |
org.apache.camel.CamelContext |
getCamelContext() |
org.apache.camel.spi.CamelLogger |
getLogger() |
org.apache.camel.LoggingLevel |
getLoggingLevel() |
int |
getMaxInflightExchanges() |
int |
getResumePercentOfMax() |
ThrottlingInflightRoutePolicy.ThrottlingScope |
getScope() |
void |
onExchangeDone(org.apache.camel.Route route,
org.apache.camel.Exchange exchange) |
void |
onInit(org.apache.camel.Route route) |
void |
setCamelContext(org.apache.camel.CamelContext camelContext) |
void |
setLogger(org.apache.camel.spi.CamelLogger logger)
Sets the logger to use for logging throttling activity.
|
void |
setLoggingLevel(org.apache.camel.LoggingLevel loggingLevel)
Sets the logging level to report the throttling activity.
|
void |
setMaxInflightExchanges(int maxInflightExchanges)
Sets the upper limit of number of concurrent inflight exchanges at which point reached the throttler should
suspend the route.
|
void |
setResumePercentOfMax(int resumePercentOfMax)
Sets at which percentage of the max the throttler should start resuming the route.
|
void |
setScope(ThrottlingInflightRoutePolicy.ThrottlingScope scope)
Sets which scope the throttling should be based upon, either route or total scoped.
|
protected void |
throttle(org.apache.camel.Route route,
org.apache.camel.Exchange exchange)
Throttles the route when
Exchange s is done. |
String |
toString() |
controller, getExceptionHandler, handleException, onExchangeBegin, onRemove, onResume, onStart, onStop, onSuspend, resumeOrStartConsumer, resumeRoute, setExceptionHandler, startConsumer, startRoute, stopConsumer, stopRoute, stopRoute, stopRouteAsync, suspendOrStopConsumer, suspendRoute, suspendRoute
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, suspend
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
public org.apache.camel.CamelContext getCamelContext()
getCamelContext
in interface org.apache.camel.CamelContextAware
public void setCamelContext(org.apache.camel.CamelContext camelContext)
setCamelContext
in interface org.apache.camel.CamelContextAware
public void onInit(org.apache.camel.Route route)
onInit
in interface org.apache.camel.spi.RoutePolicy
onInit
in class RoutePolicySupport
public void onExchangeDone(org.apache.camel.Route route, org.apache.camel.Exchange exchange)
onExchangeDone
in interface org.apache.camel.spi.RoutePolicy
onExchangeDone
in class RoutePolicySupport
protected void throttle(org.apache.camel.Route route, org.apache.camel.Exchange exchange)
Exchange
s is done.route
- the routeexchange
- the exchangepublic int getMaxInflightExchanges()
public void setMaxInflightExchanges(int maxInflightExchanges)
maxInflightExchanges
- the upper limit of concurrent inflight exchangespublic int getResumePercentOfMax()
public void setResumePercentOfMax(int resumePercentOfMax)
resumePercentOfMax
- the percentage must be between 0 and 100public ThrottlingInflightRoutePolicy.ThrottlingScope getScope()
public void setScope(ThrottlingInflightRoutePolicy.ThrottlingScope scope)
scope
- the scopepublic org.apache.camel.LoggingLevel getLoggingLevel()
public org.apache.camel.spi.CamelLogger getLogger()
public void setLogger(org.apache.camel.spi.CamelLogger logger)
logger
- the loggerpublic void setLoggingLevel(org.apache.camel.LoggingLevel loggingLevel)
loggingLevel
- the logging levelprotected org.apache.camel.spi.CamelLogger createLogger()
protected void doStart() throws Exception
doStart
in class RoutePolicySupport
Exception
protected void doStop() throws Exception
doStop
in class RoutePolicySupport
Exception
Apache Camel