|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.ekuefler.supereventbus.EventBus
public class EventBus
An event bus implementation for GWT that is significantly more powerful than the built-in
EventBus
. Features provided by this event bus over
the built-in one include the following:
Subscribe
and are all automatically registered in
a single bind step.
GwtEvent
and implement associated boilerplate. With
SuperEventBus, any object can be fired on the bus, even primitive types.
Object
to
handle all events fired by the system. It is also possible to handle multiple events of unrelated
types with the same handler method (see below).
WithPriority
annotation to force some handlers to be
run before other handlers.
When
annotation to conditionally disable certain handlers, based on either properties of the handler
or based on the event being handled.
MultiEvent
class and
EventTypes
annotation, which allow events of
several specified types to be wrapped and passed to a single method.
DeadEvent
whenever an event is fired that has no handlers. The
application can subscribe to this event in order to log it or report an error.
EventRegistration
interface for the type of the handler like this:
interface MyRegistration extends EventRegistration<TestOwner> {}This is necessary so that the GWT compiler can generate dispatch code specific to the handler class - you should not implement this interface yourself. Once this interface is defined, you can register an object to listen on the event bus like this:
eventBus.register(this, MyRegistration.class);This will cause all
Subscribe
-annotated methods on the current object to be invoked
whenever an appropriate event is fired. Methods annotated with Subscribe
must take a
single argument, which specifies the type of event to handle. An event can be any Java object,
and a handler for a given type will be invoked whenever an object of that type or its subclasses
is posted on the event bus. To post an object to an event bus, simply call
eventBus.post(new MyEvent("some data"));
Constructor Summary | |
---|---|
EventBus()
Creates a new event bus. |
Method Summary | ||
---|---|---|
void |
addExceptionHandler(ExceptionHandler exceptionHandler)
Adds an exception handler to be notified whenever an exception occurs while dispatching an event. |
|
|
post(T event)
Posts the given event to all handlers registered on this event bus. |
|
|
register(T owner,
Class<? extends EventRegistration<T>> registrationClass)
Registers all Subscribe -annotated in the given object on the event bus. |
|
void |
unregister(Object owner)
Unregisters all event handlers on the given object. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public EventBus()
GWT.log(java.lang.String)
. In prod mode, exceptions are silently ignored unless a handler
is added via addExceptionHandler(com.ekuefler.supereventbus.ExceptionHandler)
.
Method Detail |
---|
public <T> void post(T event)
addExceptionHandler(ExceptionHandler)
.
event
- event object to post to all handlerspublic <T> void register(T owner, Class<? extends EventRegistration<T>> registrationClass)
Subscribe
-annotated in the given object on the event bus. Any methods
annotated with Subscribe
must take a single argument specifying the event to handle.
After an object has been registered, whenever an event is posted on the event bus via
post(T)
, all handlers on that object for that event's type or its supertypes will be
invoked with that event.
owner
- object to scan for Subscribe
-annotated methods to registerregistrationClass
- the class object of a registration interface for the given ownerpublic void unregister(Object owner)
Subscribe
-
annotated methods on that object will never be invoked when an event is posted (unless the
object is registered again). This given object must have already been registered on the event
bus.
owner
- object whose handlers should be disabled. Must already have been registered via a
call to register(T, java.lang.Class extends com.ekuefler.supereventbus.EventRegistration>)
.
IllegalArgumentException
- if the given object was never registered on this event buspublic void addExceptionHandler(ExceptionHandler exceptionHandler)
EventBusException
and posted to every exception handler.
exceptionHandler
- handler to be notified when exceptions occur
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |