CircuitBreaker

io.chrisdavenport.circuit.CircuitBreaker$
See theCircuitBreaker companion trait

Attributes

Companion:
trait
Source:
CircuitBreaker.scala
Graph
Supertypes
class Object
trait Matchable
class Any
Self type

Members list

Concise view

Type members

Classlikes

final class Builder[F[_]]

Attributes

Source:
CircuitBreaker.scala
Graph
Supertypes
class Object
trait Matchable
class Any
Self type
final case class Closed(failures: Int) extends State

The initial State of the CircuitBreaker. While in this state the circuit breaker allows tasks to be executed.

The initial State of the CircuitBreaker. While in this state the circuit breaker allows tasks to be executed.

Contract:

  • Exceptions increment the failures counter
  • Successes reset the failure count to zero
  • When the failures counter reaches the maxFailures count, the breaker is tripped into the Open state

Attributes

failures

is the current failures count

Source:
CircuitBreaker.scala
Graph
Supertypes
trait Product
trait Equals
class State
class Object
trait Matchable
class Any
case object HalfOpen extends State with Reason

State of the CircuitBreaker in which the circuit breaker has already allowed a task to go through, as a reset attempt, in order to test the connection.

State of the CircuitBreaker in which the circuit breaker has already allowed a task to go through, as a reset attempt, in order to test the connection.

Contract:

  • The first task when Open has expired is allowed through without failing fast, just before the circuit breaker is evolved into the HalfOpen state
  • All tasks attempted in HalfOpen fail-fast with an exception just as in Open state
  • If that task attempt succeeds, the breaker is reset back to the Closed state, with the resetTimeout and the failures count also reset to initial values
  • If the first call fails, the breaker is tripped again into the Open state (the resetTimeout is passed to the backoff function)

Attributes

Source:
CircuitBreaker.scala
Graph
Supertypes
trait Singleton
trait Product
trait Mirror
trait Product
trait Equals
trait Reason
class State
class Object
trait Matchable
class Any
Self type
final case class Open(startedAt: Timestamp, resetTimeout: FiniteDuration) extends State with Reason

State of the CircuitBreaker in which the circuit breaker rejects all tasks with a RejectedExecution.

State of the CircuitBreaker in which the circuit breaker rejects all tasks with a RejectedExecution.

Contract:

  • all tasks fail fast with RejectedExecution
  • after the configured resetTimeout, the circuit breaker enters a HalfOpen state, allowing one task to go through for testing the connection

Attributes

resetTimeout

is the current resetTimeout that is applied to this Open state, to be passed to the backoff function for the next transition from HalfOpen to Open, in case the reset attempt fails

startedAt

is the timestamp in milliseconds since the epoch when the transition to Open happened

Source:
CircuitBreaker.scala
Graph
Supertypes
trait Product
trait Equals
trait Reason
class State
class Object
trait Matchable
class Any
sealed trait Reason

Attributes

Source:
CircuitBreaker.scala
Graph
Supertypes
class Object
trait Matchable
class Any
Known subtypes
object HalfOpen.type
class Open
final case class RejectedExecution(reason: Reason) extends RuntimeException

Exception thrown whenever an execution attempt was rejected.

Exception thrown whenever an execution attempt was rejected.

Attributes

Source:
CircuitBreaker.scala
Graph
Supertypes
trait Product
trait Equals
class Exception
class Throwable
class Object
trait Matchable
class Any
sealed abstract class State

An enumeration that models the internal state of CircuitBreaker, kept in an AtomicReference for synchronization.

An enumeration that models the internal state of CircuitBreaker, kept in an AtomicReference for synchronization.

The initial state when initializing a CircuitBreaker is Closed. The available states:

  • Closed in case tasks are allowed to go through
  • Open in case the circuit breaker is active and rejects incoming tasks
  • HalfOpen in case a reset attempt was triggered and it is waiting for the result in order to evolve in Closed, or back to Open

Attributes

Source:
CircuitBreaker.scala
Graph
Supertypes
class Object
trait Matchable
class Any
Known subtypes
class Closed
object HalfOpen.type
class Open

Types

Type-alias to document timestamps specified in milliseconds, as returned by Clock.realTime.

Type-alias to document timestamps specified in milliseconds, as returned by Clock.realTime.

Attributes

Source:
CircuitBreaker.scala

Value members

Concrete methods

def default[F[_]](maxFailures: Int, resetTimeout: FiniteDuration)(implicit F: Applicative[F]): Builder[F]

Attributes

Source:
CircuitBreaker.scala
def in[F[_], G[_]](maxFailures: Int, resetTimeout: FiniteDuration, backoff: FiniteDuration => FiniteDuration, maxResetTimeout: Duration)(implicit F: Sync[F], G: Async[G]): F[CircuitBreaker[G]]

Builder for a CircuitBreaker reference.

Builder for a CircuitBreaker reference.

Effect returned by this operation produces a new CircuitBreaker each time it is evaluated. To share a state between multiple consumers, pass CircuitBreaker as a parameter

Attributes

backoff

is a function from FiniteDuration to FiniteDuration used to determine the resetTimeout when in the HalfOpen state, in case the attempt to Close fails. Backoff provides some default implementations.

