Package com.linecorp.armeria.common.util
Class AbstractListenable<T>
java.lang.Object
com.linecorp.armeria.common.util.AbstractListenable<T>
- All Implemented Interfaces:
Listenable<T>
- Direct Known Subclasses:
DynamicEndpointGroup
,SettableHealthChecker
A skeletal
Listenable
implementation.-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionfinal void
addListener
(Consumer<? super T> listener) Adds aConsumer
that will be invoked when aListenable
changes its value.final void
addListener
(Consumer<? super T> listener, boolean notifyLatestValue) Adds aConsumer
that will be invoked when aListenable
changes its value.protected T
Returns the latest value notified before.protected final void
notifyListeners
(T latestValue) Notify the new value changes to the listeners added viaaddListener(Consumer)
.final void
removeListener
(Consumer<?> listener) Remove a listener.
-
Constructor Details
-
AbstractListenable
public AbstractListenable()
-
-
Method Details
-
notifyListeners
Notify the new value changes to the listeners added viaaddListener(Consumer)
. -
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
Description copied from interface:Listenable
Adds aConsumer
that will be invoked when aListenable
changes its value.- Specified by:
addListener
in interfaceListenable<T>
-
addListener
Adds aConsumer
that will be invoked when aListenable
changes its value. IfnotifyLatestValue
is set to true and thelatestValue()
is not null, theConsumer
will be invoked immediately with thelatestValue()
. -
removeListener
Description copied from interface:Listenable
Remove a listener.- Specified by:
removeListener
in interfaceListenable<T>
-