@Override public void addApplicationListener(ApplicationListener<?> listener) { Assert.notNull(listener, "ApplicationListener must not be null"); if (this.applicationEventMulticaster != null) { this.applicationEventMulticaster.addApplicationListener(listener); } this.applicationListeners.add(listener); }
public static void removeEventListener(ListableBeanFactory applicationContext, ApplicationListener listener) { Map<String, ApplicationEventMulticaster> multicasters = applicationContext.getBeansOfType(ApplicationEventMulticaster.class); for (Map.Entry<String, ApplicationEventMulticaster> entry : multicasters.entrySet()) { entry.getValue().removeApplicationListener(listener); } }
/** * Add beans that implement ApplicationListener as listeners. * Doesn't affect other listeners, which can be added without being beans. */ protected void registerListeners() { // Register statically specified listeners first. for (ApplicationListener<?> listener : getApplicationListeners()) { getApplicationEventMulticaster().addApplicationListener(listener); } // Do not initialize FactoryBeans here: We need to leave all regular beans // uninitialized to let post-processors apply to them! String[] listenerBeanNames = getBeanNamesForType(ApplicationListener.class, true, false); for (String listenerBeanName : listenerBeanNames) { getApplicationEventMulticaster().addApplicationListenerBean(listenerBeanName); } // Publish early application events now that we finally have a multicaster... Set<ApplicationEvent> earlyEventsToProcess = this.earlyApplicationEvents; this.earlyApplicationEvents = null; if (earlyEventsToProcess != null) { for (ApplicationEvent earlyEvent : earlyEventsToProcess) { getApplicationEventMulticaster().multicastEvent(earlyEvent); } } }
@Override public void postProcessBeforeDestruction(Object bean, String beanName) { if (bean instanceof ApplicationListener) { try { ApplicationEventMulticaster multicaster = this.applicationContext.getApplicationEventMulticaster(); multicaster.removeApplicationListener((ApplicationListener<?>) bean); multicaster.removeApplicationListenerBean(beanName); } catch (IllegalStateException ex) { // ApplicationEventMulticaster not initialized yet - no need to remove a listener } } }
getApplicationEventMulticaster().multicastEvent(applicationEvent, eventType);
getApplicationEventMulticaster().multicastEvent(applicationEvent, eventType);
@Override public void postProcessBeforeDestruction(Object bean, String beanName) { if (bean instanceof ApplicationListener) { try { ApplicationEventMulticaster multicaster = this.applicationContext.getApplicationEventMulticaster(); multicaster.removeApplicationListener((ApplicationListener<?>) bean); multicaster.removeApplicationListenerBean(beanName); } catch (IllegalStateException ex) { // ApplicationEventMulticaster not initialized yet - no need to remove a listener } } }
@Override public void addApplicationListener(ApplicationListener<?> listener) { Assert.notNull(listener, "ApplicationListener must not be null"); if (this.applicationEventMulticaster != null) { this.applicationEventMulticaster.addApplicationListener(listener); } this.applicationListeners.add(listener); }
/** * Add beans that implement ApplicationListener as listeners. * Doesn't affect other listeners, which can be added without being beans. */ protected void registerListeners() { // Register statically specified listeners first. for (ApplicationListener<?> listener : getApplicationListeners()) { getApplicationEventMulticaster().addApplicationListener(listener); } // Do not initialize FactoryBeans here: We need to leave all regular beans // uninitialized to let post-processors apply to them! String[] listenerBeanNames = getBeanNamesForType(ApplicationListener.class, true, false); for (String listenerBeanName : listenerBeanNames) { getApplicationEventMulticaster().addApplicationListenerBean(listenerBeanName); } // Publish early application events now that we finally have a multicaster... Set<ApplicationEvent> earlyEventsToProcess = this.earlyApplicationEvents; this.earlyApplicationEvents = null; if (earlyEventsToProcess != null) { for (ApplicationEvent earlyEvent : earlyEventsToProcess) { getApplicationEventMulticaster().multicastEvent(earlyEvent); } } }
@Override public void publishEvent(ApplicationEvent event) { multicaster.multicastEvent(event); }
public void removeApplicationListener(ApplicationListener<?> listener) { eventMulticaster.removeApplicationListener(listener); }
@Override public void postProcessBeforeDestruction(Object bean, String beanName) throws BeansException { if (bean instanceof ApplicationListener) { ApplicationListener<?> listener = (ApplicationListener<?>) bean; ApplicationEventMulticaster applicationEventMulticaster = getApplicationEventMulticaster(); if (applicationEventMulticaster != null) { applicationEventMulticaster.removeApplicationListener(listener); applicationEventMulticaster.removeApplicationListenerBean(beanName); } } }
public void registerApplicationListener(ApplicationListener<?> listener) { eventMulticaster.addApplicationListener(listener); }
/** * Add beans that implement ApplicationListener as listeners. * Doesn't affect other listeners, which can be added without being beans. */ protected void registerListeners() { // Register statically specified listeners first. for (ApplicationListener<?> listener : getApplicationListeners()) { getApplicationEventMulticaster().addApplicationListener(listener); } // Do not initialize FactoryBeans here: We need to leave all regular beans // uninitialized to let post-processors apply to them! String[] listenerBeanNames = getBeanNamesForType(ApplicationListener.class, true, false); for (String listenerBeanName : listenerBeanNames) { getApplicationEventMulticaster().addApplicationListenerBean(listenerBeanName); } // Publish early application events now that we finally have a multicaster... Set<ApplicationEvent> earlyEventsToProcess = this.earlyApplicationEvents; this.earlyApplicationEvents = null; if (earlyEventsToProcess != null) { for (ApplicationEvent earlyEvent : earlyEventsToProcess) { getApplicationEventMulticaster().multicastEvent(earlyEvent); } } }
public void multicastEvent(OsgiBundleApplicationContextEvent osgiEvent) { delegatedMulticaster.multicastEvent(osgiEvent); }
ApplicationEventMulticaster aem = context.getBean(AbstractApplicationContext.APPLICATION_EVENT_MULTICASTER_BEAN_NAME, ApplicationEventMulticaster.class); aem.removeApplicationListener(appListener);
@Override public void postProcessBeforeDestruction(Object bean, String beanName) { if (bean instanceof ApplicationListener) { try { ApplicationEventMulticaster multicaster = this.applicationContext.getApplicationEventMulticaster(); multicaster.removeApplicationListener((ApplicationListener<?>) bean); multicaster.removeApplicationListenerBean(beanName); } catch (IllegalStateException ex) { // ApplicationEventMulticaster not initialized yet - no need to remove a listener } } }
/** * Set the list of event types (classes that extend ApplicationEvent) that * this adapter should send to the message channel. By default, all event * types will be sent. * In addition, this method re-registers the current instance as a {@link GenericApplicationListener} * with the {@link ApplicationEventMulticaster} which clears the listener cache. The cache will be * refreshed on the next appropriate {@link ApplicationEvent}. * * @param eventTypes The event types. * @see ApplicationEventMulticaster#addApplicationListener * @see #supportsEventType */ public final void setEventTypes(Class<?>... eventTypes) { Assert.notNull(eventTypes, "'eventTypes' must not be null"); Set<ResolvableType> eventSet = new HashSet<ResolvableType>(eventTypes.length); for (Class<?> eventType : eventTypes) { if (eventType != null) { eventSet.add(ResolvableType.forClass(eventType)); } } this.eventTypes = (eventSet.size() > 0 ? eventSet : null); if (this.applicationEventMulticaster != null) { this.applicationEventMulticaster.addApplicationListener(this); } }
synchronized (applicationEventNotifier) { contextRefreshedEvent = (ContextRefreshedEvent) event; applicationEventNotifier.multicastEvent(event);
/** * Un-registers the Spring ApplicationListener from this SpringContextBootstrappingInitializer in order to stop * receiving ApplicationEvents on Spring context refreshes. * * @param <T> the Class type of the Spring ApplicationListener. * @param listener the ApplicationListener to unregister from receiving ContextRefreshedEvents by this * SpringContextBootstrappingInitializer. * @return the reference to the ApplicationListener for method call chaining purposes. * @see #register(org.springframework.context.ApplicationListener) * @see org.springframework.context.ApplicationListener * @see org.springframework.context.event.ContextRefreshedEvent * @see org.springframework.context.event.SimpleApplicationEventMulticaster * #removeApplicationListener(org.springframework.context.ApplicationListener) */ public static <T extends ApplicationListener<ContextRefreshedEvent>> T unregister(T listener) { synchronized (applicationEventNotifier) { applicationEventNotifier.removeApplicationListener(listener); } return listener; }