Class: CircuitBreaker

vertx-circuit-breaker-js/circuit_breaker~ CircuitBreaker

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(command) → {Future}

Same as CircuitBreaker#executeWithFallback but using the circuit breaker default fallback.
Parameters:
Name Type Description
command function the operation
Source:
Returns:
a future object completed when the operation or its fallback completes
Type
Future

executeAndReport(resultFuture, command) → {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
command function the operation
Source:
Returns:
the current CircuitBreaker
Type
CircuitBreaker

executeAndReportWithFallback(resultFuture, command, 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
command 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

executeCommand(command, handler)

Same as CircuitBreaker#executeWithFallback but using the circuit breaker default fallback.
Parameters:
Name Type Description
command function the operation
handler function
Source:

executeCommandWithFallback(command, fallback, handler)

Same as CircuitBreaker#executeWithFallback but using a callback.
Parameters:
Name Type Description
command function the operation
fallback todo the fallback
handler function the completion handler receiving either the operation result or the fallback result. The parameter is an because if the fallback is not called, the error is passed to the handler.
Source:

executeWithFallback(command, 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
command 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:
the current number of failures.
Type
number

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:
the name of the circuit breaker.
Type
string

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