Interface Channel<T>

Type Parameters:
T - the type of the state property
All Known Implementing Classes:
AppenderChannel

public interface Channel<T>
A Channel is a mechanism used to maintain a state property.

A Channel is associated with a key and a value. The Channel is updated by calling the update(String, Object, Object) method. The update operation is applied to the channel's value.

The Channel may be initialized with a default value. This default value is provided by a Supplier. The getDefault() method returns an optional containing the default supplier.

The Channel may also be associated with a Reducer. The Reducer is a function that combines the current value of the channel with a new value and returns the updated value.

The update(String, Object, Object) method updates the channel's value with the provided key, old value and new value. The update operation is applied to the channel's value. If the channel is not initialized, the default value is used. If the channel is initialized, the reducer is used to compute the new value.

  • Method Details

    • of

      static <T> Channel<T> of(Supplier<T> defaultProvider)
    • of

      static <T> Channel<T> of(Reducer<T> reducer)
    • of

      static <T> Channel<T> of(Reducer<T> reducer, Supplier<T> defaultProvider)
    • getReducer

      Optional<Reducer<T>> getReducer()
      The Reducer, if provided, is invoked for each state property to compute value.
      Returns:
      An optional containing the reducer, if it exists.
    • getDefault

      Optional<Supplier<T>> getDefault()
      a Supplier that provide a default value. The result must be mutable.
      Returns:
      an Optional containing the default Supplier
    • update

      default Object update(String key, Object oldValue, Object newValue)
      Update the state property with the given key and returns the new value.
      Parameters:
      key - the key of the state property to be updated
      oldValue - the current value of the state property
      newValue - the new value to be set
      Returns:
      the new value of the state property