org.springframework.context.event.SimpleApplicationEventMulticaster Java Examples

The following examples show how to use org.springframework.context.event.SimpleApplicationEventMulticaster. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractApplicationContext.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * 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.isTraceEnabled()) {
			logger.trace("Using ApplicationEventMulticaster [" + this.applicationEventMulticaster + "]");
		}
	}
	else {
		this.applicationEventMulticaster = new SimpleApplicationEventMulticaster(beanFactory);
		beanFactory.registerSingleton(APPLICATION_EVENT_MULTICASTER_BEAN_NAME, this.applicationEventMulticaster);
		if (logger.isTraceEnabled()) {
			logger.trace("No '" + APPLICATION_EVENT_MULTICASTER_BEAN_NAME + "' bean, using " +
					"[" + this.applicationEventMulticaster.getClass().getSimpleName() + "]");
		}
	}
}
 
Example #2
Source File: AppConfig.java    From flow-platform-x with Apache License 2.0 6 votes vote down vote up
@Bean(name = "applicationEventMulticaster")
public ApplicationEventMulticaster simpleApplicationEventMulticaster() {
    SimpleApplicationEventMulticaster multicaster = new SimpleApplicationEventMulticaster() {

        @Override
        public void multicastEvent(ApplicationEvent event, ResolvableType eventType) {
            if (event instanceof SyncEvent) {
                ResolvableType type = (eventType != null ? eventType : ResolvableType.forInstance(event));
                for (final ApplicationListener<?> listener : getApplicationListeners(event, type)) {
                    invokeListener(listener, event);
                }
                return;
            }

            super.multicastEvent(event, eventType);
        }
    };

    SimpleAsyncTaskExecutor executor = new SimpleAsyncTaskExecutor("s-event-");
    multicaster.setTaskExecutor(executor);
    return multicaster;
}
 
Example #3
Source File: AbstractApplicationContext.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
/**
 * 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 + "]");
		}
	}
}
 
Example #4
Source File: AbstractApplicationContext.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * Initialize the ApplicationEventMulticaster.
 * Uses SimpleApplicationEventMulticaster if none defined in the context.
 * @see org.springframework.context.event.SimpleApplicationEventMulticaster
 */
protected void initApplicationEventMulticaster() {
	ConfigurableListableBeanFactory beanFactory = getBeanFactory();
	// 如有有自己注册class Name 是 applicationEventMulticaster,使用自定义广播器
	if (beanFactory.containsLocalBean(APPLICATION_EVENT_MULTICASTER_BEAN_NAME)) {
		this.applicationEventMulticaster =
				beanFactory.getBean(APPLICATION_EVENT_MULTICASTER_BEAN_NAME, ApplicationEventMulticaster.class);
		if (logger.isTraceEnabled()) {
			logger.trace("Using ApplicationEventMulticaster [" + this.applicationEventMulticaster + "]");
		}
	}
	else {
		// 没有自定义,使用默认的事件广播器
		this.applicationEventMulticaster = new SimpleApplicationEventMulticaster(beanFactory);
		beanFactory.registerSingleton(APPLICATION_EVENT_MULTICASTER_BEAN_NAME, this.applicationEventMulticaster);
		if (logger.isTraceEnabled()) {
			logger.trace("No '" + APPLICATION_EVENT_MULTICASTER_BEAN_NAME + "' bean, using " +
					"[" + this.applicationEventMulticaster.getClass().getSimpleName() + "]");
		}
	}
}
 
Example #5
Source File: AbstractApplicationContext.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 + "]");
		}
	}
}
 
Example #6
Source File: AsynchronousSpringEventsConfig.java    From wetech-admin with MIT License 5 votes vote down vote up
@Bean(name = "applicationEventMulticaster")
public ApplicationEventMulticaster simpleApplicationEventMulticaster() {
    SimpleApplicationEventMulticaster eventMulticaster
            = new SimpleApplicationEventMulticaster();
    eventMulticaster.setTaskExecutor(new SimpleAsyncTaskExecutor());
    return eventMulticaster;
}
 
