Search in sources :

Example 1 with SpringAsyncExecutor

use of org.activiti.spring.SpringAsyncExecutor in project herd by FINRAOS.

the class ServiceSpringModuleConfig method activitiAsyncExecutor.

/**
 * Returns an Activiti Async executor that uses our configured task executor.
 *
 * @param activitiTaskExecutor the task executor. Note that the parameter must be named as is so that Spring IoC knows which TaskExecutor bean to autowire.
 * @param springRejectedJobsHandler The Spring rejected jobs handler
 *
 * @return the Async executor.
 */
@Bean
public AsyncExecutor activitiAsyncExecutor(TaskExecutor activitiTaskExecutor, SpringRejectedJobsHandler springRejectedJobsHandler) {
    SpringAsyncExecutor activitiAsyncExecutor = new SpringAsyncExecutor(activitiTaskExecutor, springRejectedJobsHandler);
    activitiAsyncExecutor.setAsyncJobLockTimeInMillis(configurationHelper.getProperty(ConfigurationValue.ACTIVITI_ASYNC_JOB_LOCK_TIME_MILLIS, Integer.class));
    return activitiAsyncExecutor;
}
Also used : SpringAsyncExecutor(org.activiti.spring.SpringAsyncExecutor) ProcessEngineFactoryBean(org.activiti.spring.ProcessEngineFactoryBean) SchedulerFactoryBean(org.springframework.scheduling.quartz.SchedulerFactoryBean) Bean(org.springframework.context.annotation.Bean)

Example 2 with SpringAsyncExecutor

use of org.activiti.spring.SpringAsyncExecutor in project herd by FINRAOS.

the class ActivitiProcessEngineConfigurationTest method testActivitiThreadPoolIsIsolatedFromGenericAsyncPool.

/**
 * Ensure that the Activiti's thread pool is separate from the application's generic thread pool.
 */
@Test
public void testActivitiThreadPoolIsIsolatedFromGenericAsyncPool() {
    AsyncExecutor asyncExecutor = processEngineConfiguration.getAsyncExecutor();
    SpringAsyncExecutor springAsyncExecutor = (SpringAsyncExecutor) asyncExecutor;
    TaskExecutor taskExecutor = springAsyncExecutor.getTaskExecutor();
    assertTrue(genericTaskExecutor != taskExecutor);
}
Also used : ThreadPoolTaskExecutor(org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor) TaskExecutor(org.springframework.core.task.TaskExecutor) AsyncExecutor(org.activiti.engine.impl.asyncexecutor.AsyncExecutor) SpringAsyncExecutor(org.activiti.spring.SpringAsyncExecutor) SpringAsyncExecutor(org.activiti.spring.SpringAsyncExecutor) Test(org.junit.Test) AbstractServiceTest(org.finra.herd.service.AbstractServiceTest)

Example 3 with SpringAsyncExecutor

use of org.activiti.spring.SpringAsyncExecutor in project herd by FINRAOS.

the class ActivitiProcessEngineConfigurationTest method testActivitiThreadPoolUsesConfiguredValues.

/**
 * Ensure that the Activiti's thread pool uses the correct configuration value.
 *
 * This assertion is limited in that the configuration values must be set before Spring application context is initialized, which we cannot control easily
 * in unit test.
 */
@Test
public void testActivitiThreadPoolUsesConfiguredValues() {
    AsyncExecutor asyncExecutor = processEngineConfiguration.getAsyncExecutor();
    SpringAsyncExecutor springAsyncExecutor = (SpringAsyncExecutor) asyncExecutor;
    TaskExecutor taskExecutor = springAsyncExecutor.getTaskExecutor();
    ThreadPoolTaskExecutor threadPoolTaskExecutor = (ThreadPoolTaskExecutor) taskExecutor;
    Integer corePoolSize = threadPoolTaskExecutor.getCorePoolSize();
    Integer maxPoolSize = threadPoolTaskExecutor.getMaxPoolSize();
    Integer keepAliveSeconds = threadPoolTaskExecutor.getKeepAliveSeconds();
    // No real easy way of getting the queue capacity from the already constructed thread pool
    Integer remainingCapacity = ((LinkedBlockingQueue<?>) threadPoolTaskExecutor.getThreadPoolExecutor().getQueue()).remainingCapacity();
    assertEquals(configurationHelper.getProperty(ConfigurationValue.ACTIVITI_THREAD_POOL_CORE_POOL_SIZE, Integer.class), corePoolSize);
    assertEquals(configurationHelper.getProperty(ConfigurationValue.ACTIVITI_THREAD_POOL_MAX_POOL_SIZE, Integer.class), maxPoolSize);
    assertEquals(configurationHelper.getProperty(ConfigurationValue.ACTIVITI_THREAD_POOL_KEEP_ALIVE_SECS, Integer.class), keepAliveSeconds);
    assertEquals(configurationHelper.getProperty(ConfigurationValue.ACTIVITI_THREAD_POOL_QUEUE_CAPACITY, Integer.class), remainingCapacity);
}
Also used : ThreadPoolTaskExecutor(org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor) TaskExecutor(org.springframework.core.task.TaskExecutor) ThreadPoolTaskExecutor(org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) AsyncExecutor(org.activiti.engine.impl.asyncexecutor.AsyncExecutor) SpringAsyncExecutor(org.activiti.spring.SpringAsyncExecutor) SpringAsyncExecutor(org.activiti.spring.SpringAsyncExecutor) Test(org.junit.Test) AbstractServiceTest(org.finra.herd.service.AbstractServiceTest)

Aggregations

SpringAsyncExecutor (org.activiti.spring.SpringAsyncExecutor)3 AsyncExecutor (org.activiti.engine.impl.asyncexecutor.AsyncExecutor)2 AbstractServiceTest (org.finra.herd.service.AbstractServiceTest)2 Test (org.junit.Test)2 TaskExecutor (org.springframework.core.task.TaskExecutor)2 ThreadPoolTaskExecutor (org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor)2 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)1 ProcessEngineFactoryBean (org.activiti.spring.ProcessEngineFactoryBean)1 Bean (org.springframework.context.annotation.Bean)1 SchedulerFactoryBean (org.springframework.scheduling.quartz.SchedulerFactoryBean)1