public interface HippoEventBus
Listeners can be registered using the whiteboard pattern. Methods in the listener class hierarchy,
annotated with the Subscribe
annotation will be invoked when events of a suitable type are dispatched.
(see the Subscribe
documentation for details)
Example :
//
MyObject() {
... initialization
// register as a listener using the whiteboard pattern
HippoServiceRegistry.registerService(this, HippoEventBus.class);
}
// implement a HippoEvent receiver method and annotate it with 'Subscribe'
// Note that the method with the annotation MUST be public
@Subscribe
public void processHippoEvent(HippoEvent<?> event) {
System.out.println(event);
}
If you are only interested in HippoEvent
s, you can implement the HippoEventListener
instead. Then, you
also don't need to annotate the onEvent. For example:
// get the eventBus
HippoServiceRegistry.registerService(new HippoEventListener() {
// implement the onEvent method
// Note that the method with the annotation MUST be public
public void onEvent(HippoEvent<?> event) {
System.out.println(event);
}
}, HippoEventBus.class);
Modifier and Type | Method and Description |
---|---|
void |
post(Object event)
Publish an event to registered listeners.
|
void |
register(Object listener)
Deprecated.
|
void |
unregister(Object listener)
Deprecated.
use the whiteboard pattern instead
|
@Deprecated void register(Object listener)
listener
- @Deprecated void unregister(Object listener)
listener
- void post(Object event)
event
- Copyright © 2012–2015 Hippo B.V. (http://www.onehippo.com). All rights reserved.