public class ThrottlingInflightRoutePolicy
extends org.apache.camel.support.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 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.| 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
Exchanges is done. |
String |
toString() |
getExceptionHandler, handleException, onExchangeBegin, onRemove, onResume, onStart, onStop, onSuspend, resumeOrStartConsumer, resumeRoute, setExceptionHandler, startConsumer, startRoute, stopConsumer, stopRoute, stopRoute, stopRouteAsync, suspendOrStopConsumer, suspendRoute, suspendRoutedoInit, doResume, doShutdown, doSuspend, getStatus, init, isInit, isNew, isRunAllowed, isShutdown, isStarted, isStarting, isStartingOrStarted, isStopped, isStopping, isStoppingOrStopped, isSuspended, isSuspending, isSuspendingOrSuspended, resume, shutdown, start, stop, suspendpublic org.apache.camel.CamelContext getCamelContext()
getCamelContext in interface org.apache.camel.CamelContextAwarepublic void setCamelContext(org.apache.camel.CamelContext camelContext)
setCamelContext in interface org.apache.camel.CamelContextAwarepublic void onInit(org.apache.camel.Route route)
onInit in interface org.apache.camel.spi.RoutePolicyonInit in class org.apache.camel.support.RoutePolicySupportpublic void onExchangeDone(org.apache.camel.Route route,
org.apache.camel.Exchange exchange)
onExchangeDone in interface org.apache.camel.spi.RoutePolicyonExchangeDone in class org.apache.camel.support.RoutePolicySupportprotected void throttle(org.apache.camel.Route route,
org.apache.camel.Exchange exchange)
Exchanges 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 org.apache.camel.support.RoutePolicySupportExceptionApache Camel