Package: io.vertx.groovy.circuitbreaker

## [Groovy] Class CircuitBreaker

- io.vertx.groovy.circuitbreaker.CircuitBreaker

- An implementation of the circuit breaker pattern for Vert.x

- - ### Constructor Summary

    Constructors
    Constructor and description
    `CircuitBreaker (java.lang.Object delegate)`

  - ### Methods Summary

    Methods
    Type | Name and description
    --- | ---
    `CircuitBreaker` | `close()` Closes the circuit breaker.
    `CircuitBreaker` | `closeHandler(io.vertx.core.Handler<java.lang.Void> handler)` Sets a invoked when the circuit breaker state switches to close.
    `static CircuitBreaker` | `create(java.lang.String name, Vertx vertx, java.util.Map<java.lang.String, java.lang.Object> options)` Creates a new instance of CircuitBreaker.
    `static CircuitBreaker` | `create(java.lang.String name, Vertx vertx)` Creates a new instance of CircuitBreaker, with default options.
    `Future<T>` | `execute(io.vertx.core.Handler<Future<T>> operation)` Same as CircuitBreaker.executeWithFallback but using the circuit breaker default fallback.
    `CircuitBreaker` | `executeAndReport(Future<T> resultFuture, io.vertx.core.Handler<Future<T>> operation)` Same as CircuitBreaker.executeAndReportWithFallback but using the circuit breaker default fallback.
    `CircuitBreaker` | `executeAndReportWithFallback(Future<T> resultFuture, io.vertx.core.Handler<Future<T>> operation, java.util.function.Function<java.lang.Throwable, T> fallback)` Executes the given operation with the circuit breaker control.
    `Future<T>` | `executeWithFallback(io.vertx.core.Handler<Future<T>> operation, java.util.function.Function<java.lang.Throwable, T> fallback)` Executes the given operation with the circuit breaker control.
    `long` | `failureCount()` Returns: the current number of failures.
    `CircuitBreaker` | `fallback(java.util.function.Function<java.lang.Throwable, T> handler)` Sets a default invoked when the bridge is open to handle the "request", or on failure if | `java.lang.Object` | `getDelegate()`
    `CircuitBreaker` | `halfOpenHandler(io.vertx.core.Handler<java.lang.Void> handler)` Sets a invoked when the circuit breaker state switches to half-open.
    `java.lang.String` | `name()` Returns: the name of the circuit breaker.
    `CircuitBreaker` | `open()` Explicitly opens the circuit.
    `CircuitBreaker` | `openHandler(io.vertx.core.Handler<java.lang.Void> handler)` Sets a invoked when the circuit breaker state switches to open.
    `CircuitBreaker` | `reset()` Resets the circuit breaker state (number of failure set to 0 and state set to closed).
    `CircuitBreakerState` | `state()` Returns: the current state.

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class java.lang.Object` | `java.lang.Object#wait(long, int), java.lang.Object#wait(long), java.lang.Object#wait(), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll()`

- - ### Constructor Detail

    - #### CircuitBreaker(java.lang.Object delegate)

  - ### Method Detail

    - #### CircuitBreaker close()

      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.

      Returns:

    - #### CircuitBreaker closeHandler(io.vertx.core.Handler<java.lang.Void> handler)

      Sets a invoked when the circuit breaker state switches to close.

      Returns:
        the current CircuitBreaker
      Parameters:
        `handler` - the handler, must not be `null`

    - #### static CircuitBreaker create(java.lang.String name, Vertx vertx, java.util.Map<java.lang.String, java.lang.Object> options)

      Creates a new instance of CircuitBreaker.

      Returns:
        the created instance
      Parameters:
        `name` - the name
        `vertx` - the Vert.x instance
        `options` - the configuration option (see CircuitBreakerOptions)

    - #### static CircuitBreaker create(java.lang.String name, Vertx vertx)

      Creates a new instance of CircuitBreaker, with default options.

      Returns:
        the created instance
      Parameters:
        `name` - the name
        `vertx` - the Vert.x instance

    - #### Future<T> execute(io.vertx.core.Handler<Future<T>> operation)

      Same as CircuitBreaker.executeWithFallback but using the circuit breaker default fallback.

      Returns:
        a future object completed when the operation or its fallback completes
      Parameters:
        `operation` - the operation

    - #### CircuitBreaker executeAndReport(Future<T> resultFuture, io.vertx.core.Handler<Future<T>> operation)

      Same as CircuitBreaker.executeAndReportWithFallback but using the circuit breaker default fallback.

      Returns:
        the current CircuitBreaker
      Parameters:
        `resultFuture` - the future on which the operation result is reported
        `operation` - the operation

    - #### CircuitBreaker executeAndReportWithFallback(Future<T> resultFuture, io.vertx.core.Handler<Future<T>> operation, java.util.function.Function<java.lang.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 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.

      Returns:
        the current CircuitBreaker
      Parameters:
        `resultFuture` - the future on which the operation result is reported
        `operation` - the operation
        `fallback` - the fallback function. It gets an exception as parameter and returns the fallback result

    - #### Future<T> executeWithFallback(io.vertx.core.Handler<Future<T>> operation, java.util.function.Function<java.lang.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 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.

      Returns:
        a future object completed when the operation or its fallback completes
      Parameters:
        `operation` - the operation
        `fallback` - the fallback function. It gets an exception as parameter and returns the fallback result

    - #### long failureCount()

      Returns:
        the current number of failures.

    - #### CircuitBreaker fallback(java.util.function.Function<java.lang.Throwable, T> handler)

      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.

      Returns:
        the current CircuitBreaker
      Parameters:
        `handler` - the handler

    - #### java.lang.Object getDelegate()

    - #### CircuitBreaker halfOpenHandler(io.vertx.core.Handler<java.lang.Void> handler)

      Sets a invoked when the circuit breaker state switches to half-open.

      Returns:
        the current CircuitBreaker
      Parameters:
        `handler` - the handler, must not be `null`

    - #### java.lang.String name()

      Returns:
        the name of the circuit breaker.

    - #### CircuitBreaker open()

      Explicitly opens the circuit.

      Returns:
        the current CircuitBreaker

    - #### CircuitBreaker openHandler(io.vertx.core.Handler<java.lang.Void> handler)

      Sets a invoked when the circuit breaker state switches to open.

      Returns:
        the current CircuitBreaker
      Parameters:
        `handler` - the handler, must not be `null`

    - #### CircuitBreaker reset()

      Resets the circuit breaker state (number of failure set to 0 and state set to closed).

      Returns:
        the current CircuitBreaker

    - #### CircuitBreakerState state()

      Returns:
        the current state.