maxFailures

is the maximum count for failures before opening the circuit breaker

maxResetTimeout

is the maximum timeout the circuit breaker is allowed to use when applying the backoff

resetTimeout

is the timeout to wait in the Open state before attempting a close of the circuit breaker (but without the backoff function applied)

Source:
CircuitBreaker.scala
def in[F[_], G[_]](maxFailures: Int, resetTimeout: FiniteDuration, backoff: FiniteDuration => FiniteDuration, maxResetTimeout: Duration, onRejected: G[Unit], onClosed: G[Unit], onHalfOpen: G[Unit], onOpen: G[Unit])(implicit F: Sync[F], G: Async[G]): F[CircuitBreaker[G]]

Builder for a CircuitBreaker reference.

Builder for a CircuitBreaker reference.

Effect returned by this operation produces a new CircuitBreaker each time it is evaluated. To share a state between multiple consumers, pass CircuitBreaker as a parameter

This method returns a circuit breaker inside of a different effect from its own. For a simpler version, see CircuitBreaker.of.

Attributes

backoff

is a function from FiniteDuration to FiniteDuration used to determine the resetTimeout when in the HalfOpen state, in case the attempt to Close fails. Backoff provides some default implementations.

maxFailures

is the maximum count for failures before opening the circuit breaker

maxResetTimeout

is the maximum timeout the circuit breaker is allowed to use when applying the backoff

onClosed

is for signaling a transition to Closed

onHalfOpen

is for signaling a transition to HalfOpen

onOpen

is for signaling a transition to Open

onRejected

is for signaling rejected tasks

resetTimeout

is the timeout to wait in the Open state before attempting a close of the circuit breaker (but without the backoff function applied)

Source:
CircuitBreaker.scala
def noop[F[_]](implicit F: Applicative[F]): CircuitBreaker[F]

Creates a No-Operation circuit breaker which is always closed and passes through the effect.

Creates a No-Operation circuit breaker which is always closed and passes through the effect.

Attributes

Source:
CircuitBreaker.scala
def of[F[_]](maxFailures: Int, resetTimeout: FiniteDuration, backoff: FiniteDuration => FiniteDuration, maxResetTimeout: Duration)(implicit F: Temporal[F]): F[CircuitBreaker[F]]

Builder for a CircuitBreaker reference.

Builder for a CircuitBreaker reference.

Effect returned by this operation produces a new CircuitBreaker each time it is evaluated. To share a state between multiple consumers, pass CircuitBreaker as a parameter

Attributes

backoff

is a function from FiniteDuration to FiniteDuration used to determine the resetTimeout when in the HalfOpen state, in case the attempt to Close fails. Backoff provides some default implementations.

maxFailures

is the maximum count for failures before opening the circuit breaker

maxResetTimeout

is the maximum timeout the circuit breaker is allowed to use when applying the backoff result.

resetTimeout

is the timeout to wait in the Open state before attempting a close of the circuit breaker (but without the backoff function applied)

Source:
CircuitBreaker.scala
def of[F[_]](maxFailures: Int, resetTimeout: FiniteDuration, backoff: FiniteDuration => FiniteDuration, maxResetTimeout: Duration, onRejected: F[Unit], onClosed: F[Unit], onHalfOpen: F[Unit], onOpen: F[Unit])(implicit F: Temporal[F]): F[CircuitBreaker[F]]

Builder for a CircuitBreaker reference.

Builder for a CircuitBreaker reference.

Effect returned by this operation produces a new CircuitBreaker each time it is evaluated. To share a state between multiple consumers, pass CircuitBreaker as a parameter

Attributes

backoff

is a function from FiniteDuration to FiniteDuration used to determine the resetTimeout when in the HalfOpen state, in case the attempt to Close fails. Backoff provides some default implementations.

maxFailures

is the maximum count for failures before opening the circuit breaker

maxResetTimeout

is the maximum timeout the circuit breaker is allowed to use when applying the backoff

onClosed

is for signaling a transition to Closed

onHalfOpen

is for signaling a transition to HalfOpen

onOpen

is for signaling a transition to Open

onRejected

is for signaling rejected tasks

resetTimeout

is the timeout to wait in the Open state before attempting a close of the circuit breaker (but without the backoff function applied)

Source:
CircuitBreaker.scala
def unsafe[G[_] : Temporal](ref: Ref[G, State], maxFailures: Int, resetTimeout: FiniteDuration, backoff: FiniteDuration => FiniteDuration, maxResetTimeout: Duration, onRejected: G[Unit], onClosed: G[Unit], onHalfOpen: G[Unit], onOpen: G[Unit]): CircuitBreaker[G]

For Custom Ref Implementations Ideally this will be in some valid state for the state machine and that maxFailures/resetTimeout/backoff/maxResetTimeout will all be consistent across users or else you may wait based on incorrect information.

For Custom Ref Implementations Ideally this will be in some valid state for the state machine and that maxFailures/resetTimeout/backoff/maxResetTimeout will all be consistent across users or else you may wait based on incorrect information.

Attributes

Source:
CircuitBreaker.scala