|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object akka.pattern.CircuitBreaker
public class CircuitBreaker
Provides circuit breaker functionality to provide stability when working with "dangerous" operations, e.g. calls to remote systems
Transitions through three states:
- In *Closed* state, calls pass through until the maxFailures
count is reached. This causes the circuit breaker
to open. Both exceptions and calls exceeding callTimeout
are considered failures.
- In *Open* state, calls fail-fast with an exception. After resetTimeout
, circuit breaker transitions to
half-open state.
- In *Half-Open* state, the first call will be allowed through, if it succeeds the circuit breaker will reset to
closed state. If it fails, the circuit breaker will re-open to open state. All calls beyond the first that
execute while the first is running will fail-fast with an exception.
param: scheduler Reference to Akka scheduler
param: maxFailures Maximum number of failures before opening the circuit
param: callTimeout FiniteDuration
of time after which to consider a call a failure
param: resetTimeout FiniteDuration
of time after which to attempt to close the circuit
param: executor ExecutionContext
used for execution of state transition listeners
Field Summary | |
---|---|
protected static long |
stateOffset
|
Constructor Summary | |
---|---|
CircuitBreaker(scala.concurrent.ExecutionContext executor,
Scheduler scheduler,
int maxFailures,
scala.concurrent.duration.FiniteDuration callTimeout,
scala.concurrent.duration.FiniteDuration resetTimeout)
|
|
CircuitBreaker(Scheduler scheduler,
int maxFailures,
scala.concurrent.duration.FiniteDuration callTimeout,
scala.concurrent.duration.FiniteDuration resetTimeout,
scala.concurrent.ExecutionContext executor)
|
Method Summary | ||
---|---|---|
static CircuitBreaker |
apply(Scheduler scheduler,
int maxFailures,
scala.concurrent.duration.FiniteDuration callTimeout,
scala.concurrent.duration.FiniteDuration resetTimeout)
Create a new CircuitBreaker. |
|
|
callWithCircuitBreaker(java.util.concurrent.Callable<scala.concurrent.Future<T>> body)
Java API for withCircuitBreaker(scala.Function0 |
|
|
callWithSyncCircuitBreaker(java.util.concurrent.Callable<T> body)
Java API for withSyncCircuitBreaker(scala.Function0 |
|
static CircuitBreaker |
create(Scheduler scheduler,
int maxFailures,
scala.concurrent.duration.FiniteDuration callTimeout,
scala.concurrent.duration.FiniteDuration resetTimeout)
Java API: Create a new CircuitBreaker. |
|
int |
currentFailureCount()
Retrieves current failure count. |
|
CircuitBreaker |
onClose(scala.Function0<scala.runtime.BoxedUnit> callback)
Adds a callback to execute when circuit breaker state closes |
|
CircuitBreaker |
onClose(java.lang.Runnable callback)
JavaAPI for onClose |
|
CircuitBreaker |
onHalfOpen(scala.Function0<scala.runtime.BoxedUnit> callback)
Adds a callback to execute when circuit breaker transitions to half-open |
|
CircuitBreaker |
onHalfOpen(java.lang.Runnable callback)
JavaAPI for onHalfOpen |
|
CircuitBreaker |
onOpen(scala.Function0<scala.runtime.BoxedUnit> callback)
Adds a callback to execute when circuit breaker opens |
|
CircuitBreaker |
onOpen(java.lang.Runnable callback)
Java API for onOpen |
|
|
withCircuitBreaker(scala.Function0<scala.concurrent.Future<T>> body)
Wraps invocations of asynchronous calls that need to be protected |
|
|
withSyncCircuitBreaker(scala.Function0<T> body)
Wraps invocations of synchronous calls that need to be protected |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected static final long stateOffset
Constructor Detail |
---|
public CircuitBreaker(Scheduler scheduler, int maxFailures, scala.concurrent.duration.FiniteDuration callTimeout, scala.concurrent.duration.FiniteDuration resetTimeout, scala.concurrent.ExecutionContext executor)
public CircuitBreaker(scala.concurrent.ExecutionContext executor, Scheduler scheduler, int maxFailures, scala.concurrent.duration.FiniteDuration callTimeout, scala.concurrent.duration.FiniteDuration resetTimeout)
Method Detail |
---|
public static CircuitBreaker apply(Scheduler scheduler, int maxFailures, scala.concurrent.duration.FiniteDuration callTimeout, scala.concurrent.duration.FiniteDuration resetTimeout)
Callbacks run in caller's thread when using withSyncCircuitBreaker, and in same ExecutionContext as the passed in Future when using withCircuitBreaker. To use another ExecutionContext for the callbacks you can specify the executor in the constructor.
scheduler
- Reference to Akka schedulermaxFailures
- Maximum number of failures before opening the circuitcallTimeout
- FiniteDuration
of time after which to consider a call a failureresetTimeout
- FiniteDuration
of time after which to attempt to close the circuit
public static CircuitBreaker create(Scheduler scheduler, int maxFailures, scala.concurrent.duration.FiniteDuration callTimeout, scala.concurrent.duration.FiniteDuration resetTimeout)
Callbacks run in caller's thread when using withSyncCircuitBreaker, and in same ExecutionContext as the passed in Future when using withCircuitBreaker. To use another ExecutionContext for the callbacks you can specify the executor in the constructor.
scheduler
- Reference to Akka schedulermaxFailures
- Maximum number of failures before opening the circuitcallTimeout
- FiniteDuration
of time after which to consider a call a failureresetTimeout
- FiniteDuration
of time after which to attempt to close the circuit
public <T> scala.concurrent.Future<T> withCircuitBreaker(scala.Function0<scala.concurrent.Future<T>> body)
body
- Call needing protected
Future
containing the call resultpublic <T> scala.concurrent.Future<T> callWithCircuitBreaker(java.util.concurrent.Callable<scala.concurrent.Future<T>> body)
withCircuitBreaker(scala.Function0>)
body
- Call needing protected
Future
containing the call resultpublic <T> T withSyncCircuitBreaker(scala.Function0<T> body)
Calls are run in caller's thread
body
- Call needing protected
public <T> T callWithSyncCircuitBreaker(java.util.concurrent.Callable<T> body)
withSyncCircuitBreaker(scala.Function0)
body
- Call needing protected
public CircuitBreaker onOpen(scala.Function0<scala.runtime.BoxedUnit> callback)
The callback is run in the ExecutionContext
supplied in the constructor.
callback
- Handler to be invoked on state change
public CircuitBreaker onOpen(java.lang.Runnable callback)
callback
- Handler to be invoked on state change
public CircuitBreaker onHalfOpen(scala.Function0<scala.runtime.BoxedUnit> callback)
The callback is run in the ExecutionContext
supplied in the constructor.
callback
- Handler to be invoked on state change
public CircuitBreaker onHalfOpen(java.lang.Runnable callback)
callback
- Handler to be invoked on state change
public CircuitBreaker onClose(scala.Function0<scala.runtime.BoxedUnit> callback)
The callback is run in the ExecutionContext
supplied in the constructor.
callback
- Handler to be invoked on state change
public CircuitBreaker onClose(java.lang.Runnable callback)
callback
- Handler to be invoked on state change
public int currentFailureCount()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |