use of org.springframework.context.event.SimpleApplicationEventMulticaster in project spring-framework by spring-projects.
the class AbstractApplicationContext method initApplicationEventMulticaster.
/**
* 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 + "]");
}
}
}
use of org.springframework.context.event.SimpleApplicationEventMulticaster in project metacat by Netflix.
the class CommonServerConfig method asyncEventMulticaster.
/**
* 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;
}
use of org.springframework.context.event.SimpleApplicationEventMulticaster in project spring-integration by spring-projects.
the class MessageBusParserTests method testMulticasterIsSyncByDefault.
@Test
public void testMulticasterIsSyncByDefault() {
ConfigurableApplicationContext context = new ClassPathXmlApplicationContext("messageBusWithDefaults.xml", this.getClass());
SimpleApplicationEventMulticaster multicaster = (SimpleApplicationEventMulticaster) context.getBean(AbstractApplicationContext.APPLICATION_EVENT_MULTICASTER_BEAN_NAME);
DirectFieldAccessor accessor = new DirectFieldAccessor(multicaster);
Object taskExecutor = accessor.getPropertyValue("taskExecutor");
if (SpringVersion.getVersion().startsWith("2")) {
assertEquals(SyncTaskExecutor.class, taskExecutor.getClass());
} else {
assertNull(taskExecutor);
}
context.close();
}
use of org.springframework.context.event.SimpleApplicationEventMulticaster in project spring-integration by spring-projects.
the class ApplicationEventListeningMessageProducerTests method payloadExpressionEvaluatedAgainstApplicationEvent.
@Test
public void payloadExpressionEvaluatedAgainstApplicationEvent() {
QueueChannel channel = new QueueChannel();
ApplicationEventListeningMessageProducer adapter = new ApplicationEventListeningMessageProducer();
adapter.setPayloadExpression(PARSER.parseExpression("'received: ' + source"));
adapter.setOutputChannel(channel);
GenericApplicationContext ctx = TestUtils.createTestApplicationContext();
ConfigurableListableBeanFactory beanFactory = ctx.getBeanFactory();
beanFactory.registerSingleton(AbstractApplicationContext.APPLICATION_EVENT_MULTICASTER_BEAN_NAME, new SimpleApplicationEventMulticaster(beanFactory));
adapter.setBeanFactory(beanFactory);
beanFactory.registerSingleton("testListenerMessageProducer", adapter);
adapter.afterPropertiesSet();
ctx.refresh();
Message<?> message1 = channel.receive(0);
// ContextRefreshedEvent
assertNotNull(message1);
assertTrue(message1.getPayload().toString().contains("org.springframework.integration.test.util.TestUtils$TestApplicationContext"));
adapter.onApplicationEvent(new TestApplicationEvent1());
adapter.onApplicationEvent(new TestApplicationEvent2());
Message<?> message2 = channel.receive(20);
assertNotNull(message2);
assertEquals("received: event1", message2.getPayload());
Message<?> message3 = channel.receive(20);
assertNotNull(message3);
assertEquals("received: event2", message3.getPayload());
}
use of org.springframework.context.event.SimpleApplicationEventMulticaster in project spring-boot by spring-projects.
the class LoggingApplicationListenerTests method multicastEvent.
private void multicastEvent(ApplicationListener<?> listener, ApplicationEvent event) {
SimpleApplicationEventMulticaster multicaster = new SimpleApplicationEventMulticaster();
multicaster.addApplicationListener(listener);
multicaster.multicastEvent(event);
}
Aggregations