|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.scijava.AbstractContextual
org.scijava.plugin.AbstractRichPlugin
org.scijava.service.AbstractService
org.scijava.event.DefaultEventService
public class DefaultEventService
Default service for publishing and subscribing to SciJava events.
| Field Summary | |
|---|---|
static double |
PRIORITY
The default event service's priority. |
| Constructor Summary | |
|---|---|
DefaultEventService()
|
|
| Method Summary | ||
|---|---|---|
void |
dispose()
Performs any needed cleanup of the object's services, in preparation for the object being retired (e.g., to make garbage collection possible). |
|
|
getSubscribers(Class<E> c)
Gets a list of all subscribers to the given event class (and subclasses thereof). |
|
void |
initialize()
Performs any needed initialization when the service is first loaded. |
|
|
publish(E e)
Publishes the given event immediately, reporting it to all subscribers. |
|
|
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. |
|
| Methods inherited from class org.scijava.service.AbstractService |
|---|
getContext, registerEventHandlers, setContext, toString |
| Methods inherited from class org.scijava.plugin.AbstractRichPlugin |
|---|
compareTo, getInfo, getPriority, setInfo, setPriority |
| Methods inherited from class org.scijava.AbstractContextual |
|---|
context |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface org.scijava.service.Service |
|---|
registerEventHandlers |
| Methods inherited from interface org.scijava.Contextual |
|---|
context, getContext, setContext |
| Methods inherited from interface org.scijava.Prioritized |
|---|
getPriority, setPriority |
| Methods inherited from interface java.lang.Comparable |
|---|
compareTo |
| Methods inherited from interface org.scijava.plugin.HasPluginInfo |
|---|
getInfo, setInfo |
| Field Detail |
|---|
public static final double PRIORITY
Alternative event service implementations that wish to prioritize
themselves above this one can still ensure preferential usage via
priority = DefaultEventService.PRIORITY + 1 or similar.
| Constructor Detail |
|---|
public DefaultEventService()
| Method Detail |
|---|
public <E extends SciJavaEvent> void publish(E e)
EventService
Note that with EventService.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:
ModulesUpdatedEvent is published with
EventService.publish(E).DefaultMenuService receives the event and
handles it, publishing MenusUpdatedEvent in
response.ModulesUpdatedEvent and
MenusUpdatedEvent will receive the latter
before the former.EventService.publish(E) depends on the thread from
which it is called: if called from a thread identified as a dispatch thread
by ThreadService.isDispatchThread(), it will
publish immediately; otherwise, it will be queued for publication on a
dispatch thread, and block the calling thread until publication is
complete. This means that a chain of events published with a mixture of
EventService.publish(E) and EventService.publishLater(E) may result in event delivery in
an unintuitive order.
publish in interface EventServicepublic <E extends SciJavaEvent> void publishLater(E e)
EventService
Note that with EventService.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:
ModulesUpdatedEvent is published with
EventService.publishLater(E).DefaultMenuService receives the event and
handles it, publishing MenusUpdatedEvent in
response.ModulesUpdatedEvent and
MenusUpdatedEvent will receive the former
first, since it was already queued by the time the latter was published.
publishLater in interface EventServicepublic List<EventSubscriber<?>> subscribe(Object o)
EventServiceEventHandler annotated
methods.
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.
subscribe in interface EventServiceo - the event handler object containing the EventHandler
annotated methods
EventSubscribers, weakly
subscribed to the event service.AbstractContextual,
Context.inject(Object)public void unsubscribe(Collection<EventSubscriber<?>> subscribers)
EventService
unsubscribe in interface EventServicepublic <E extends SciJavaEvent> List<EventSubscriber<E>> getSubscribers(Class<E> c)
EventService
getSubscribers in interface EventServicepublic void initialize()
Service
NB: This method is not intended to be called directly. It is called by
the service framework itself (specifically by the ServiceHelper)
when initializing the service. It should not be called a second time.
initialize in interface Serviceinitialize in class AbstractServicepublic void dispose()
Disposable
dispose in interface Disposabledispose in class AbstractService
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||