Search in sources :

Example 11 with SimpleApplicationEventMulticaster

use of org.springframework.context.event.SimpleApplicationEventMulticaster in project tutorials by eugenp.

the class AsynchronousSpringEventsConfig method simpleApplicationEventMulticaster.

@Bean(name = "applicationEventMulticaster")
public ApplicationEventMulticaster simpleApplicationEventMulticaster() {
    final SimpleApplicationEventMulticaster simpleApplicationEventMulticaster = new SimpleApplicationEventMulticaster();
    simpleApplicationEventMulticaster.setTaskExecutor(new SimpleAsyncTaskExecutor());
    return simpleApplicationEventMulticaster;
}
Also used : SimpleApplicationEventMulticaster(org.springframework.context.event.SimpleApplicationEventMulticaster) SimpleAsyncTaskExecutor(org.springframework.core.task.SimpleAsyncTaskExecutor) Bean(org.springframework.context.annotation.Bean)

Example 12 with SimpleApplicationEventMulticaster

use of org.springframework.context.event.SimpleApplicationEventMulticaster in project yaps-client by serdaroquai.

the class ApplicationConfig method simpleApplicationEventMulticaster.

// spring asynchronous event handling
@Bean(name = "applicationEventMulticaster")
public ApplicationEventMulticaster simpleApplicationEventMulticaster(Executor executor) {
    SimpleApplicationEventMulticaster eventMulticaster = new SimpleApplicationEventMulticaster();
    eventMulticaster.setTaskExecutor(executor);
    return eventMulticaster;
}
Also used : SimpleApplicationEventMulticaster(org.springframework.context.event.SimpleApplicationEventMulticaster) Bean(org.springframework.context.annotation.Bean)

Example 13 with SimpleApplicationEventMulticaster

use of org.springframework.context.event.SimpleApplicationEventMulticaster in project data-prep by Talend.

the class AsynchronousSpringEventConfiguration method simpleApplicationEventMulticaster.

@Bean(name = "applicationEventMulticaster")
public ApplicationEventMulticaster simpleApplicationEventMulticaster() {
    SimpleApplicationEventMulticaster eventMulticaster = new SimpleApplicationEventMulticaster();
    eventMulticaster.setTaskExecutor(new SimpleAsyncTaskExecutor());
    return eventMulticaster;
}
Also used : SimpleApplicationEventMulticaster(org.springframework.context.event.SimpleApplicationEventMulticaster) SimpleAsyncTaskExecutor(org.springframework.core.task.SimpleAsyncTaskExecutor) Bean(org.springframework.context.annotation.Bean)

Example 14 with SimpleApplicationEventMulticaster

use of org.springframework.context.event.SimpleApplicationEventMulticaster in project spring-integration by spring-projects.

the class MessageBusParserTests method testAsyncMulticasterExplicitlySetToFalse.

@Test
public void testAsyncMulticasterExplicitlySetToFalse() throws Exception {
    AbstractApplicationContext context = new ClassPathXmlApplicationContext("messageBusWithoutAsyncEventMulticaster.xml", this.getClass());
    context.refresh();
    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();
}
Also used : AbstractApplicationContext(org.springframework.context.support.AbstractApplicationContext) SimpleApplicationEventMulticaster(org.springframework.context.event.SimpleApplicationEventMulticaster) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) Test(org.junit.Test)

Example 15 with SimpleApplicationEventMulticaster

use of org.springframework.context.event.SimpleApplicationEventMulticaster in project spring-integration by spring-projects.

the class MessageBusParserTests method testAsyncMulticaster.

@Test
public void testAsyncMulticaster() throws Exception {
    AbstractApplicationContext context = new ClassPathXmlApplicationContext("messageBusWithAsyncEventMulticaster.xml", this.getClass());
    context.refresh();
    SimpleApplicationEventMulticaster multicaster = (SimpleApplicationEventMulticaster) context.getBean(AbstractApplicationContext.APPLICATION_EVENT_MULTICASTER_BEAN_NAME);
    DirectFieldAccessor accessor = new DirectFieldAccessor(multicaster);
    Object taskExecutor = accessor.getPropertyValue("taskExecutor");
    assertThat(taskExecutor.getClass()).isEqualTo(ThreadPoolTaskExecutor.class);
    context.close();
}
Also used : AbstractApplicationContext(org.springframework.context.support.AbstractApplicationContext) SimpleApplicationEventMulticaster(org.springframework.context.event.SimpleApplicationEventMulticaster) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) Test(org.junit.Test)

Aggregations

SimpleApplicationEventMulticaster (org.springframework.context.event.SimpleApplicationEventMulticaster)15 Bean (org.springframework.context.annotation.Bean)7 Test (org.junit.Test)4 SimpleAsyncTaskExecutor (org.springframework.core.task.SimpleAsyncTaskExecutor)4 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)3 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)3 ConfigurableListableBeanFactory (org.springframework.beans.factory.config.ConfigurableListableBeanFactory)2 AbstractApplicationContext (org.springframework.context.support.AbstractApplicationContext)2 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)1 ApplicationEnvironmentPreparedEvent (org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent)1 ApplicationEvent (org.springframework.context.ApplicationEvent)1 ApplicationListener (org.springframework.context.ApplicationListener)1 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)1 ApplicationEventMulticaster (org.springframework.context.event.ApplicationEventMulticaster)1 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)1 QueueChannel (org.springframework.integration.channel.QueueChannel)1 ThreadPoolTaskExecutor (org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor)1