public final class CircuitBreakerStateMachine extends java.lang.Object implements CircuitBreaker
CircuitBreaker.CircuitBreakerFuture<T>, CircuitBreaker.EventPublisher, CircuitBreaker.Metrics, CircuitBreaker.State, CircuitBreaker.StateTransition| Constructor and Description |
|---|
CircuitBreakerStateMachine(java.lang.String name)
Creates a circuitBreaker with default config.
|
CircuitBreakerStateMachine(java.lang.String name,
CircuitBreakerConfig circuitBreakerConfig)
Creates a circuitBreaker.
|
CircuitBreakerStateMachine(java.lang.String name,
CircuitBreakerConfig circuitBreakerConfig,
java.time.Clock clock)
Creates a circuitBreaker.
|
CircuitBreakerStateMachine(java.lang.String name,
CircuitBreakerConfig circuitBreakerConfig,
java.time.Clock clock,
io.vavr.collection.Map<java.lang.String,java.lang.String> tags)
Creates a circuitBreaker.
|
CircuitBreakerStateMachine(java.lang.String name,
CircuitBreakerConfig circuitBreakerConfig,
io.vavr.collection.Map<java.lang.String,java.lang.String> tags)
Creates a circuitBreaker.
|
CircuitBreakerStateMachine(java.lang.String name,
CircuitBreakerConfig circuitBreakerConfig,
SchedulerFactory schedulerFactory)
Creates a circuitBreaker.
|
CircuitBreakerStateMachine(java.lang.String name,
java.util.function.Supplier<CircuitBreakerConfig> circuitBreakerConfig)
Creates a circuitBreaker.
|
CircuitBreakerStateMachine(java.lang.String name,
java.util.function.Supplier<CircuitBreakerConfig> circuitBreakerConfig,
io.vavr.collection.Map<java.lang.String,java.lang.String> tags)
Creates a circuitBreaker.
|
| Modifier and Type | Method and Description |
|---|---|
void |
acquirePermission()
Try to obtain a permission to execute a call.
|
CircuitBreakerConfig |
getCircuitBreakerConfig()
Get the config of this CircuitBreaker.
|
CircuitBreaker.EventPublisher |
getEventPublisher()
Returns an EventPublisher which can be used to register event consumers.
|
CircuitBreaker.Metrics |
getMetrics()
Returns the Metrics of this CircuitBreaker.
|
java.lang.String |
getName()
Get the name of this CircuitBreaker.
|
CircuitBreaker.State |
getState()
Get the state of this CircuitBreaker.
|
io.vavr.collection.Map<java.lang.String,java.lang.String> |
getTags()
Returns an unmodifiable map with tags assigned to this Retry.
|
void |
onError(long duration,
java.util.concurrent.TimeUnit durationUnit,
java.lang.Throwable throwable)
Records a failed call.
|
void |
onSuccess(long duration,
java.util.concurrent.TimeUnit durationUnit)
Records a successful call.
|
void |
releasePermission()
Releases a permission.
|
void |
reset()
Returns the circuit breaker to its original closed state, losing statistics.
|
java.lang.String |
toString() |
void |
transitionToClosedState()
Transitions the state machine to CLOSED state.
|
void |
transitionToDisabledState()
Transitions the state machine to a DISABLED state, stopping state transition, metrics and
event publishing.
|
void |
transitionToForcedOpenState()
Transitions the state machine to a FORCED_OPEN state, stopping state transition, metrics and
event publishing.
|
void |
transitionToHalfOpenState()
Transitions the state machine to HALF_OPEN state.
|
void |
transitionToOpenState()
Transitions the state machine to OPEN state.
|
boolean |
tryAcquirePermission()
Acquires a permission to execute a call, only if one is available at the time of invocation.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitdecorateCallable, decorateCallable, decorateCheckedConsumer, decorateCheckedConsumer, decorateCheckedFunction, decorateCheckedRunnable, decorateCheckedRunnable, decorateCheckedSupplier, decorateCheckedSupplier, decorateCompletionStage, decorateCompletionStage, decorateConsumer, decorateConsumer, decorateEitherSupplier, decorateEitherSupplier, decorateFunction, decorateFuture, decorateFuture, decorateRunnable, decorateRunnable, decorateSupplier, decorateSupplier, decorateTrySupplier, decorateTrySupplier, executeCallable, executeCheckedRunnable, executeCheckedSupplier, executeCompletionStage, executeEitherSupplier, executeRunnable, executeSupplier, executeTrySupplier, of, of, of, of, ofDefaultspublic CircuitBreakerStateMachine(java.lang.String name,
CircuitBreakerConfig circuitBreakerConfig,
SchedulerFactory schedulerFactory)
name - the name of the CircuitBreakercircuitBreakerConfig - The CircuitBreaker configuration.schedulerFactory - A SchedulerFactory which can be mocked in tests.public CircuitBreakerStateMachine(java.lang.String name,
CircuitBreakerConfig circuitBreakerConfig,
java.time.Clock clock)
name - the name of the CircuitBreakercircuitBreakerConfig - The CircuitBreaker configuration.public CircuitBreakerStateMachine(java.lang.String name,
CircuitBreakerConfig circuitBreakerConfig,
java.time.Clock clock,
io.vavr.collection.Map<java.lang.String,java.lang.String> tags)
name - the name of the CircuitBreakercircuitBreakerConfig - The CircuitBreaker configuration.public CircuitBreakerStateMachine(java.lang.String name,
CircuitBreakerConfig circuitBreakerConfig)
name - the name of the CircuitBreakercircuitBreakerConfig - The CircuitBreaker configuration.public CircuitBreakerStateMachine(java.lang.String name,
CircuitBreakerConfig circuitBreakerConfig,
io.vavr.collection.Map<java.lang.String,java.lang.String> tags)
name - the name of the CircuitBreakercircuitBreakerConfig - The CircuitBreaker configuration.tags - Tags to add to the CircuitBreaker.public CircuitBreakerStateMachine(java.lang.String name)
name - the name of the CircuitBreakerpublic CircuitBreakerStateMachine(java.lang.String name,
java.util.function.Supplier<CircuitBreakerConfig> circuitBreakerConfig)
name - the name of the CircuitBreakercircuitBreakerConfig - The CircuitBreaker configuration supplier.public CircuitBreakerStateMachine(java.lang.String name,
java.util.function.Supplier<CircuitBreakerConfig> circuitBreakerConfig,
io.vavr.collection.Map<java.lang.String,java.lang.String> tags)
name - the name of the CircuitBreakercircuitBreakerConfig - The CircuitBreaker configuration supplier.public boolean tryAcquirePermission()
CircuitBreakerReturns false when the state is OPEN or FORCED_OPEN. Returns true when the state is CLOSED or DISABLED. Returns true when the state is HALF_OPEN and further test calls are allowed. Returns false when the state is HALF_OPEN and the number of test calls has been reached. If the state is HALF_OPEN, the number of allowed test calls is decreased. Important: Make sure to call onSuccess or onError after the call is finished. If the call is cancelled before it is invoked, you have to release the permission again.
tryAcquirePermission in interface CircuitBreakertrue if a permission was acquired and false otherwisepublic void releasePermission()
CircuitBreaker
Should only be used when a permission was acquired but not used. Otherwise use CircuitBreaker.onSuccess(long, TimeUnit) or CircuitBreaker.onError(long, TimeUnit,
Throwable) to signal a completed or failed call.
If the state is HALF_OPEN, the number of allowed test calls is increased by one.
releasePermission in interface CircuitBreakerpublic void acquirePermission()
CircuitBreakerThrows a CallNotPermittedException when the state is OPEN or FORCED_OPEN. Returns when the state is CLOSED or DISABLED. Returns when the state is HALF_OPEN and further test calls are allowed. Throws a CallNotPermittedException when the state is HALF_OPEN and the number of test calls has been reached. If the state is HALF_OPEN, the number of allowed test calls is decreased. Important: Make sure to call onSuccess or onError after the call is finished. If the call is cancelled before it is invoked, you have to release the permission again.
acquirePermission in interface CircuitBreakerpublic void onError(long duration,
java.util.concurrent.TimeUnit durationUnit,
java.lang.Throwable throwable)
CircuitBreakeronError in interface CircuitBreakerduration - The elapsed time duration of the calldurationUnit - The duration unitthrowable - The throwable which must be recordedpublic void onSuccess(long duration,
java.util.concurrent.TimeUnit durationUnit)
CircuitBreakeronSuccess in interface CircuitBreakerduration - The elapsed time duration of the calldurationUnit - The duration unit This method must be invoked when a call was
successful.public CircuitBreaker.State getState()
getState in interface CircuitBreakerpublic java.lang.String getName()
getName in interface CircuitBreakerpublic CircuitBreakerConfig getCircuitBreakerConfig()
getCircuitBreakerConfig in interface CircuitBreakerpublic CircuitBreaker.Metrics getMetrics()
CircuitBreakergetMetrics in interface CircuitBreakerpublic io.vavr.collection.Map<java.lang.String,java.lang.String> getTags()
CircuitBreakergetTags in interface CircuitBreakerpublic java.lang.String toString()
toString in class java.lang.Objectpublic void reset()
CircuitBreakerShould only be used, when you want to want to fully reset the circuit breaker without creating a new one.
reset in interface CircuitBreakerpublic void transitionToDisabledState()
CircuitBreakerShould only be used, when you want to disable the circuit breaker allowing all calls to pass. To recover from this state you must force a new state transition
transitionToDisabledState in interface CircuitBreakerpublic void transitionToForcedOpenState()
CircuitBreakerShould only be used, when you want to disable the circuit breaker allowing no call to pass. To recover from this state you must force a new state transition
transitionToForcedOpenState in interface CircuitBreakerpublic void transitionToClosedState()
CircuitBreakerShould only be used, when you want to force a state transition. State transition are normally done internally.
transitionToClosedState in interface CircuitBreakerpublic void transitionToOpenState()
CircuitBreakerShould only be used, when you want to force a state transition. State transition are normally done internally.
transitionToOpenState in interface CircuitBreakerpublic void transitionToHalfOpenState()
CircuitBreakerShould only be used, when you want to force a state transition. State transition are normally done internally.
transitionToHalfOpenState in interface CircuitBreakerpublic CircuitBreaker.EventPublisher getEventPublisher()
CircuitBreakergetEventPublisher in interface CircuitBreaker