@Override public void publishEvent(final Object payload) { eventBus.publish(this.sender, payload); } }
/** * The constructor automatically subscribes to event bus events. * * @param view <em>View</em> * @param eventBus Vaadin even bus */ public Presenter(T view, EventBus eventBus) { Assert.notNull(view); Assert.notNull(eventBus); this.view = view; this.eventBus = eventBus; eventBus.subscribe(this); }
/** * Gets the scope of the event. * * @return the scope, never {@code null}. */ public EventScope getScope() { return eventBus.getScope(); }
@PreDestroy void destroy() { logger.trace("Destroying event bus [{}] and removing all listeners", this); listeners.clear(); if (parentEventBus != null) { parentEventBus.unsubscribe(parentListener); } }
@PreDestroy void destroy() { logger.trace("Destroying event bus [{}] and removing all listeners", this); listeners.clear(); if (parentEventBus != null) { parentEventBus.unsubscribe(parentListener); } }
@Override public void publishEvent(final ApplicationEvent payload) { eventBus.publish(this.sender, payload); }
@PreDestroy // It's good manners to do this, even though we should be automatically unsubscribed // when the UI is garbage collected void destroy() { getEventBus().unsubscribe(this); }
/** * @param scope the scope of the events that this event bus handles. * @param parentEventBus the parent event bus to use, may be {@code null}; */ public ScopedEventBus(EventScope scope, EventBus parentEventBus) { eventScope = scope; this.parentEventBus = parentEventBus; if (parentEventBus != null) { if (AopUtils.isJdkDynamicProxy(parentEventBus)) { logger.debug("Parent event bus [{}] is proxied, trying to get the real EventBus instance", parentEventBus); try { this.parentEventBus = (EventBus) ((Advised) parentEventBus).getTargetSource().getTarget(); } catch (Exception e) { logger.error("Could not get target EventBus from proxy", e); throw new RuntimeException("Could not get parent event bus", e); } } logger.debug("Using parent event bus [{}]", this.parentEventBus); this.parentEventBus.subscribe(parentListener); } }
/** * Gets the scope of the event. * * @return the scope, never {@code null}. */ public EventScope getScope() { return eventBus.getScope(); }
@Override public void onApplicationEvent(ApplicationEvent event) { logger.debug(String.format("Propagating application event [%s] to event bus [%s]", event, this)); eventBus.publish(event.getSource(), event); } }
@PreDestroy void destroy() { logger.trace("Destroying event bus [{}] and removing all listeners", this); listeners.clear(); if (parentEventBus != null) { parentEventBus.unsubscribe(parentListener); } }
/** * @param scope the scope of the events that this event bus handles. * @param parentEventBus the parent event bus to use, may be {@code null}; */ public ScopedEventBus(EventScope scope, EventBus parentEventBus) { eventScope = scope; this.parentEventBus = parentEventBus; if (parentEventBus != null) { if (AopUtils.isJdkDynamicProxy(parentEventBus)) { logger.debug("Parent event bus [{}] is proxied, trying to get the real EventBus instance", parentEventBus); try { this.parentEventBus = (EventBus) ((Advised) parentEventBus).getTargetSource().getTarget(); } catch (Exception e) { logger.error("Could not get target EventBus from proxy", e); throw new RuntimeException("Could not get parent event bus", e); } } logger.debug("Using parent event bus [{}]", this.parentEventBus); this.parentEventBus.subscribe(parentListener); } }
/** * Gets the scope of the event. * * @return the scope, never {@code null}. */ public EventScope getScope() { return eventBus.getScope(); }
@Override public void onApplicationEvent(ApplicationEvent event) { logger.debug(String.format("Propagating application event [%s] to event bus [%s]", event, this)); eventBus.publish(event.getSource(), event); } }
/** * @param scope the scope of the events that this event bus handles. * @param parentEventBus the parent event bus to use, may be {@code null}; */ public ScopedEventBus(EventScope scope, EventBus parentEventBus) { eventScope = scope; this.parentEventBus = parentEventBus; if (parentEventBus != null) { if (AopUtils.isJdkDynamicProxy(parentEventBus)) { logger.debug("Parent event bus [{}] is proxied, trying to get the real EventBus instance", parentEventBus); try { this.parentEventBus = (EventBus) ((Advised) parentEventBus).getTargetSource().getTarget(); } catch (Exception e) { logger.error("Could not get target EventBus from proxy", e); throw new RuntimeException("Could not get parent event bus", e); } } logger.debug("Using parent event bus [{}]", this.parentEventBus); this.parentEventBus.subscribe(parentListener); } }
@Override public void onApplicationEvent(ApplicationEvent event) { logger.debug(String.format("Propagating application event [%s] to event bus [%s]", event, this)); eventBus.publish(event.getSource(), event); } }
@Override public <T> void publish(EventScope scope, Object sender, T payload) throws UnsupportedOperationException { logger.debug("Trying to publish payload [{}] from sender [{}] using scope [{}] on event bus [{}]", payload, sender, scope, this); if (eventScope.equals(scope)) { publish(sender, payload); } else if (parentEventBus != null) { parentEventBus.publish(scope, sender, payload); } else { logger.warn("Could not publish payload with scope [{}] on event bus [{}]", scope, this); throw new UnsupportedOperationException("Could not publish event with scope " + scope); } }
@Override public <T> void publish(EventScope scope, String topic, Object sender, T payload) throws UnsupportedOperationException { logger.debug("Trying to publish payload [{}] from sender [{}] using scope [{}] on event bus [{}] in topic [{}]", payload, sender, scope, this, topic); if (eventScope.equals(scope)) { publish(topic, sender, payload); } else if (parentEventBus != null) { parentEventBus.publish(scope, topic, sender, payload); } else { logger.warn("Could not publish payload with scope [{}] on event bus [{}]", scope, this); throw new UnsupportedOperationException("Could not publish event with scope " + scope); } }
@Override public <T> void publish(EventScope scope, String topic, Object sender, T payload) throws UnsupportedOperationException { logger.debug("Trying to publish payload [{}] from sender [{}] using scope [{}] on event bus [{}] in topic [{}]", payload, sender, scope, this, topic); if (eventScope.equals(scope)) { publish(topic, sender, payload); } else if (parentEventBus != null) { parentEventBus.publish(scope, topic, sender, payload); } else { logger.warn("Could not publish payload with scope [{}] on event bus [{}]", scope, this); throw new UnsupportedOperationException("Could not publish event with scope " + scope); } }