Search in sources :

Example 66 with ThreadPoolTaskScheduler

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

the class EventApisFactory method operationsKafkaListenerContainerFactory.

@Bean("operationsKafkaListenerContainerFactory")
public ConcurrentKafkaListenerContainerFactory<String, Operation> operationsKafkaListenerContainerFactory(ConsumerFactory<String, Operation> consumerFactory) {
    ConcurrentKafkaListenerContainerFactory<String, Operation> factory = new ConcurrentKafkaListenerContainerFactory<>();
    factory.setConsumerFactory(consumerFactory);
    RetryTemplate retryTemplate = new RetryTemplate();
    factory.setRetryTemplate(retryTemplate);
    factory.setConcurrency(eventApisConfiguration.getEventBus().getConsumer().getOperationSchedulerPoolSize());
    ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
    scheduler.setPoolSize(eventApisConfiguration.getEventBus().getConsumer().getOperationSchedulerPoolSize());
    scheduler.setBeanName("OperationsFactory-Scheduler");
    scheduler.initialize();
    factory.getContainerProperties().setScheduler(scheduler);
    ThreadPoolTaskScheduler consumerScheduler = new ThreadPoolTaskScheduler();
    consumerScheduler.setPoolSize(eventApisConfiguration.getEventBus().getConsumer().getOperationSchedulerPoolSize());
    consumerScheduler.setBeanName("OperationsFactory-ConsumerScheduler");
    consumerScheduler.initialize();
    factory.getContainerProperties().setPollTimeout(3000L);
    factory.getContainerProperties().setAckOnError(false);
    factory.getContainerProperties().setConsumerTaskExecutor(consumerScheduler);
    factory.getContainerProperties().setAckMode(ContainerProperties.AckMode.RECORD);
    /**
     * This is Fix for Spring Kafka versions which does not have ConsumerAwareErrorHandler handler till 2.0
     * When Listener faces with error, it retries snapshot operation
     * See https://github.com/kloiasoft/eventapis/issues/44
     */
    factory.getContainerProperties().setTransactionManager(new EmptyTransactionManager());
    // factory.getContainerProperties().setTransactionManager(platformTransactionManager);
    return factory;
}
Also used : RetryTemplate(org.springframework.retry.support.RetryTemplate) ConcurrentKafkaListenerContainerFactory(org.springframework.kafka.config.ConcurrentKafkaListenerContainerFactory) Operation(io.splitet.core.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 67 with ThreadPoolTaskScheduler

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

the class EventApisFactory method eventsKafkaListenerContainerFactory.

@Bean({ "eventsKafkaListenerContainerFactory", "kafkaListenerContainerFactory" })
public ConcurrentKafkaListenerContainerFactory<String, PublishedEventWrapper> eventsKafkaListenerContainerFactory(EventMessageConverter eventMessageConverter, ConsumerFactory<String, PublishedEventWrapper> consumerFactory) {
    ConcurrentKafkaListenerContainerFactory<String, PublishedEventWrapper> factory = new ConcurrentKafkaListenerContainerFactory<>();
    factory.setConsumerFactory(consumerFactory);
    factory.setConcurrency(eventApisConfiguration.getEventBus().getConsumer().getEventConcurrency());
    factory.setMessageConverter(eventMessageConverter);
    factory.getContainerProperties().setPollTimeout(3000);
    ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
    scheduler.setPoolSize(eventApisConfiguration.getEventBus().getConsumer().getEventSchedulerPoolSize());
    scheduler.setBeanName("EventsFactory-Scheduler");
    scheduler.initialize();
    factory.getContainerProperties().setScheduler(scheduler);
    factory.getContainerProperties().setAckMode(ContainerProperties.AckMode.RECORD);
    return factory;
}
Also used : PublishedEventWrapper(io.splitet.core.kafka.PublishedEventWrapper) ConcurrentKafkaListenerContainerFactory(org.springframework.kafka.config.ConcurrentKafkaListenerContainerFactory) 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 68 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(1);
    scheduler.setThreadNamePrefix("HydraTask");
    scheduler.setThreadGroupName("HydraTask");
    return scheduler;
}
Also used : ThreadPoolTaskScheduler(org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler) Bean(org.springframework.context.annotation.Bean)

