Search in sources :

Example 31 with ThreadPoolTaskScheduler

use of org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler in project brewery by spring-cloud-samples.

the class BottlingConfiguration method threadPoolTaskScheduler.

@Bean(destroyMethod = "shutdown")
ThreadPoolTaskScheduler threadPoolTaskScheduler() {
    ThreadPoolTaskScheduler threadPoolTaskScheduler = new ThreadPoolTaskScheduler();
    threadPoolTaskScheduler.initialize();
    return threadPoolTaskScheduler;
}
Also used : ThreadPoolTaskScheduler(org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler) Bean(org.springframework.context.annotation.Bean)

Example 32 with ThreadPoolTaskScheduler

use of org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler in project eventapis by kloiasoft.

the class EventApisFactory method operationsKafkaListenerContainerFactory.

@Bean("operationsKafkaListenerContainerFactory")
public KafkaListenerContainerFactory<KafkaMessageListenerContainer<String, Operation>> operationsKafkaListenerContainerFactory(ConsumerFactory<String, Operation> consumerFactory, PlatformTransactionManager platformTransactionManager) {
    AbstractKafkaListenerContainerFactory<KafkaMessageListenerContainer<String, Operation>, String, Operation> abstractKafkaListenerContainerFactory = new EventApisKafkaListenerContainerFactory(consumerFactory);
    RetryTemplate retryTemplate = new RetryTemplate();
    abstractKafkaListenerContainerFactory.setRetryTemplate(retryTemplate);
    abstractKafkaListenerContainerFactory.getContainerProperties().setPollTimeout(3000L);
    abstractKafkaListenerContainerFactory.getContainerProperties().setAckOnError(false);
    ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
    scheduler.setPoolSize(eventApisConfiguration.getEventBus().getConsumer().getOperationSchedulerPoolSize());
    scheduler.setBeanName("OperationsFactory-Scheduler");
    scheduler.initialize();
    abstractKafkaListenerContainerFactory.getContainerProperties().setScheduler(scheduler);
    // ThreadPoolTaskScheduler consumerScheduler = new ThreadPoolTaskScheduler();
    // consumerScheduler.setPoolSize(30);
    // consumerScheduler.setBeanName("OperationsFactory-ConsumerScheduler");
    // consumerScheduler.initialize();
    // 
    // abstractKafkaListenerContainerFactory.getContainerProperties().setConsumerTaskExecutor(consumerScheduler);
    abstractKafkaListenerContainerFactory.getContainerProperties().setAckMode(AbstractMessageListenerContainer.AckMode.RECORD);
    abstractKafkaListenerContainerFactory.getContainerProperties().setTransactionManager(platformTransactionManager);
    return abstractKafkaListenerContainerFactory;
}
Also used : RetryTemplate(org.springframework.retry.support.RetryTemplate) KafkaMessageListenerContainer(org.springframework.kafka.listener.KafkaMessageListenerContainer) Operation(com.kloia.eventapis.pojos.Operation) ThreadPoolTaskScheduler(org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler) FilterRegistrationBean(org.springframework.boot.web.servlet.FilterRegistrationBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 33 with ThreadPoolTaskScheduler

use of org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler in project nzbhydra2 by theotherp.

the class HydraTaskConfiguration method taskExecutor.

@Bean
public ThreadPoolTaskScheduler taskExecutor() {
    ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
    scheduler.setPoolSize(5);
    scheduler.setThreadNamePrefix("HydraTask");
    return scheduler;
}
Also used : ThreadPoolTaskScheduler(org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler) Bean(org.springframework.context.annotation.Bean)

Example 34 with ThreadPoolTaskScheduler

use of org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler in project gravitee-gateway by gravitee-io.

the class SyncConfiguration method taskScheduler.

@Bean
public TaskScheduler taskScheduler() {
    ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
    scheduler.setThreadNamePrefix("sync-");
    return scheduler;
}
Also used : ThreadPoolTaskScheduler(org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler) Bean(org.springframework.context.annotation.Bean)

Example 35 with ThreadPoolTaskScheduler

use of org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler in project spring-cloud-stream by spring-cloud.

the class BindingServiceTests method testLateBindingProducer.

@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testLateBindingProducer() throws Exception {
    BindingServiceProperties properties = new BindingServiceProperties();
    properties.setBindingRetryInterval(1);
    Map<String, BindingProperties> bindingProperties = new HashMap<>();
    BindingProperties props = new BindingProperties();
    props.setDestination("foo");
    final String outputChannelName = "output";
    bindingProperties.put(outputChannelName, props);
    properties.setBindings(bindingProperties);
    DefaultBinderFactory binderFactory = createMockBinderFactory();
    Binder binder = binderFactory.getBinder("mock", MessageChannel.class);
    ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
    scheduler.initialize();
    BindingService service = new BindingService(properties, binderFactory, scheduler);
    MessageChannel outputChannel = new DirectChannel();
    final Binding<MessageChannel> mockBinding = Mockito.mock(Binding.class);
    final CountDownLatch fail = new CountDownLatch(2);
    doAnswer(i -> {
        fail.countDown();
        if (fail.getCount() == 1) {
            throw new RuntimeException("fail");
        }
        return mockBinding;
    }).when(binder).bindProducer(eq("foo"), same(outputChannel), any(ProducerProperties.class));
    Binding<MessageChannel> binding = service.bindProducer(outputChannel, outputChannelName);
    assertThat(fail.await(10, TimeUnit.SECONDS)).isTrue();
    assertThat(binding).isNotNull();
    Binding delegate = TestUtils.getPropertyValue(binding, "delegate", Binding.class);
    int n = 0;
    while (n++ < 300 && delegate == null) {
        Thread.sleep(100);
        delegate = TestUtils.getPropertyValue(binding, "delegate", Binding.class);
    }
    assertThat(delegate).isSameAs(mockBinding);
    service.unbindProducers(outputChannelName);
    verify(binder, times(2)).bindProducer(eq("foo"), same(outputChannel), any(ProducerProperties.class));
    verify(delegate).unbind();
    binderFactory.destroy();
    scheduler.destroy();
}
Also used : Binding(org.springframework.cloud.stream.binder.Binding) ProducerProperties(org.springframework.cloud.stream.binder.ProducerProperties) ExtendedProducerProperties(org.springframework.cloud.stream.binder.ExtendedProducerProperties) HashMap(java.util.HashMap) DirectChannel(org.springframework.integration.channel.DirectChannel) BindingProperties(org.springframework.cloud.stream.config.BindingProperties) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) CountDownLatch(java.util.concurrent.CountDownLatch) DefaultBinderFactory(org.springframework.cloud.stream.binder.DefaultBinderFactory) ThreadPoolTaskScheduler(org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler) ExtendedPropertiesBinder(org.springframework.cloud.stream.binder.ExtendedPropertiesBinder) Binder(org.springframework.cloud.stream.binder.Binder) MessageChannel(org.springframework.messaging.MessageChannel) BindingServiceProperties(org.springframework.cloud.stream.config.BindingServiceProperties) Test(org.junit.Test)

Aggregations

ThreadPoolTaskScheduler (org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler)122 Test (org.junit.Test)41 Bean (org.springframework.context.annotation.Bean)32 BeanFactory (org.springframework.beans.factory.BeanFactory)31 Test (org.junit.jupiter.api.Test)26 CountDownLatch (java.util.concurrent.CountDownLatch)19 QueueChannel (org.springframework.integration.channel.QueueChannel)19 GenericMessage (org.springframework.messaging.support.GenericMessage)13 AtomicReference (java.util.concurrent.atomic.AtomicReference)12 ExecutorService (java.util.concurrent.ExecutorService)10 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)8 MqttPahoMessageDrivenChannelAdapter (org.springframework.integration.mqtt.inbound.MqttPahoMessageDrivenChannelAdapter)8 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)7 MqttPahoMessageHandler (org.springframework.integration.mqtt.outbound.MqttPahoMessageHandler)6 JmsTemplate (org.springframework.jms.core.JmsTemplate)6 ArrayList (java.util.ArrayList)5 Log (org.apache.commons.logging.Log)5 MessageChannel (org.springframework.messaging.MessageChannel)5 File (java.io.File)4 ConnectionFactory (javax.jms.ConnectionFactory)4