Package org.apache.camel.throttling
Class ThrottlingExceptionRoutePolicy
- java.lang.Object
-
- org.apache.camel.support.service.BaseService
-
- org.apache.camel.support.service.ServiceSupport
-
- org.apache.camel.support.RoutePolicySupport
-
- org.apache.camel.throttling.ThrottlingExceptionRoutePolicy
-
- 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 ThrottlingExceptionRoutePolicy extends RoutePolicySupport implements org.apache.camel.CamelContextAware
Modeled after the circuit breakerThrottlingInflightRoutePolicythisRoutePolicywill stop consuming from an endpoint based on the type of exceptions that are thrown and the threshold setting. the scenario: if a route cannot process data from an endpoint due to problems with resources used by the route (ie database down) then it will stop consuming new messages from the endpoint by stopping the consumer. The implementation is comparable to the Circuit Breaker pattern. After a set amount of time, it will move to a half open state and attempt to determine if the consumer can be started. There are two ways to determine if a route can be closed after being opened (1) start the consumer and check the failure threshold (2) call theThrottlingExceptionHalfOpenHandlerThe second option allows a custom check to be performed without having to take on the possibility of multiple messages from the endpoint. The idea is that a handler could run a simple test (ie select 1 from dual) to determine if the processes that cause the route to be open are now available
-
-
Constructor Summary
Constructors Constructor Description ThrottlingExceptionRoutePolicy(int threshold, long failureWindow, long halfOpenAfter, List<Class<?>> handledExceptions)ThrottlingExceptionRoutePolicy(int threshold, long failureWindow, long halfOpenAfter, List<Class<?>> handledExceptions, boolean keepOpen)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidaddHalfOpenTimer(org.apache.camel.Route route)protected voidcloseCircuit(org.apache.camel.Route route)StringdumpState()org.apache.camel.CamelContextgetCamelContext()intgetFailures()intgetFailureThreshold()longgetFailureWindow()longgetHalfOpenAfter()ThrottlingExceptionHalfOpenHandlergetHalfOpenHandler()booleangetKeepOpen()longgetLastFailure()longgetOpenedAt()protected voidhalfOpenCircuit(org.apache.camel.Route route)protected booleanisThresholdExceeded()voidonExchangeDone(org.apache.camel.Route route, org.apache.camel.Exchange exchange)voidonInit(org.apache.camel.Route route)voidonStart(org.apache.camel.Route route)protected voidopenCircuit(org.apache.camel.Route route)voidsetCamelContext(org.apache.camel.CamelContext camelContext)voidsetFailureThreshold(int failureThreshold)voidsetFailureWindow(long failureWindow)voidsetHalfOpenAfter(long halfOpenAfter)voidsetHalfOpenHandler(ThrottlingExceptionHalfOpenHandler halfOpenHandler)voidsetKeepOpen(boolean keepOpen)-
Methods inherited from class org.apache.camel.support.RoutePolicySupport
controller, doStart, doStop, getExceptionHandler, handleException, onExchangeBegin, onRemove, onResume, onStop, onSuspend, resumeOrStartConsumer, resumeRoute, setExceptionHandler, startConsumer, startRoute, stopConsumer, stopRoute, stopRoute, stopRouteAsync, suspendOrStopConsumer, suspendRoute, suspendRoute
-
Methods 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, suspend
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
-
-
Method Detail
-
setCamelContext
public void setCamelContext(org.apache.camel.CamelContext camelContext)
- Specified by:
setCamelContextin interfaceorg.apache.camel.CamelContextAware
-
getCamelContext
public org.apache.camel.CamelContext getCamelContext()
- Specified by:
getCamelContextin interfaceorg.apache.camel.CamelContextAware
-
onInit
public void onInit(org.apache.camel.Route route)
- Specified by:
onInitin interfaceorg.apache.camel.spi.RoutePolicy- Overrides:
onInitin classRoutePolicySupport
-
onStart
public void onStart(org.apache.camel.Route route)
- Specified by:
onStartin interfaceorg.apache.camel.spi.RoutePolicy- Overrides:
onStartin 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
-
isThresholdExceeded
protected boolean isThresholdExceeded()
-
openCircuit
protected void openCircuit(org.apache.camel.Route route)
-
addHalfOpenTimer
protected void addHalfOpenTimer(org.apache.camel.Route route)
-
halfOpenCircuit
protected void halfOpenCircuit(org.apache.camel.Route route)
-
closeCircuit
protected void closeCircuit(org.apache.camel.Route route)
-
dumpState
public String dumpState()
-
getHalfOpenHandler
public ThrottlingExceptionHalfOpenHandler getHalfOpenHandler()
-
setHalfOpenHandler
public void setHalfOpenHandler(ThrottlingExceptionHalfOpenHandler halfOpenHandler)
-
getKeepOpen
public boolean getKeepOpen()
-
setKeepOpen
public void setKeepOpen(boolean keepOpen)
-
getFailureThreshold
public int getFailureThreshold()
-
setFailureThreshold
public void setFailureThreshold(int failureThreshold)
-
getFailureWindow
public long getFailureWindow()
-
setFailureWindow
public void setFailureWindow(long failureWindow)
-
getHalfOpenAfter
public long getHalfOpenAfter()
-
setHalfOpenAfter
public void setHalfOpenAfter(long halfOpenAfter)
-
getFailures
public int getFailures()
-
getLastFailure
public long getLastFailure()
-
getOpenedAt
public long getOpenedAt()
-
-