资 源 简 介
events-on-fire
The repeated implementation of the listener pattern for Java is a boring task which cannot be easily abstracted. Events-On-Fire is a way to get rid of this. Events-On-Fire offers a simple mechanism to fire events across your application without the need for any configuration and without the danger of memory leaks.
A simple example
Imagine, you have some sort of mailbox that occasionally tends to receive mails and some narrators that like to read these mails.
Object mailbox = new MyMailbox(); // my producerObject narrator1 = new MyNarrator(); // one of my consumersObject narrator2 = new MyNarrator(); // another one of my consumers
First, implement an event handler in MyNarrator:
@EventHandlerpublic void handleEvent(Mail someMail) { // do fancy stuff here}
Then, bind the narrators to the mailbox:
Events.bind(mailbox, narrator1);Events.bind(mailbox, narrator2);