CircuitBreaker

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
Companion
object
trait Product
trait Equals
trait LogSupport
trait LazyLogger
trait LoggingMethods
trait Serializable
class Object
trait Matchable
class Any

Value members

Concrete methods

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)

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

Set an event listener that monitors CircuitBreaker state changes

Set an event listener that monitors CircuitBreaker state changes

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.

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.

def reset: Unit

Reset the lastFailure and close the circuit

Reset the lastFailure and close the circuit

def run[A](body: => A)(`evidence$1`: ClassTag[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.

Force setting the current state.

Force setting the current state.

def verifyConnection: Unit

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

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.

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.

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.

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.

def withName(newName: String): CircuitBreaker

Set the name of this CircuitBreaker

Set the name of this CircuitBreaker

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.

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.

Inherited methods

inline protected def debug(inline message: Any, inline cause: Throwable): Unit
Inherited from
LoggingMethods
inline protected def debug(inline message: Any): Unit
Inherited from
LoggingMethods
inline protected def error(inline message: Any, inline cause: Throwable): Unit
Inherited from
LoggingMethods
inline protected def error(inline message: Any): Unit
Inherited from
LoggingMethods
inline protected def info(inline message: Any, inline cause: Throwable): Unit
Inherited from
LoggingMethods
inline protected def info(inline message: Any): Unit
Inherited from
LoggingMethods
inline protected def logAt(inline logLevel: LogLevel, inline message: Any): Unit
Inherited from
LoggingMethods
def productElementNames: Iterator[String]
Inherited from
Product
def productIterator: Iterator[Any]
Inherited from
Product
inline protected def trace(inline message: Any, inline cause: Throwable): Unit
Inherited from
LoggingMethods
inline protected def trace(inline message: Any): Unit
Inherited from
LoggingMethods
inline protected def warn(inline message: Any, inline cause: Throwable): Unit
Inherited from
LoggingMethods
inline protected def warn(inline message: Any): Unit
Inherited from
LoggingMethods