Module it.rebirthproject.ufoeb
Annotation Interface Listen
This annotation must be applied to methods of registered listeners to
EventBus
. Those methods will be used by
the bus system as callbacks to notify listeners about new events of the requested type.
Method annotated with Listen
must be public, return nothing (void), and have exactly one parameter (the event).
Example:
Class MagazineReader wants to receive MagazineNews events, so this could be a stub of the class:
public class MagazineReader {
@Listen
public void listenOnMagazineNews(MagazineNewsEvent event) {
System.out.println("A news arrived: " + event.getNews());
}
}
Class MagazineNewsEvent can be a simple POJO used to carry event's metadata, like this one:
public class MagazineNewsEvent {
private final String newsMessage;
public MagazineNewsEvent(String newsMessage) {
this.newsMessage = newsMessage;
}
public String getNews() {
return newsMessage;
}
}
The MagazineReader instance must be registered to EventBus
to receive news in his listenOnMagazineNews method.
public static void main(String ... args) {
MagazineReader magazineReader = new MagazineReader();
eventBus.register(magazineReader);
...
eventBus.post(new MagazineNewsEvent("Hello Readers!!! Something new just happened..."));
...
}
- See Also:
-
Optional Element Summary
Modifier and TypeOptional ElementDescriptionint
Listener priority to influence the order of event delivery.
-
Element Details
-
priority
int priorityListener priority to influence the order of event delivery. Higher priority listeners will receive events before others with a lower priority. The default priority is 0 (lowest priority).- Returns:
- the listener priority.
- Default:
- 0
-