AbstractCircuitBreaker (Apache Commons Lang 3.17.0 API)
Description: declaration: package: org.apache.commons.lang3.concurrent, class: AbstractCircuitBreaker

Package org.apache.commons.lang3.concurrent

# Class AbstractCircuitBreaker<T>

java.lang.Object
org.apache.commons.lang3.concurrent.AbstractCircuitBreaker<T>

Type Parameters:
  `T` - the type of the value monitored by this circuit breaker

All Implemented Interfaces:
  `CircuitBreaker<T>`

Direct Known Subclasses:
  `EventCountCircuitBreaker`, `ThresholdCircuitBreaker`

public abstract class AbstractCircuitBreaker<T> extends Object implements CircuitBreaker<T>
Base class for circuit breakers.

Since:
  3.5

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `protected static enum`
  `AbstractCircuitBreaker.State`
  An internal enumeration representing the different states of a circuit breaker.

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final String`
  `PROPERTY_NAME`
  The name of the open property as it is passed to registered change listeners.
  `protected final AtomicReference<AbstractCircuitBreaker.State>`
  `state`
  The current state of this circuit breaker.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `AbstractCircuitBreaker()`
  Creates an `AbstractCircuitBreaker`.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `addChangeListener(PropertyChangeListener listener)`
  Adds a change listener to this circuit breaker.
  `protected void`
  `changeState(AbstractCircuitBreaker.State newState)`
  Changes the internal state of this circuit breaker.
  `abstract boolean`
  `checkState()`
  Checks the state of this circuit breaker and changes it if necessary.
  `void`
  `close()`
  Closes this circuit breaker.
  `abstract boolean`
  `incrementAndCheckState(T increment)`
  Increments the monitored value and performs a check of the current state of this circuit breaker.
  `boolean`
  `isClosed()`
  Tests the current closed state of this circuit breaker.
  `boolean`
  `isOpen()`
  Tests the current open state of this circuit breaker.
  `protected static boolean`
  `isOpen(AbstractCircuitBreaker.State state)`
  Converts the given state value to a boolean open property.
  `void`
  `open()`
  Opens this circuit breaker.
  `void`
  `removeChangeListener(PropertyChangeListener listener)`
  Removes the specified change listener from this circuit breaker.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### PROPERTY_NAME

    public static final String PROPERTY_NAME
    The name of the open property as it is passed to registered change listeners.
    See Also:
      - Constant Field Values

  - ### state

    protected final AtomicReference<AbstractCircuitBreaker.State> state
    The current state of this circuit breaker.

- ## Constructor Details

  - ### AbstractCircuitBreaker

    public AbstractCircuitBreaker()
    Creates an `AbstractCircuitBreaker`. It also creates an internal `PropertyChangeSupport`.

- ## Method Details

  - ### isOpen

    protected static boolean isOpen(AbstractCircuitBreaker.State state)
    Converts the given state value to a boolean open property.
    Parameters:
      `state` - the state to be converted
    Returns:
      the boolean open flag

  - ### addChangeListener

    public void addChangeListener(PropertyChangeListener listener)
    Adds a change listener to this circuit breaker. This listener is notified whenever the state of this circuit breaker changes. If the listener is null, it is silently ignored.
    Parameters:
      `listener` - the listener to be added

  - ### changeState

    protected void changeState(AbstractCircuitBreaker.State newState)
    Changes the internal state of this circuit breaker. If there is actually a change of the state value, all registered change listeners are notified.
    Parameters:
      `newState` - the new state to be set

  - ### checkState

    public abstract boolean checkState()
    Checks the state of this circuit breaker and changes it if necessary. The return value indicates whether the circuit breaker is now in state closed; a value of true typically means that the current operation can continue.
    Specified by:
      `checkState` in interface `CircuitBreaker<T>`
    Returns:
      true if the circuit breaker is now closed; false otherwise.

  - ### close

    public void close()
    Closes this circuit breaker. Its state is changed to closed. If this circuit breaker is already closed, this method has no effect.
    Specified by:
      `close` in interface `CircuitBreaker<T>`

  - ### incrementAndCheckState

    public abstract boolean incrementAndCheckState(T increment)
    Increments the monitored value and performs a check of the current state of this circuit breaker. This method works like `CircuitBreaker.checkState()`, but the monitored value is incremented before the state check is performed.
    Specified by:
      `incrementAndCheckState` in interface `CircuitBreaker<T>`
    Parameters:
      `increment` - value to increment in the monitored value of the circuit breaker
    Returns:
      true if the circuit breaker is now closed; false otherwise

  - ### isClosed

    public boolean isClosed()
    Tests the current closed state of this circuit breaker. A return value of true means that the circuit breaker is currently closed. This means that everything is okay with the monitored subsystem.
    Specified by:
      `isClosed` in interface `CircuitBreaker<T>`
    Returns:
      the current closed state of this circuit breaker.

  - ### isOpen

    public boolean isOpen()
    Tests the current open state of this circuit breaker. A return value of true means that the circuit breaker is currently open indicating a problem in the monitored subsystem.
    Specified by:
      `isOpen` in interface `CircuitBreaker<T>`
    Returns:
      the current open state of this circuit breaker.

  - ### open

    public void open()
    Opens this circuit breaker. Its state is changed to open. Depending on a concrete implementation, it may close itself again if the monitored subsystem becomes available. If this circuit breaker is already open, this method has no effect.
    Specified by:
      `open` in interface `CircuitBreaker<T>`

  - ### removeChangeListener

    public void removeChangeListener(PropertyChangeListener listener)
    Removes the specified change listener from this circuit breaker.
    Parameters:
      `listener` - the listener to be removed