How the Event Bus Works
How the Event Bus Works
The event bus is general enough to be used in any application, not just those employing Data Pipeline's readers and writers. For example, you can use the event bus in your Swing, SWT, or Android apps. You can also use it in your web apps to send real-time updates to web users.
EventListener Interface
One big difference between this event bus and other implementations of the observer pattern is that it uses the same interface for both publishing and subscribing to events.
If an event publisher calls userAdded(User)
, that same method will be called sometime later (using a different thread) on all the event subscribers. There's no
need to a create separate UserEvent
class or call a notifyUserAdded(UserEvent)
method. Just call a method on your interface and have it propagate
automatically.
The only requirement is that your listener must be a Java interface for the event bus to use it.