- Type Parameters:
T
- the type of data propagated with this event
An event class implementing Observer
.
Events are triggered with run()
or accept(Object)
, depending
on whether data should be propagated with the event.
Listeners are notified in the order they were added.
Note that both listeners and consumers are notified each time the event is
triggered, regardless of whether run()
or accept(Object)
is used.
Events provide access to their Observer
instance via observer()
, which can
be used to add listeners and consumers, but can not be used to trigger the event.
Unhandled exceptions occurring in a listener will prevent further listeners from being notified.
Event<Boolean> event = Event.event();
event.addListener(this::doSomething);
event.run();
event.addConsumer(this::onBoolean);
event.accept(true);
Observer<Boolean> observer = event.observer();
observer.addListener(this::doSomethingElse);
Listeners and Consumers can be added using a WeakReference
.
observer.addWeakListener(this::doSomethingElse);
observer.addWeakConsumer(this::onBoolean);
Any weak references that no longer refer to a listener/consumer instance are cleared when listeners or consumers are added or removed.
-
Method Summary
Methods inherited from interface is.codion.common.observable.Observer
addConsumer, addListener, addWeakConsumer, addWeakListener, removeConsumer, removeListener, removeWeakConsumer, removeWeakListener
-
Method Details
-
run
void run()Triggers this event. -
accept
Triggers this event. -
observer
- Returns:
- an observer notified each time this event occurs
-
event
Creates a newEvent
.- Type Parameters:
T
- the type of data propagated to listeners on event occurrence- Returns:
- a new Event
-