Example #7
Source File: GenieEventBusImpl.java    From genie with Apache License 2.0 5 votes vote down vote up
/**
 * Constructor.
 *
 * @param syncEventMulticaster  The synchronous task multicaster to use
 * @param asyncEventMulticaster The asynchronous task multicaster to use
 */
public GenieEventBusImpl(
    @NonNull final SimpleApplicationEventMulticaster syncEventMulticaster,
    @NonNull final SimpleApplicationEventMulticaster asyncEventMulticaster
) {
    this.syncMulticaster = syncEventMulticaster;
    this.asyncMulticaster = asyncEventMulticaster;
}
 
Example #8
Source File: EventsAutoConfiguration.java    From genie with Apache License 2.0 5 votes vote down vote up
/**
 * A multicast event publisher to replace the default one used by Spring via the ApplicationContext.
 *
 * @param syncTaskExecutor  The synchronous task executor to use
 * @param asyncTaskExecutor The asynchronous task executor to use
 * @return The application event multicaster to use
 */
@Bean
@ConditionalOnMissingBean(GenieEventBus.class)
public GenieEventBusImpl applicationEventMulticaster(
    @Qualifier("genieSyncTaskExecutor") final SyncTaskExecutor syncTaskExecutor,
    @Qualifier("genieAsyncTaskExecutor") final AsyncTaskExecutor asyncTaskExecutor
) {
    final SimpleApplicationEventMulticaster syncMulticaster = new SimpleApplicationEventMulticaster();
    syncMulticaster.setTaskExecutor(syncTaskExecutor);

    final SimpleApplicationEventMulticaster asyncMulticaster = new SimpleApplicationEventMulticaster();
    asyncMulticaster.setTaskExecutor(asyncTaskExecutor);
    return new GenieEventBusImpl(syncMulticaster, asyncMulticaster);
}
 
Example #9
Source File: AsynchronousSpringEventConfiguration.java    From data-prep with Apache License 2.0 5 votes vote down vote up
@Bean(name = "applicationEventMulticaster")
public ApplicationEventMulticaster simpleApplicationEventMulticaster() {
    SimpleApplicationEventMulticaster eventMulticaster = new SimpleApplicationEventMulticaster();

    eventMulticaster.setTaskExecutor(new SimpleAsyncTaskExecutor());
    return eventMulticaster;
}
 
Example #10
Source File: EventPublisherAutoConfiguration.java    From hawkbit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * 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)
ApplicationEventMulticaster applicationEventMulticaster(@Qualifier("asyncExecutor") final Executor executor,
        final TenantAware tenantAware) {
    final SimpleApplicationEventMulticaster simpleApplicationEventMulticaster = new TenantAwareApplicationEventPublisher(
            tenantAware, applicationEventFilter());
    simpleApplicationEventMulticaster.setTaskExecutor(executor);
    return simpleApplicationEventMulticaster;
}
 
Example #11
Source File: TestConfiguration.java    From hawkbit with Eclipse Public License 1.0 5 votes vote down vote up
@Bean(name = AbstractApplicationContext.APPLICATION_EVENT_MULTICASTER_BEAN_NAME)
SimpleApplicationEventMulticaster applicationEventMulticaster(final ApplicationEventFilter applicationEventFilter) {
    final SimpleApplicationEventMulticaster simpleApplicationEventMulticaster = new FilterEnabledApplicationEventPublisher(
            applicationEventFilter);
    simpleApplicationEventMulticaster.setTaskExecutor(asyncExecutor());
    return simpleApplicationEventMulticaster;
}
 
Example #12
Source File: MetacatApplicationEventMulticaster.java    From metacat with Apache License 2.0 5 votes vote down vote up
private ApplicationEventMulticaster createApplicationEventMultiCaster(final String name) {
    final SimpleApplicationEventMulticaster result = new SimpleApplicationEventMulticaster();
    final ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
    executor.setCorePoolSize(metacatProperties.getEvent().getBus().getExecutor().getThread().getCount());
    executor.initialize();
    RegistryUtil.registerThreadPool(registry, "metacat.event.pool." + name,
        executor.getThreadPoolExecutor());
    result.setTaskExecutor(executor);
    return result;
}
 
