The EventBus
class (found in the com.google.common.eventbus
package) is the focal point for establishing the publish/subscribe-programming paradigm with Guava. At a very high level, subscribers will register with EventBus
to be notified of particular events, and publishers will send events to EventBus
for distribution to interested subscribers. All the subscribers are notified serially, so it's important that any code performed in the event-handling method executes quickly.
Creating an EventBus
instance is accomplished by merely making a call to the EventBus
constructor:
EventBus eventBus = new EventBus();
We could also provide an optional string argument to create an identifier (for logging purposes) for EventBus
:
EventBus eventBus = new EventBus(TradeAccountEvent.class.getName());