org.springframework.scheduling.annotation.AsyncConfigurer Java Examples

The following examples show how to use org.springframework.scheduling.annotation.AsyncConfigurer. 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: ExecutorConfiguration.java    From jetlinks-community with Apache License 2.0 6 votes vote down vote up
@Bean
public AsyncConfigurer asyncConfigurer() {
    AsyncUncaughtExceptionHandler handler = new SimpleAsyncUncaughtExceptionHandler();

    return new AsyncConfigurer() {
        @Override
        @SneakyThrows
        public Executor getAsyncExecutor() {
            return threadPoolTaskExecutor().getObject();
        }

        @Override
        public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() {
            return handler;
        }
    };
}
 
Example #2
Source File: CustomAsyncConfigurerAutoConfiguration.java    From java-spring-cloud with Apache License 2.0 5 votes vote down vote up
@Override
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
  if (bean instanceof AsyncConfigurer && !(bean instanceof TracedAsyncConfigurer)) {
    AsyncConfigurer configurer = (AsyncConfigurer) bean;
    Tracer tracer = this.beanFactory.getBean(Tracer.class);
    return new TracedAsyncConfigurer(tracer, configurer);
  }
  return bean;
}
 
Example #3
Source File: CustomAsyncConfigurerAutoConfigurationTest.java    From java-spring-cloud with Apache License 2.0 5 votes vote down vote up
@Test
public void should_return_async_configurer_when_bean_instance_of_it() {
  BeanFactory beanFactory = mock(BeanFactory.class);
  when(beanFactory.getBean(Tracer.class)).thenReturn(new MockTracer());

  CustomAsyncConfigurerAutoConfiguration configuration = new CustomAsyncConfigurerAutoConfiguration();
  configuration.setBeanFactory(beanFactory);

  Object bean = configuration
      .postProcessAfterInitialization(mock(AsyncConfigurer.class), "myAsync");
  then(bean).isInstanceOf(TracedAsyncConfigurer.class);
}
 
Example #4
Source File: AsyncCustomAutoConfiguration.java    From spring-cloud-sleuth with Apache License 2.0 5 votes vote down vote up
@Override
public Object postProcessAfterInitialization(Object bean, String beanName)
		throws BeansException {
	if (bean instanceof AsyncConfigurer
			&& !(bean instanceof LazyTraceAsyncCustomizer)) {
		AsyncConfigurer configurer = (AsyncConfigurer) bean;
		return new LazyTraceAsyncCustomizer(this.beanFactory, configurer);
	}
	return bean;
}
 
Example #5
Source File: AsyncCustomAutoConfigurationTest.java    From spring-cloud-sleuth with Apache License 2.0 5 votes vote down vote up
@Test
public void should_return_lazy_async_configurer_when_bean_is_async_configurer()
		throws Exception {
	AsyncCustomAutoConfiguration configuration = new AsyncCustomAutoConfiguration();

	Object bean = configuration
			.postProcessAfterInitialization(mock(AsyncConfigurer.class), "someName");

	then(bean).isInstanceOf(LazyTraceAsyncCustomizer.class);
}
 
Example #6
Source File: GH1212Tests.java    From spring-cloud-sleuth with Apache License 2.0 5 votes vote down vote up
@Bean
public AsyncConfigurer customAsyncConfigurer() {
	return new AsyncConfigurerSupport() {
		@Override
		public Executor getAsyncExecutor() {
			return new SimpleAsyncTaskExecutor("customAsyncConfigurer");
		}
	};
}
 
Example #7
Source File: TracedAsyncConfigurer.java    From java-spring-cloud with Apache License 2.0 4 votes vote down vote up
public TracedAsyncConfigurer(Tracer tracer, AsyncConfigurer delegate) {
  this.tracer = tracer;
  this.delegate = delegate;
}
 
Example #8
Source File: LazyTraceAsyncCustomizer.java    From spring-cloud-sleuth with Apache License 2.0 4 votes vote down vote up
public LazyTraceAsyncCustomizer(BeanFactory beanFactory, AsyncConfigurer delegate) {
	this.beanFactory = beanFactory;
	this.delegate = delegate;
}