/** * Initialize the ApplicationEventMulticaster. * Uses SimpleApplicationEventMulticaster if none defined in the context. * @see org.springframework.context.event.SimpleApplicationEventMulticaster */ protected void initApplicationEventMulticaster() { ConfigurableListableBeanFactory beanFactory = getBeanFactory(); if (beanFactory.containsLocalBean(APPLICATION_EVENT_MULTICASTER_BEAN_NAME)) { this.applicationEventMulticaster = beanFactory.getBean(APPLICATION_EVENT_MULTICASTER_BEAN_NAME, ApplicationEventMulticaster.class); if (logger.isDebugEnabled()) { logger.debug("Using ApplicationEventMulticaster [" + this.applicationEventMulticaster + "]"); } } else { this.applicationEventMulticaster = new SimpleApplicationEventMulticaster(beanFactory); beanFactory.registerSingleton(APPLICATION_EVENT_MULTICASTER_BEAN_NAME, this.applicationEventMulticaster); if (logger.isDebugEnabled()) { logger.debug("Unable to locate ApplicationEventMulticaster with name '" + APPLICATION_EVENT_MULTICASTER_BEAN_NAME + "': using default [" + this.applicationEventMulticaster + "]"); } } }
@Override public void onApplicationEvent(ApplicationEvent event) { if (event instanceof ApplicationEnvironmentPreparedEvent) { List<ApplicationListener<ApplicationEvent>> delegates = getListeners( ((ApplicationEnvironmentPreparedEvent) event).getEnvironment()); if (delegates.isEmpty()) { return; } this.multicaster = new SimpleApplicationEventMulticaster(); for (ApplicationListener<ApplicationEvent> listener : delegates) { this.multicaster.addApplicationListener(listener); } } if (this.multicaster != null) { this.multicaster.multicastEvent(event); } }
public void testApplicationEventNotification() throws Exception { TestAdvisor advisor = new TestAdvisor(); advisor.afterPropertiesSet(); Application.load(null); new Application(advisor); StaticApplicationContext applicationContext = new StaticApplicationContext(); Application.instance().setApplicationContext(applicationContext); applicationContext.registerSingleton( "eventMulticaster", SimpleApplicationEventMulticaster.class ); applicationContext.refresh(); advisor.setWindowCommandBarDefinitions( "org/springframework/richclient/config/app-lifecycle-test-ctx.xml"); // Fire up test..... advisor.testInit(); TestCommand cmd = (TestCommand)advisor.getBeanFactory().getBean("testCommand"); assertEquals("Command must be notified of refresh", 1, cmd.getCount()); advisor.onApplicationEvent(new ApplicationEvent(this) {}); assertEquals("Command must be notified", 2, cmd.getCount()); }
@Bean(name = "applicationEventMulticaster") public ApplicationEventMulticaster simpleApplicationEventMulticaster() { SimpleApplicationEventMulticaster eventMulticaster = new SimpleApplicationEventMulticaster(); taskExecutor = new ThreadPoolTaskExecutor(); taskExecutor.setThreadNamePrefix("asyncEventExecutor-"); taskExecutor.setCorePoolSize(4); taskExecutor.initialize(); eventMulticaster.setTaskExecutor(taskExecutor); return eventMulticaster; }
@Bean(name = "applicationEventMulticaster") public ApplicationEventMulticaster simpleApplicationEventMulticaster() { multicasterExecutor.initialize(); SimpleApplicationEventMulticaster eventMulticaster = new SimpleApplicationEventMulticaster(); eventMulticaster.setTaskExecutor(multicasterExecutor); return eventMulticaster; }
/** * A multicast (async) event publisher to replace the synchronous one used by Spring via the ApplicationContext. * * @param taskExecutor The task executor to use * @return The application event multicaster to use */ @Bean public ApplicationEventMulticaster asyncEventMulticaster(final TaskExecutor taskExecutor) { final SimpleApplicationEventMulticaster applicationEventMulticaster = new SimpleApplicationEventMulticaster(); applicationEventMulticaster.setTaskExecutor(taskExecutor); return applicationEventMulticaster; }
public EventPublishingRunListener(SpringApplication application, String[] args) { this.application = application; this.args = args; this.initialMulticaster = new SimpleApplicationEventMulticaster(); for (ApplicationListener<?> listener : application.getListeners()) { this.initialMulticaster.addApplicationListener(listener); } }
public EventPublishingRunListener(SpringApplication application, String[] args) { this.application = application; this.args = args; this.multicaster = new SimpleApplicationEventMulticaster(); for (ApplicationListener<?> listener : application.getListeners()) { this.multicaster.addApplicationListener(listener); } }
@Bean(name = AbstractApplicationContext.APPLICATION_EVENT_MULTICASTER_BEAN_NAME) SimpleApplicationEventMulticaster applicationEventMulticaster(final ApplicationEventFilter applicationEventFilter) { final SimpleApplicationEventMulticaster simpleApplicationEventMulticaster = new FilterEnabledApplicationEventPublisher( applicationEventFilter); simpleApplicationEventMulticaster.setTaskExecutor(asyncExecutor()); return simpleApplicationEventMulticaster; }
/** * Server internal event publisher that allows parallel event processing if * the event listener is marked as so. * * @return publisher bean */ @Bean(name = AbstractApplicationContext.APPLICATION_EVENT_MULTICASTER_BEAN_NAME) public ApplicationEventMulticaster applicationEventMulticaster() { final SimpleApplicationEventMulticaster simpleApplicationEventMulticaster = new TenantAwareApplicationEventPublisher( tenantAware, applicationEventFilter()); simpleApplicationEventMulticaster.setTaskExecutor(executor); return simpleApplicationEventMulticaster; }
private OsgiBundleApplicationContextEventMulticaster createDefaultEventMulticaster() { isMulticasterManagedInternally = true; return new OsgiBundleApplicationContextEventMulticasterAdapter(new SimpleApplicationEventMulticaster()); }
@Bean(name = "applicationEventMulticaster") public ApplicationEventMulticaster simpleApplicationEventMulticaster() { SimpleApplicationEventMulticaster eventMulticaster = new SimpleApplicationEventMulticaster(); eventMulticaster.setTaskExecutor(executor); return eventMulticaster; }
@Bean public SimpleApplicationEventMulticaster applicationEventMulticaster() { final SimpleApplicationEventMulticaster multicaster = new SimpleApplicationEventMulticaster(); multicaster.setTaskExecutor(new SimpleAsyncTaskExecutor()); return multicaster; }
@Bean(name = "applicationEventMulticaster") public ApplicationEventMulticaster simpleApplicationEventMulticaster() { SimpleApplicationEventMulticaster eventMulticaster = new SimpleApplicationEventMulticaster(); eventMulticaster.setTaskExecutor(new SimpleAsyncTaskExecutor()); return eventMulticaster; }
@Bean(name = AbstractApplicationContext.APPLICATION_EVENT_MULTICASTER_BEAN_NAME) public ApplicationEventMulticaster applicationEventMulticaster() { return spy(new SimpleApplicationEventMulticaster()); }
@Bean public SimpleApplicationEventMulticaster applicationEventMulticaster() { return new SimpleApplicationEventMulticaster(); }