All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.norwae.circuit4stream.CircuitBreakerMode.scala Maven / Gradle / Ivy

Go to download

This module packages a circuit breaker that can be used to avoid overloading or otherwise depending on a temporarily unavailable (remote) system. The central use of the circuit breaker is to prevent failures from one system to cascade to other systems in an unchecked manner. Thus, our implementation is chiefly concerned with replacing a failing component with another component that fails in a very predictable manner. These failures are not "dropped" or otherwise made invisible, and still need to be handled, but they will occur in a predictable, and hopefully usable manner.

The newest version!
package com.github.norwae.circuit4stream

import java.time.Instant

/**
  * The mode for a circuit breaker - the breaker can either
  * bypass the failing component (for example to relieve
  * pressure on an other system), or backpressure the stream
  */
sealed trait CircuitBreakerMode

object CircuitBreakerMode {

  /** Select backpressure mode - the circuit breaker will
    * backpressure the stream while open, not request
    * new elements from upstream until it closes
    */
  case object Backpressure extends CircuitBreakerMode

  /**
    * Select bypass mode - the circuit breaker will request
    * an upstream event immediately, pushing a failure
    * with a [[CircuitBreakerIsOpen]] exception
    * downstream instead of stressing the failing component
    */
  case object Bypass extends CircuitBreakerMode

  /**
    * Unique exception object to indicate the circuit breaker
    * is currently open
    *
    * @param originalValue value causing this exception
    */
  case class CircuitBreakerIsOpen(originalValue: Any, nextReset: Instant) extends Exception("The circuit breaker is currently open", null, false, false)

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy