use of org.springframework.context.event.SimpleApplicationEventMulticaster in project SpringBoot-Learning by LuoLiangDSGA.
the class AsynchronousSpringEventConfig method simpleApplicationEventMulticaster.
@Bean(name = "applicationEventMulticaster")
public ApplicationEventMulticaster simpleApplicationEventMulticaster() {
SimpleApplicationEventMulticaster eventMulticaster = new SimpleApplicationEventMulticaster();
eventMulticaster.setTaskExecutor(new SimpleAsyncTaskExecutor());
return eventMulticaster;
}
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
assertThat(message1).isNotNull();
assertThat(message1.getPayload().toString().contains("org.springframework.integration.test.util.TestUtils$TestApplicationContext")).isTrue();
adapter.onApplicationEvent(new TestApplicationEvent1());
adapter.onApplicationEvent(new TestApplicationEvent2());
Message<?> message2 = channel.receive(20);
assertThat(message2).isNotNull();
assertThat(message2.getPayload()).isEqualTo("received: event1");
Message<?> message3 = channel.receive(20);
assertThat(message3).isNotNull();
assertThat(message3.getPayload()).isEqualTo("received: event2");
ctx.close();
}
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")) {
assertThat(taskExecutor.getClass()).isEqualTo(SyncTaskExecutor.class);
} else {
assertThat(taskExecutor).isNull();
}
context.close();
}
use of org.springframework.context.event.SimpleApplicationEventMulticaster in project spring-boot by spring-projects.
the class DelegatingApplicationListener method onApplicationEvent.
@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);
}
}
use of org.springframework.context.event.SimpleApplicationEventMulticaster in project metacat by Netflix.
the class CommonServerConfig method applicationEventMulticaster.
/**
* 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 applicationEventMulticaster(final TaskExecutor taskExecutor) {
final SimpleApplicationEventMulticaster applicationEventMulticaster = new SimpleApplicationEventMulticaster();
applicationEventMulticaster.setTaskExecutor(taskExecutor);
return applicationEventMulticaster;
}
Aggregations