CircuitBreaker

wvlet.airframe.control.CircuitBreaker
See theCircuitBreaker companion object
case class CircuitBreaker(name: String, healthCheckPolicy: HealthCheckPolicy, resultClassifier: Any => ResultClass, errorClassifier: Throwable => Failed, onOpenFailureHandler: CircuitBreakerContext => Unit, onStateChangeListener: CircuitBreakerContext => Unit, fallbackHandler: Throwable => Any, delayAfterMarkedDead: RetryPolicy, recoveryPolicy: CircuitBreakerRecoveryPolicy, var nextProvingTimeMillis: Long, var provingWaitTimeMillis: Long, var lastFailure: Option[Throwable], currentState: AtomicReference[CircuitBreakerState]) extends CircuitBreakerContext with LogSupport

Attributes

Companion:
object
Graph
Supertypes
trait Product
trait Equals
trait LogSupport
trait LazyLogger
trait LoggingMethods
trait Serializable
class Object
trait Matchable
class Any

Members list

Concise view

Value members

Concrete methods

def close: CircuitBreaker.this.type
def halfOpen: CircuitBreaker.this.type
def isConnected: Boolean

Returns true when the circuit can execute the code ( OPEN or HALF_OPEN state)

Returns true when the circuit can execute the code ( OPEN or HALF_OPEN state)

Attributes

Defines the action when trying to use the open circuit. The default behavior is to throw CircuitBreakerOpenException

Defines the action when trying to use the open circuit. The default behavior is to throw CircuitBreakerOpenException

Attributes

Set an event listener that monitors CircuitBreaker state changes

Set an event listener that monitors CircuitBreaker state changes

Attributes

def open: CircuitBreaker.this.type
def recordFailure(e: Throwable): Unit

Note: Use this method only for the standalone mode. Generally, using CircuitBreaker.run is sufficient.

Note: Use this method only for the standalone mode. Generally, using CircuitBreaker.run is sufficient.

This method reports a failure state to the CircuitBreaker.

Attributes

def recordSuccess: Unit

Note: Use this method only for the standalone mode. Generally, using CircuitBreaker.run is sufficient.

Note: Use this method only for the standalone mode. Generally, using CircuitBreaker.run is sufficient.

This method reports a successful state to the CircuitBreaker.

Attributes

def reset: Unit

Reset the lastFailure and close the circuit

Reset the lastFailure and close the circuit

Attributes

def run[A : ClassTag](body: => A): A

Execute the body block through the CircuitBreaker.

Execute the body block through the CircuitBreaker.

If the state is OPEN, this will throw CircuitBreakerOpenException (fail-fast). The state will move to HALF_OPEN state after a certain amount of delay, determined by the delayAfterMarkedDead policy.

If the state is HALF_OPEN, this method allows running the code block once, and if the result is successful, the state will move to CLOSED. If not, the state will be OPEN again.

If the state is CLOSED, the code block will be executed normally. If the result is marked failure or nonRetryable exception is thrown, it will report to the failure to the HealthCheckPolicy. If this policy determines the target service is dead, the circuit will shift to OPEN state to block the future execution.

Attributes

def setState(newState: CircuitBreakerState): CircuitBreaker.this.type

Force setting the current state.

Force setting the current state.

Attributes

Note: Use this method only for the standalone mode. Generally, using CircuiteBreaker.run is sufficient.

Note: Use this method only for the standalone mode. Generally, using CircuiteBreaker.run is sufficient.

If the connection is open, perform the specified action. The default behavior is fail-fast, i.e., throwing CircuitBreakerOpenException

Attributes

Set a delay policy until moving the state from OPEN to HALF_OPEN (probing) state. The default is Jittered-exponential backoff delay with the initial interval of 30 seconds.

Set a delay policy until moving the state from OPEN to HALF_OPEN (probing) state. The default is Jittered-exponential backoff delay with the initial interval of 30 seconds.

Attributes

def withErrorClassifier(newErrorClassifier: Throwable => Failed): CircuitBreaker

Set a classifier to determine whether the exception happened in the code block can be ignoreable or not for the accessing the target service.

Set a classifier to determine whether the exception happened in the code block can be ignoreable or not for the accessing the target service.

Attributes

def withFallbackHandler(handler: Throwable => Any): CircuitBreaker

Set a fallback handler which process the exception happened in the code block. The default is just throwing the exception as it is.

Set a fallback handler which process the exception happened in the code block. The default is just throwing the exception as it is.

Attributes

Set a health check policy, which will be used to determine the state of the target service.

Set a health check policy, which will be used to determine the state of the target service.

Attributes

def withName(newName: String): CircuitBreaker

Set the name of this CircuitBreaker

Set the name of this CircuitBreaker

Attributes

Set a recovery policiy which determine if ths circuit breaker can recover from HALF_OPEN to CLOSED. The default policy recovers immediately if health check is once successful.

Set a recovery policiy which determine if ths circuit breaker can recover from HALF_OPEN to CLOSED. The default policy recovers immediately if health check is once successful.

Attributes

def withResultClassifier(newResultClassifier: Any => ResultClass): CircuitBreaker

Set a classifier to determine whether the execution result of the code block is successful or not.

Set a classifier to determine whether the execution result of the code block is successful or not.

Attributes

Inherited methods

inline protected def debug(inline message: Any, inline cause: Throwable): Unit

Attributes

Inherited from:
LoggingMethods
inline protected def debug(inline message: Any): Unit

Attributes

Inherited from:
LoggingMethods
inline protected def error(inline message: Any, inline cause: Throwable): Unit

Attributes

Inherited from:
LoggingMethods
inline protected def error(inline message: Any): Unit

Attributes

Inherited from:
LoggingMethods
inline protected def info(inline message: Any, inline cause: Throwable): Unit

Attributes

Inherited from:
LoggingMethods
inline protected def info(inline message: Any): Unit

Attributes

Inherited from:
LoggingMethods
inline protected def logAt(inline logLevel: LogLevel, inline message: Any): Unit

Attributes

Inherited from:
LoggingMethods
def productElementNames: Iterator[String]

Attributes

Inherited from:
Product
def productIterator: Iterator[Any]

Attributes

Inherited from:
Product
inline protected def trace(inline message: Any, inline cause: Throwable): Unit

Attributes

Inherited from:
LoggingMethods
inline protected def trace(inline message: Any): Unit

Attributes

Inherited from:
LoggingMethods
inline protected def warn(inline message: Any, inline cause: Throwable): Unit

Attributes

Inherited from:
LoggingMethods
inline protected def warn(inline message: Any): Unit

Attributes

Inherited from:
LoggingMethods