public class ThrottlingInflightRoutePolicy extends RoutePolicySupport implements CamelContextAware, NonManagedService
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 |
log
shutdown, shuttingdown, started, starting, stopped, stopping, suspended, suspending
Constructor and Description |
---|
ThrottlingInflightRoutePolicy() |
Modifier and Type | Method and Description |
---|---|
protected CamelLogger |
createLogger() |
protected void |
doStart()
Implementations override this method to support customized start/stop.
|
protected void |
doStop()
Implementations override this method to support customized start/stop.
|
CamelContext |
getCamelContext()
Get the
CamelContext |
CamelLogger |
getLogger() |
LoggingLevel |
getLoggingLevel() |
int |
getMaxInflightExchanges() |
int |
getResumePercentOfMax() |
ThrottlingInflightRoutePolicy.ThrottlingScope |
getScope() |
void |
onExchangeDone(Route route,
Exchange exchange)
|
void |
onInit(Route route)
Callback invoked when the
Route is being initialized |
void |
setCamelContext(CamelContext camelContext)
Injects the
CamelContext |
void |
setLogger(CamelLogger logger)
Sets the logger to use for logging throttling activity.
|
void |
setLoggingLevel(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(Route route,
Exchange exchange)
Throttles the route when
Exchange s is done. |
String |
toString() |
getExceptionHandler, handleException, onExchangeBegin, onRemove, onResume, onStart, onStop, onSuspend, resumeRoute, setExceptionHandler, startConsumer, startRoute, stopConsumer, stopRoute, stopRoute, suspendRoute, suspendRoute
doResume, doShutdown, doSuspend, getStatus, getVersion, isRunAllowed, isStarted, isStarting, isStopped, isStopping, isStoppingOrStopped, isSuspended, isSuspending, isSuspendingOrSuspended, resume, shutdown, start, stop, suspend
public CamelContext getCamelContext()
CamelContextAware
CamelContext
getCamelContext
in interface CamelContextAware
public void setCamelContext(CamelContext camelContext)
CamelContextAware
CamelContext
setCamelContext
in interface CamelContextAware
camelContext
- the Camel contextpublic void onInit(Route route)
RoutePolicy
Route
is being initializedonInit
in interface RoutePolicy
onInit
in class RoutePolicySupport
route
- the route being initializedpublic void onExchangeDone(Route route, Exchange exchange)
RoutePolicy
Exchange
is done being routed, where it started from the given Route
Notice this callback is invoked when the Exchange is done and the Route
is the route where
the Exchange
was started. Most often its also the route where the exchange is done. However its
possible to route an Exchange
to other routes using endpoints such as
direct or seda. Bottom line is that the Route
parameter may not be the endpoint
route and thus why we state its the starting route.
onExchangeDone
in interface RoutePolicy
onExchangeDone
in class RoutePolicySupport
route
- the route where the exchange started fromexchange
- the created exchangeprotected void throttle(Route route, Exchange exchange)
Exchange
s is done.route
- the routeexchange
- the exchangepublic int getMaxInflightExchanges()
public void setMaxInflightExchanges(int maxInflightExchanges)
Is default 1000.
maxInflightExchanges
- the upper limit of concurrent inflight exchangespublic int getResumePercentOfMax()
public void setResumePercentOfMax(int resumePercentOfMax)
Will by default use 70%.
resumePercentOfMax
- the percentage must be between 0 and 100public ThrottlingInflightRoutePolicy.ThrottlingScope getScope()
public void setScope(ThrottlingInflightRoutePolicy.ThrottlingScope scope)
scope
- the scopepublic LoggingLevel getLoggingLevel()
public CamelLogger getLogger()
public void setLogger(CamelLogger logger)
logger
- the loggerpublic void setLoggingLevel(LoggingLevel loggingLevel)
Is default INFO level.
loggingLevel
- the logging levelprotected CamelLogger createLogger()
protected void doStart() throws Exception
ServiceSupport
Important: See ServiceSupport.doStop()
for more details.
doStart
in class RoutePolicySupport
Exception
ServiceSupport.doStop()
protected void doStop() throws Exception
ServiceSupport
Important: Camel will invoke this ServiceSupport.doStop()
method when
the service is being stopped. This method will also be invoked
if the service is still in uninitialized state (eg has not
been started). The method is always called to allow the service
to do custom logic when the service is being stopped, such as when
CamelContext
is shutting down.
doStop
in class RoutePolicySupport
Exception
ServiceSupport.doStart()
Copyright © 2007–2016 The Apache Software Foundation. All rights reserved.