Class AbstractListenable<T>

java.lang.Object
com.linecorp.armeria.common.util.AbstractListenable<T>
All Implemented Interfaces:
Listenable<T>
Direct Known Subclasses:
DynamicEndpointGroup, SettableHealthChecker

public abstract class AbstractListenable<T> extends Object implements Listenable<T>
A skeletal Listenable implementation.
  • Constructor Details

    • AbstractListenable

      public AbstractListenable()
  • Method Details

    • notifyListeners

      protected final void notifyListeners(T latestValue)
      Notify the new value changes to the listeners added via addListener(Consumer).
    • latestValue

      @Nullable protected T latestValue()
      Returns the latest value notified before. null if the value has not been initialized yet or the implementation of this class cannot cache it.
    • addListener

      public final void addListener(Consumer<? super T> listener)
      Description copied from interface: Listenable
      Adds a Consumer that will be invoked when a Listenable changes its value.
      Specified by:
      addListener in interface Listenable<T>
    • addListener

      public final void addListener(Consumer<? super T> listener, boolean notifyLatestValue)
      Adds a Consumer that will be invoked when a Listenable changes its value. If notifyLatestValue is set to true and the latestValue() is not null, the Consumer will be invoked immediately with the latestValue().
    • removeListener

      public final void removeListener(Consumer<?> listener)
      Description copied from interface: Listenable
      Remove a listener.
      Specified by:
      removeListener in interface Listenable<T>