public class CircuitBreakerImpl extends Object implements CircuitBreaker
| Modifier and Type | Class and Description |
|---|---|
static class |
CircuitBreakerImpl.RollingCounter |
| Constructor and Description |
|---|
CircuitBreakerImpl(String name,
Vertx vertx,
CircuitBreakerOptions options) |
| Modifier and Type | Method and Description |
|---|---|
CircuitBreaker |
close()
Closes the circuit breaker.
|
CircuitBreaker |
closeHandler(Handler<Void> handler)
Sets a
Handler invoked when the circuit breaker state switches to close. |
<T> Future<T> |
execute(Handler<Promise<T>> operation)
Same as
CircuitBreaker.executeWithFallback(Handler, Function) but using the circuit breaker default fallback. |
<T> CircuitBreaker |
executeAndReport(Promise<T> resultFuture,
Handler<Promise<T>> operation)
Same as
CircuitBreaker.executeAndReportWithFallback(Promise, Handler, Function) but using the circuit breaker default
fallback. |
<T> CircuitBreaker |
executeAndReportWithFallback(Promise<T> userFuture,
Handler<Promise<T>> command,
Function<Throwable,T> fallback)
Executes the given operation with the circuit breaker control.
|
<T> Future<T> |
executeWithFallback(Handler<Promise<T>> operation,
Function<Throwable,T> fallback)
Executes the given operation with the circuit breaker control.
|
long |
failureCount() |
<T> CircuitBreaker |
fallback(Function<Throwable,T> handler)
Sets a default
Function invoked when the bridge is open to handle the "request", or on failure
if CircuitBreakerOptions.isFallbackOnFailure() is enabled. |
CircuitBreakerMetrics |
getMetrics()
For testing purpose only.
|
CircuitBreaker |
halfOpenHandler(Handler<Void> handler)
Sets a
Handler invoked when the circuit breaker state switches to half-open. |
String |
name() |
CircuitBreaker |
open()
Explicitly opens the circuit.
|
CircuitBreaker |
openHandler(Handler<Void> handler)
Sets a
Handler invoked when the circuit breaker state switches to open. |
CircuitBreakerOptions |
options() |
CircuitBreaker |
reset()
Resets the circuit breaker state (number of failure set to 0 and state set to closed).
|
CircuitBreaker |
reset(boolean force)
A version of reset that can force the the state to `close` even if the circuit breaker is open.
|
CircuitBreaker |
retryPolicy(Function<Integer,Long> retryPolicy) |
CircuitBreakerState |
state() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitcreate, create, execute, executeAndReport, executeAndReportWithFallback, executeCommand, executeCommandWithFallback, executeWithFallbackpublic CircuitBreakerImpl(String name, Vertx vertx, CircuitBreakerOptions options)
public CircuitBreaker close()
CircuitBreakerclose state of the circuit breaker. To set the circuit breaker in the
close state, use CircuitBreaker.reset().close in interface CircuitBreakerpublic CircuitBreaker openHandler(Handler<Void> handler)
CircuitBreakerHandler invoked when the circuit breaker state switches to open.openHandler in interface CircuitBreakerhandler - the handler, must not be nullCircuitBreakerpublic CircuitBreaker halfOpenHandler(Handler<Void> handler)
CircuitBreakerHandler invoked when the circuit breaker state switches to half-open.halfOpenHandler in interface CircuitBreakerhandler - the handler, must not be nullCircuitBreakerpublic CircuitBreaker closeHandler(Handler<Void> handler)
CircuitBreakerHandler invoked when the circuit breaker state switches to close.closeHandler in interface CircuitBreakerhandler - the handler, must not be nullCircuitBreakerpublic <T> CircuitBreaker fallback(Function<Throwable,T> handler)
CircuitBreakerFunction invoked when the bridge is open to handle the "request", or on failure
if CircuitBreakerOptions.isFallbackOnFailure() is enabled.
The function gets the exception as parameter and returns the fallback result.
fallback in interface CircuitBreakerhandler - the handlerCircuitBreakerpublic CircuitBreaker reset(boolean force)
force - whether or not we force the state and allow an illegal transitionpublic CircuitBreaker reset()
CircuitBreakerreset in interface CircuitBreakerCircuitBreakerpublic CircuitBreaker open()
CircuitBreakeropen in interface CircuitBreakerCircuitBreakerpublic long failureCount()
failureCount in interface CircuitBreakerpublic CircuitBreakerState state()
state in interface CircuitBreakerpublic <T> CircuitBreaker executeAndReportWithFallback(Promise<T> userFuture, Handler<Promise<T>> command, Function<Throwable,T> fallback)
CircuitBreakerPromise object as parameter and must
call Promise.complete(Object) when the operation has terminated successfully. The operation must also
call Promise.fail(Throwable) in case of failure.
The operation is not invoked if the circuit breaker is open, and the given fallback is called immediately. The circuit breaker also monitor the completion of the operation before a configure timeout. The operation is considered as failed if it does not terminate in time.
Unlike CircuitBreaker.executeWithFallback(Handler, Function), this method does return a Future object, but
let the caller pass a Promise object on which the result is reported. If the fallback is called, the promise
is successfully completed with the value returned by the fallback function. If the fallback throws an exception,
the promise is marked as failed.
executeAndReportWithFallback in interface CircuitBreakerT - the type of resultuserFuture - the promise on which the operation result is reportedcommand - the operationfallback - the fallback function. It gets an exception as parameter and returns the fallback resultCircuitBreakerpublic <T> Future<T> executeWithFallback(Handler<Promise<T>> operation, Function<Throwable,T> fallback)
CircuitBreakerPromise object as parameter and must
call Promise.complete(Object) when the operation has terminated successfully. The operation must also
call Promise.fail(Throwable) in case of failure.
The operation is not invoked if the circuit breaker is open, and the given fallback is called immediately. The circuit breaker also monitor the completion of the operation before a configure timeout. The operation is considered as failed if it does not terminate in time.
This method returns a Future object to retrieve the status and result of the operation, with the status
being a success or a failure. If the fallback is called, the returned future is successfully completed with the
value returned from the fallback. If the fallback throws an exception, the returned future is marked as failed.
executeWithFallback in interface CircuitBreakerT - the type of resultoperation - the operationfallback - the fallback function. It gets an exception as parameter and returns the fallback resultpublic <T> Future<T> execute(Handler<Promise<T>> operation)
CircuitBreakerCircuitBreaker.executeWithFallback(Handler, Function) but using the circuit breaker default fallback.execute in interface CircuitBreakerT - the type of resultoperation - the operationpublic <T> CircuitBreaker executeAndReport(Promise<T> resultFuture, Handler<Promise<T>> operation)
CircuitBreakerCircuitBreaker.executeAndReportWithFallback(Promise, Handler, Function) but using the circuit breaker default
fallback.executeAndReport in interface CircuitBreakerT - the type of resultresultFuture - the promise on which the operation result is reportedoperation - the operationCircuitBreakerpublic String name()
name in interface CircuitBreakerpublic CircuitBreakerMetrics getMetrics()
public CircuitBreakerOptions options()
public CircuitBreaker retryPolicy(Function<Integer,Long> retryPolicy)
retryPolicy in interface CircuitBreakerCopyright © 2020. All rights reserved.