# Class: CircuitBreaker

## vertx-circuit-breaker-js/circuit_breaker~ CircuitBreaker

#### new CircuitBreaker()

An implementation of the circuit breaker pattern for Vert.x

Source:
  - vertx-circuit-breaker-js/circuit_breaker.js, line 32

### 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:
  - vertx-circuit-breaker-js/circuit_breaker.js, line 46

##### 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:
  - vertx-circuit-breaker-js/circuit_breaker.js, line 91

##### 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:
  - vertx-circuit-breaker-js/circuit_breaker.js, line 137

##### 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:
  - vertx-circuit-breaker-js/circuit_breaker.js, line 155

##### 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:
  - vertx-circuit-breaker-js/circuit_breaker.js, line 186

##### 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:
  - vertx-circuit-breaker-js/circuit_breaker.js, line 118

##### Returns:

a future object completed when the operation or its fallback completes

Type
  Future

#### failureCount() → {number}

Source:
  - vertx-circuit-breaker-js/circuit_breaker.js, line 269

##### 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:
  - vertx-circuit-breaker-js/circuit_breaker.js, line 209

##### 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:
  - vertx-circuit-breaker-js/circuit_breaker.js, line 76

##### Returns:

the current CircuitBreaker

Type
  CircuitBreaker

#### name() → {string}

Source:
  - vertx-circuit-breaker-js/circuit_breaker.js, line 282

##### Returns:

the name of the circuit breaker.

Type
  string

#### open() → {CircuitBreaker}

Explicitly opens the circuit.

Source:
  - vertx-circuit-breaker-js/circuit_breaker.js, line 242

##### 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:
  - vertx-circuit-breaker-js/circuit_breaker.js, line 61

##### 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:
  - vertx-circuit-breaker-js/circuit_breaker.js, line 227

##### Returns:

the current CircuitBreaker

Type
  CircuitBreaker

#### state() → {Object}

Source:
  - vertx-circuit-breaker-js/circuit_breaker.js, line 256

##### Returns:

the current state.

Type
  Object