Example 69 with ThreadPoolTaskScheduler

use of org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler in project spring-boot by spring-projects.

the class TaskExecutorMetricsAutoConfigurationTests method taskSchedulersWithCustomNamesAreInstrumented.

@Test
void taskSchedulersWithCustomNamesAreInstrumented() {
    this.contextRunner.withBean("firstTaskScheduler", Executor.class, ThreadPoolTaskScheduler::new).withBean("customName", ThreadPoolTaskScheduler.class, ThreadPoolTaskScheduler::new).run((context) -> {
        MeterRegistry registry = context.getBean(MeterRegistry.class);
        Collection<FunctionCounter> meters = registry.get("executor.completed").functionCounters();
        assertThat(meters).map((meter) -> meter.getId().getTag("name")).containsExactlyInAnyOrder("firstTaskScheduler", "customName");
    });
}
Also used : ThreadPoolTaskExecutor(org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor) AutoConfigurations(org.springframework.boot.autoconfigure.AutoConfigurations) TaskExecutionAutoConfiguration(org.springframework.boot.autoconfigure.task.TaskExecutionAutoConfiguration) MeterNotFoundException(io.micrometer.core.instrument.search.MeterNotFoundException) Executor(java.util.concurrent.Executor) Collection(java.util.Collection) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) MetricsRun(org.springframework.boot.actuate.autoconfigure.metrics.test.MetricsRun) ApplicationContextRunner(org.springframework.boot.test.context.runner.ApplicationContextRunner) Test(org.junit.jupiter.api.Test) TaskSchedulingAutoConfiguration(org.springframework.boot.autoconfigure.task.TaskSchedulingAutoConfiguration) Configuration(org.springframework.context.annotation.Configuration) BDDMockito.given(org.mockito.BDDMockito.given) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) Assertions.assertThatExceptionOfType(org.assertj.core.api.Assertions.assertThatExceptionOfType) FunctionCounter(io.micrometer.core.instrument.FunctionCounter) EnableScheduling(org.springframework.scheduling.annotation.EnableScheduling) ThreadPoolTaskScheduler(org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler) Mockito.mock(org.mockito.Mockito.mock) FunctionCounter(io.micrometer.core.instrument.FunctionCounter) ThreadPoolTaskScheduler(org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) Test(org.junit.jupiter.api.Test)

Example 70 with ThreadPoolTaskScheduler

use of org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler in project spring-boot by spring-projects.

the class PrometheusPushGatewayManagerTests method shutdownWhenDoesNotOwnSchedulerDoesNotShutdownScheduler.

@Test
void shutdownWhenDoesNotOwnSchedulerDoesNotShutdownScheduler() {
    ThreadPoolTaskScheduler otherScheduler = givenScheduleAtFixedRateWillReturnFuture(mock(ThreadPoolTaskScheduler.class));
    PrometheusPushGatewayManager manager = new PrometheusPushGatewayManager(this.pushGateway, this.registry, otherScheduler, this.pushRate, "job", this.groupingKey, null);
    manager.shutdown();
    then(otherScheduler).should(never()).shutdown();
}
Also used : ThreadPoolTaskScheduler(org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler) Test(org.junit.jupiter.api.Test)

Aggregations

ThreadPoolTaskScheduler (org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler)146 Test (org.junit.jupiter.api.Test)53 Bean (org.springframework.context.annotation.Bean)46 BeanFactory (org.springframework.beans.factory.BeanFactory)33 CountDownLatch (java.util.concurrent.CountDownLatch)23 QueueChannel (org.springframework.integration.channel.QueueChannel)23 Test (org.junit.Test)18 AtomicReference (java.util.concurrent.atomic.AtomicReference)17 GenericMessage (org.springframework.messaging.support.GenericMessage)14 ExecutorService (java.util.concurrent.ExecutorService)12 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)12 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)11 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)9 Message (org.springframework.messaging.Message)9 MessageChannel (org.springframework.messaging.MessageChannel)9 ArrayList (java.util.ArrayList)8 MessagingException (org.springframework.messaging.MessagingException)8 LogAccessor (org.springframework.core.log.LogAccessor)7 IOException (java.io.IOException)6 Socket (java.net.Socket)6