/** * Populates {@link #eventBusImplementation} with the {@link #registeredSubscribers currently registered subscribers}. * * <p> * Guava event bus will throw an exception if attempt to unsubscribe any subscribers that were not subscribed. * It is therefore the responsibility of this service to remember which services were registered * at the start of the request, and to unregister precisely this same set of services at the end. * </p> * * <p> * That said, the Guava event bus is only ever instantiated once (it is in essence an application-scoped singleton), * and so once created it is not possible for any subscribers to be registered. For this reason, the * {@link #register(Object)} will throw an exception if any attempt is made to register once the event bus * has been instantiated. * </p> */ protected void setupEventBus() { if(eventBusImplementation != null) { return; } this.eventBusImplementation = newEventBus(); registeredSubscribers = getSubscribers(); for (Object subscriber : this.registeredSubscribers) { eventBusImplementation.register(subscriber); } }