new CircuitBreaker()
An implementation of the circuit breaker pattern for Vert.x
- Source:
Methods
close() → {CircuitBreaker}
Closes the circuit breaker. It stops sending events on its state on the event bus.
This method is not related to the close
state of the circuit breaker. To set the circuit breaker in the
close
state, use CircuitBreaker#reset.
- Source:
Returns:
-
Type
-
CircuitBreaker
closeHandler(handler) → {CircuitBreaker}
Sets a invoked when the circuit breaker state switches to close.
Parameters:
Name |
Type |
Description |
handler |
function
|
the handler, must not be null |
- Source:
Returns:
the current CircuitBreaker
-
Type
-
CircuitBreaker
execute(operation) → {Future}
Same as CircuitBreaker#executeWithFallback but using the circuit breaker default fallback.
Parameters:
Name |
Type |
Description |
operation |
function
|
the operation |
- Source:
Returns:
a future object completed when the operation or its fallback completes
-
Type
-
Future
executeAndReport(resultFuture, operation) → {CircuitBreaker}
Same as CircuitBreaker#executeAndReportWithFallback but using the circuit breaker default
fallback.
Parameters:
Name |
Type |
Description |
resultFuture |
Future
|
the future on which the operation result is reported |
operation |
function
|
the operation |
- Source:
Returns:
the current CircuitBreaker
-
Type
-
CircuitBreaker
executeAndReportWithFallback(resultFuture, operation, fallback) → {CircuitBreaker}
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 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, this method does return a object, but
let the caller pass a object on which the result is reported. If the fallback is called, the future
is successfully completed with the value returned by the fallback function. If the fallback throws an exception,
the future is marked as failed.
Parameters:
Name |
Type |
Description |
resultFuture |
Future
|
the future on which the operation result is reported |
operation |
function
|
the operation |
fallback |
todo
|
the fallback function. It gets an exception as parameter and returns the fallback result |
- Source:
Returns:
the current CircuitBreaker
-
Type
-
CircuitBreaker
executeWithFallback(operation, fallback) → {Future}
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 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 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:
Name |
Type |
Description |
operation |
function
|
the operation |
fallback |
todo
|
the fallback function. It gets an exception as parameter and returns the fallback result |
- Source:
Returns:
a future object completed when the operation or its fallback completes
-
Type
-
Future
failureCount() → {number}
- Source:
Returns:
fallback(handler) → {CircuitBreaker}
Sets a
default invoked when the bridge is open to handle the "request", or on failure
if
CircuitBreakerOptions is enabled.
The function gets the exception as parameter and returns the fallback result.
Parameters:
Name |
Type |
Description |
handler |
todo
|
the handler |
- Source:
Returns:
the current CircuitBreaker
-
Type
-
CircuitBreaker
halfOpenHandler(handler) → {CircuitBreaker}
Sets a invoked when the circuit breaker state switches to half-open.
Parameters:
Name |
Type |
Description |
handler |
function
|
the handler, must not be null |
- Source:
Returns:
the current CircuitBreaker
-
Type
-
CircuitBreaker
name() → {string}
- Source:
Returns:
open() → {CircuitBreaker}
Explicitly opens the circuit.
- Source:
Returns:
the current CircuitBreaker
-
Type
-
CircuitBreaker
openHandler(handler) → {CircuitBreaker}
Sets a invoked when the circuit breaker state switches to open.
Parameters:
Name |
Type |
Description |
handler |
function
|
the handler, must not be null |
- Source:
Returns:
the current CircuitBreaker
-
Type
-
CircuitBreaker
reset() → {CircuitBreaker}
Resets the circuit breaker state (number of failure set to 0 and state set to closed).
- Source:
Returns:
the current CircuitBreaker
-
Type
-
CircuitBreaker
state() → {Object}
- Source:
Returns:
-
the current state.
-
-
Type
-
Object