| <E extends SciJavaEvent> List<EventSubscriber<E>> |
getSubscribers(Class<E> c)
Gets a list of all subscribers to the given event class (and subclasses
thereof).
|
| <E extends SciJavaEvent> void |
publish(E e)
Publishes the given event immediately, reporting it to all subscribers.
|
| <E extends SciJavaEvent> void |
publishLater(E e)
Queues the given event for publication, typically on a separate thread
(called the "event dispatch thread").
|
| List<EventSubscriber<?>> | subscribe(Object o)
Subscribes all of the given object's @EventHandler annotated
methods.
|
| void | unsubscribe(Collection<EventSubscriber<?>> subscribers)
Removes all the given subscribers; they will no longer be notified when
events are published.
|
Note that with publish(E), in the case of multiple events published in a chain to multiple subscribers, the delivery order will resemble that of a stack. For example:
Note that with publishLater(E), in the case of multiple events published in a chain to multiple subscribers, the delivery order will resemble that of a queue. For example:
This allows a single class to subscribe to multiple types of events by implementing multiple event handling methods and annotating each one with the EventHandler annotation.
Note that it is not necessary to store a copy of the event subscribers (because the event service is expected to hold a weak mapping between the event handler object and the subscribers) unless the subscribers need to be unsubscribed explicitly.
Most users will want to extend AbstractContextual, or call Context.inject(Object), instead of subscribing to the event service explicitly.
Copyright © 2015–2022 SciJava. All rights reserved.