Example #13
Source File: AsynchronousSpringEventsConfiguration.java    From integration-patterns with MIT License 5 votes vote down vote up
@Bean(name = "applicationEventMulticaster")
public ApplicationEventMulticaster simpleApplicationEventMulticaster() {
    final SimpleApplicationEventMulticaster eventMulticaster = new SimpleApplicationEventMulticaster();

    // FIXME use fixed size thread pool
    eventMulticaster.setTaskExecutor(new SimpleAsyncTaskExecutor());
    return eventMulticaster;
}
 
Example #14
Source File: Application.java    From daming with Apache License 2.0 5 votes vote down vote up
@Bean(name = "applicationEventMulticaster")
public ApplicationEventMulticaster simpleApplicationEventMulticaster() {
    SimpleApplicationEventMulticaster eventMulticaster
            = new SimpleApplicationEventMulticaster();

    eventMulticaster.setTaskExecutor(new SimpleAsyncTaskExecutor());
    return eventMulticaster;
}
 
Example #15
Source File: InputAdaptersConfiguration.java    From ddd-with-spring with Apache License 2.0 5 votes vote down vote up
@Bean(name = "applicationEventMulticaster")
public ApplicationEventMulticaster simpleApplicationEventMulticaster() {
	SimpleApplicationEventMulticaster eventMulticaster
			= new SimpleApplicationEventMulticaster();

	eventMulticaster.setTaskExecutor(new SimpleAsyncTaskExecutor());
	return eventMulticaster;
}
 
Example #16
Source File: EventNetstrapSpringRunListener.java    From netstrap with Apache License 2.0 5 votes vote down vote up
/**
 * Netstrap事件监听器
 */
public EventNetstrapSpringRunListener(NetstrapBootApplication application) {
    this.application = application;
    this.initialMulticaster = new SimpleApplicationEventMulticaster();
    for (ApplicationListener<?> listener : application.getListeners()) {
        this.initialMulticaster.addApplicationListener(listener);
    }
}
 
Example #17
Source File: NotificationEventBusConfig.java    From stream-registry with Apache License 2.0 5 votes vote down vote up
@Bean(name = "applicationEventMulticaster")
public ApplicationEventMulticaster simpleApplicationEventMulticaster() {
  SimpleApplicationEventMulticaster eventMulticaster = new SimpleApplicationEventMulticaster();
  eventMulticaster.setTaskExecutor(new SimpleAsyncTaskExecutor());

  return eventMulticaster;
}
 
Example #18
Source File: NotificationEventListenerKafkaIntegrationTest.java    From stream-registry with Apache License 2.0 5 votes vote down vote up
@Bean
public ApplicationEventMulticaster simpleApplicationEventMulticaster() {
  SimpleApplicationEventMulticaster eventMulticaster = new SimpleApplicationEventMulticaster();
  eventMulticaster.setTaskExecutor(new SimpleAsyncTaskExecutor());

  return eventMulticaster;
}
 
Example #19
Source File: NotificationEventListenerTest.java    From stream-registry with Apache License 2.0 5 votes vote down vote up
@Bean
public ApplicationEventMulticaster simpleApplicationEventMulticaster() {
  SimpleApplicationEventMulticaster eventMulticaster = new SimpleApplicationEventMulticaster();
  eventMulticaster.setTaskExecutor(new SimpleAsyncTaskExecutor());

  return eventMulticaster;
}
 
Example #20
Source File: ButlerConfig.java    From cf-butler with Apache License 2.0 5 votes vote down vote up
@Bean(name = "applicationEventMulticaster")
public ApplicationEventMulticaster simpleApplicationEventMulticaster() {
    SimpleApplicationEventMulticaster eventMulticaster =
        new SimpleApplicationEventMulticaster();
    eventMulticaster.setTaskExecutor(new SimpleAsyncTaskExecutor());
    return eventMulticaster;
}