Class CircuitBreaker
- java.lang.Object
-
- io.vertx.reactivex.circuitbreaker.CircuitBreaker
-
-
Field Summary
Fields Modifier and Type Field Description static io.vertx.lang.rx.TypeArg<CircuitBreaker>
__TYPE_ARG
-
Constructor Summary
Constructors Constructor Description CircuitBreaker(CircuitBreaker delegate)
CircuitBreaker(Object delegate)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description CircuitBreaker
close()
Closes the circuit breaker.CircuitBreaker
closeHandler(Handler<Void> handler)
Sets a to be invoked when the circuit breaker state switches to closed.static CircuitBreaker
create(String name, Vertx vertx)
Creates a new instance ofCircuitBreaker
, with default options.static CircuitBreaker
create(String name, Vertx vertx, CircuitBreakerOptions options)
Creates a new instance ofCircuitBreaker
.boolean
equals(Object o)
<T> Future<T>
execute(Handler<Promise<T>> command)
Same asexecuteWithFallback(io.vertx.core.Handler<io.vertx.reactivex.core.Promise<T>>, java.util.function.Function<java.lang.Throwable, T>)
but using the circuit breaker .<T> Future<T>
execute(java.util.function.Supplier<Future<T>> command)
Same asexecuteWithFallback(io.vertx.core.Handler<io.vertx.reactivex.core.Promise<T>>, java.util.function.Function<java.lang.Throwable, T>)
but using the circuit breaker .<T> CircuitBreaker
executeAndReport(Promise<T> resultPromise, Handler<Promise<T>> command)
<T> CircuitBreaker
executeAndReportWithFallback(Promise<T> resultPromise, Handler<Promise<T>> command, java.util.function.Function<Throwable,T> fallback)
Executes the given operation with the circuit breaker control.<T> Future<T>
executeWithFallback(Handler<Promise<T>> command, java.util.function.Function<Throwable,T> fallback)
Executes the given operation with the circuit breaker control.<T> Future<T>
executeWithFallback(java.util.function.Supplier<Future<T>> command, java.util.function.Function<Throwable,T> fallback)
Executes the given operation with the circuit breaker control.long
failureCount()
<T> CircuitBreaker
failurePolicy(FailurePolicy<T> failurePolicy)
Configures the failure policy for this circuit-breaker.<T> CircuitBreaker
fallback(java.util.function.Function<Throwable,T> handler)
Sets a default fallback to be invoked when the circuit breaker is open or when failure occurs andCircuitBreakerOptions
is enabled.CircuitBreaker
getDelegate()
CircuitBreaker
halfOpenHandler(Handler<Void> handler)
Sets a to be invoked when the circuit breaker state switches to half-open.int
hashCode()
String
name()
static CircuitBreaker
newInstance(CircuitBreaker arg)
CircuitBreaker
open()
Explicitly opens the circuit breaker.CircuitBreaker
openHandler(Handler<Void> handler)
Sets a to be invoked when the circuit breaker state switches to open.CircuitBreaker
reset()
Resets the circuit breaker state.CircuitBreaker
retryPolicy(RetryPolicy retryPolicy)
Set aRetryPolicy
which computes a delay before a retry attempt.CircuitBreaker
retryPolicy(java.util.function.Function<Integer,Long> retryPolicy)
Deprecated.<T> Single<T>
rxExecute(Handler<Promise<T>> command)
Same asexecuteWithFallback(io.vertx.core.Handler<io.vertx.reactivex.core.Promise<T>>, java.util.function.Function<java.lang.Throwable, T>)
but using the circuit breaker .<T> Single<T>
rxExecute(java.util.function.Supplier<Future<T>> command)
Same asexecuteWithFallback(io.vertx.core.Handler<io.vertx.reactivex.core.Promise<T>>, java.util.function.Function<java.lang.Throwable, T>)
but using the circuit breaker .<T> Single<T>
rxExecuteWithFallback(Handler<Promise<T>> command, java.util.function.Function<Throwable,T> fallback)
Executes the given operation with the circuit breaker control.<T> Single<T>
rxExecuteWithFallback(java.util.function.Supplier<Future<T>> command, java.util.function.Function<Throwable,T> fallback)
Executes the given operation with the circuit breaker control.CircuitBreakerState
state()
String
toString()
-
-
-
Field Detail
-
__TYPE_ARG
public static final io.vertx.lang.rx.TypeArg<CircuitBreaker> __TYPE_ARG
-
-
Constructor Detail
-
CircuitBreaker
public CircuitBreaker(CircuitBreaker delegate)
-
CircuitBreaker
public CircuitBreaker(Object delegate)
-
-
Method Detail
-
getDelegate
public CircuitBreaker getDelegate()
-
create
public static CircuitBreaker create(String name, Vertx vertx, CircuitBreakerOptions options)
Creates a new instance ofCircuitBreaker
.- Parameters:
name
- the namevertx
- the Vert.x instanceoptions
- the configuration options- Returns:
- the created instance
-
create
public static CircuitBreaker create(String name, Vertx vertx)
Creates a new instance ofCircuitBreaker
, with default options.- Parameters:
name
- the namevertx
- the Vert.x instance- Returns:
- the created instance
-
close
public CircuitBreaker close()
Closes the circuit breaker. It stops sending events on its state on the event bus.This method is not related to the
closed
state of the circuit breaker. To move the circuit breaker to theclosed
state, usereset()
.- Returns:
-
openHandler
public CircuitBreaker openHandler(Handler<Void> handler)
Sets a to be invoked when the circuit breaker state switches to open.- Parameters:
handler
- the handler, must not benull
- Returns:
- this
CircuitBreaker
-
halfOpenHandler
public CircuitBreaker halfOpenHandler(Handler<Void> handler)
Sets a to be invoked when the circuit breaker state switches to half-open.- Parameters:
handler
- the handler, must not benull
- Returns:
- this
CircuitBreaker
-
closeHandler
public CircuitBreaker closeHandler(Handler<Void> handler)
Sets a to be invoked when the circuit breaker state switches to closed.- Parameters:
handler
- the handler, must not benull
- Returns:
- this
CircuitBreaker
-
executeWithFallback
public <T> Future<T> executeWithFallback(Handler<Promise<T>> command, java.util.function.Function<Throwable,T> fallback)
Executes the given operation with the circuit breaker control. The operation is generally calling an external system. The operation receives a object as parameter and must call when the operation has terminated successfully. The operation must also call in case of a failure.The operation is not invoked if the circuit breaker is open, and the given fallback is called instead. The circuit breaker also monitors whether the operation completes in time. The operation is considered failed if it does not terminate before the configured timeout.
This method returns a 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.
- Parameters:
command
- the operationfallback
- the fallback function; gets an exception as parameter and returns the fallback result- Returns:
- a future object completed when the operation or the fallback completes
-
rxExecuteWithFallback
public <T> Single<T> rxExecuteWithFallback(Handler<Promise<T>> command, java.util.function.Function<Throwable,T> fallback)
Executes the given operation with the circuit breaker control. The operation is generally calling an external system. The operation receives a object as parameter and must call when the operation has terminated successfully. The operation must also call in case of a failure.The operation is not invoked if the circuit breaker is open, and the given fallback is called instead. The circuit breaker also monitors whether the operation completes in time. The operation is considered failed if it does not terminate before the configured timeout.
This method returns a 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.
- Parameters:
command
- the operationfallback
- the fallback function; gets an exception as parameter and returns the fallback result- Returns:
- a future object completed when the operation or the fallback completes
-
executeWithFallback
public <T> Future<T> executeWithFallback(java.util.function.Supplier<Future<T>> command, java.util.function.Function<Throwable,T> fallback)
Executes the given operation with the circuit breaker control. The operation is generally calling an external system. The operation receives a object as parameter and must call when the operation has terminated successfully. The operation must also call in case of a failure.The operation is not invoked if the circuit breaker is open, and the given fallback is called instead. The circuit breaker also monitors whether the operation completes in time. The operation is considered failed if it does not terminate before the configured timeout.
This method returns a 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.
- Parameters:
command
- the operationfallback
- the fallback function; gets an exception as parameter and returns the fallback result- Returns:
- a future object completed when the operation or the fallback completes
-
rxExecuteWithFallback
public <T> Single<T> rxExecuteWithFallback(java.util.function.Supplier<Future<T>> command, java.util.function.Function<Throwable,T> fallback)
Executes the given operation with the circuit breaker control. The operation is generally calling an external system. The operation receives a object as parameter and must call when the operation has terminated successfully. The operation must also call in case of a failure.The operation is not invoked if the circuit breaker is open, and the given fallback is called instead. The circuit breaker also monitors whether the operation completes in time. The operation is considered failed if it does not terminate before the configured timeout.
This method returns a 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.
- Parameters:
command
- the operationfallback
- the fallback function; gets an exception as parameter and returns the fallback result- Returns:
- a future object completed when the operation or the fallback completes
-
execute
public <T> Future<T> execute(Handler<Promise<T>> command)
Same asexecuteWithFallback(io.vertx.core.Handler<io.vertx.reactivex.core.Promise<T>>, java.util.function.Function<java.lang.Throwable, T>)
but using the circuit breaker .- Parameters:
command
- the operation- Returns:
- a future object completed when the operation or its fallback completes
-
rxExecute
public <T> Single<T> rxExecute(Handler<Promise<T>> command)
Same asexecuteWithFallback(io.vertx.core.Handler<io.vertx.reactivex.core.Promise<T>>, java.util.function.Function<java.lang.Throwable, T>)
but using the circuit breaker .- Parameters:
command
- the operation- Returns:
- a future object completed when the operation or its fallback completes
-
execute
public <T> Future<T> execute(java.util.function.Supplier<Future<T>> command)
Same asexecuteWithFallback(io.vertx.core.Handler<io.vertx.reactivex.core.Promise<T>>, java.util.function.Function<java.lang.Throwable, T>)
but using the circuit breaker .- Parameters:
command
- the operation- Returns:
- a future object completed when the operation or its fallback completes
-
rxExecute
public <T> Single<T> rxExecute(java.util.function.Supplier<Future<T>> command)
Same asexecuteWithFallback(io.vertx.core.Handler<io.vertx.reactivex.core.Promise<T>>, java.util.function.Function<java.lang.Throwable, T>)
but using the circuit breaker .- Parameters:
command
- the operation- Returns:
- a future object completed when the operation or its fallback completes
-
executeAndReport
public <T> CircuitBreaker executeAndReport(Promise<T> resultPromise, Handler<Promise<T>> command)
Same asexecuteAndReportWithFallback(io.vertx.reactivex.core.Promise<T>, io.vertx.core.Handler<io.vertx.reactivex.core.Promise<T>>, java.util.function.Function<java.lang.Throwable, T>)
but using the circuit breaker .- Parameters:
resultPromise
- the promise on which the operation result is reportedcommand
- the operation- Returns:
- this
CircuitBreaker
-
executeAndReportWithFallback
public <T> CircuitBreaker executeAndReportWithFallback(Promise<T> resultPromise, Handler<Promise<T>> command, java.util.function.Function<Throwable,T> fallback)
Executes the given operation with the circuit breaker control. The operation is generally calling an external system. The operation receives a object as parameter and must call when the operation has terminated successfully. The operation must also call in case of a failure.The operation is not invoked if the circuit breaker is open, and the given fallback is called instead. The circuit breaker also monitors whether the operation completes in time. The operation is considered failed if it does not terminate before the configured timeout.
Unlike
executeWithFallback(io.vertx.core.Handler<io.vertx.reactivex.core.Promise<T>>, java.util.function.Function<java.lang.Throwable, T>)
, this method does not return a object, but lets the caller pass a 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.- Parameters:
resultPromise
- the promise on which the operation result is reportedcommand
- the operationfallback
- the fallback function; gets an exception as parameter and returns the fallback result- Returns:
- this
CircuitBreaker
-
fallback
public <T> CircuitBreaker fallback(java.util.function.Function<Throwable,T> handler)
Sets a default fallback to be invoked when the circuit breaker is open or when failure occurs andCircuitBreakerOptions
is enabled.The function gets the exception as parameter and returns the fallback result.
- Parameters:
handler
- the fallback handler- Returns:
- this
CircuitBreaker
-
failurePolicy
public <T> CircuitBreaker failurePolicy(FailurePolicy<T> failurePolicy)
Configures the failure policy for this circuit-breaker.- Parameters:
failurePolicy
-- Returns:
- the current
CircuitBreaker
-
reset
public CircuitBreaker reset()
Resets the circuit breaker state. The number of recent failures is set to 0 and if the state is half-open, it is set to closed.- Returns:
- this
CircuitBreaker
-
open
public CircuitBreaker open()
Explicitly opens the circuit breaker.- Returns:
- this
CircuitBreaker
-
state
public CircuitBreakerState state()
- Returns:
- the current state of this circuit breaker
-
failureCount
public long failureCount()
- Returns:
- the current number of recorded failures
-
name
public String name()
- Returns:
- the name of this circuit breaker
-
retryPolicy
@Deprecated public CircuitBreaker retryPolicy(java.util.function.Function<Integer,Long> retryPolicy)
Deprecated.- Parameters:
retryPolicy
-- Returns:
-
retryPolicy
public CircuitBreaker retryPolicy(RetryPolicy retryPolicy)
Set aRetryPolicy
which computes a delay before a retry attempt.- Parameters:
retryPolicy
-- Returns:
-
newInstance
public static CircuitBreaker newInstance(CircuitBreaker arg)
-
-