org.activiti.spring.SpringAsyncExecutor Java Examples

The following examples show how to use org.activiti.spring.SpringAsyncExecutor. 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: AbstractProcessEngineConfiguration.java    From activiti6-boot2 with Apache License 2.0 7 votes vote down vote up
public SpringProcessEngineConfiguration processEngineConfigurationBean(Resource[] processDefinitions,
                                                                       DataSource dataSource,
                                                                       PlatformTransactionManager transactionManager,
                                                                       SpringAsyncExecutor springAsyncExecutor)
      throws IOException {

  SpringProcessEngineConfiguration engine = new SpringProcessEngineConfiguration();
  if (processDefinitions != null && processDefinitions.length > 0) {
    engine.setDeploymentResources(processDefinitions);
  }
  engine.setDataSource(dataSource);
  engine.setTransactionManager(transactionManager);

  if (null != springAsyncExecutor) {
    engine.setAsyncExecutor(springAsyncExecutor);
  }

  return engine;
}
 
Example #2
Source File: ActivitiProcessEngineConfigurationTest.java    From herd with Apache License 2.0 6 votes vote down vote up
/**
 * 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);
}
 
Example #3
Source File: ProcessEngineConfiguration.java    From open-cloud with MIT License 5 votes vote down vote up
@Bean
public SpringProcessEngineConfiguration springProcessEngineConfiguration(DataSource dataSource, PlatformTransactionManager transactionManager,
                                                                         SpringAsyncExecutor springAsyncExecutor
) throws IOException {
    SpringProcessEngineConfiguration engineConfiguration = baseSpringProcessEngineConfiguration(
            dataSource,
            transactionManager,
            springAsyncExecutor);
    Map<String, List<ActivitiEventListener>> typedListeners = new HashMap<>();
    typedListeners.put("TASK_CREATED", Collections.singletonList(taskCreatedListener()));
    typedListeners.put("TASK_COMPLETED", Collections.singletonList(taskCompletedListener()));
    engineConfiguration.setTypedEventListeners(typedListeners);
    return engineConfiguration;
}
 
Example #4
Source File: JpaProcessEngineAutoConfiguration.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Bean
@ConditionalOnMissingBean
public SpringProcessEngineConfiguration springProcessEngineConfiguration(
        DataSource dataSource, EntityManagerFactory entityManagerFactory,
        PlatformTransactionManager transactionManager, SpringAsyncExecutor springAsyncExecutor) throws IOException {

  SpringProcessEngineConfiguration config = this.baseSpringProcessEngineConfiguration(dataSource, 
      transactionManager, springAsyncExecutor);
  config.setJpaEntityManagerFactory(entityManagerFactory);
  config.setTransactionManager(transactionManager);
  config.setJpaHandleTransaction(false);
  config.setJpaCloseEntityManager(false);
  return config;
}
 
Example #5
Source File: DataSourceProcessEngineAutoConfiguration.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Bean
@ConditionalOnMissingBean
public SpringProcessEngineConfiguration springProcessEngineConfiguration(
        DataSource dataSource,
        PlatformTransactionManager transactionManager,
        SpringAsyncExecutor springAsyncExecutor) throws IOException {
  
  return this.baseSpringProcessEngineConfiguration(dataSource, transactionManager, springAsyncExecutor);
}
 
Example #6
Source File: ActivitiConfig.java    From easyweb with Apache License 2.0 5 votes vote down vote up
@Bean
public SpringProcessEngineConfiguration springProcessEngineConfiguration(
        @Qualifier("activitidatabaseSource") DataSource dataSource,
        @Qualifier("activitiTransactionManager") PlatformTransactionManager transactionManager,
        SpringAsyncExecutor springAsyncExecutor) throws IOException {
    return this.baseSpringProcessEngineConfiguration(dataSource, transactionManager, springAsyncExecutor);
}
 
Example #7
Source File: ActivitiProcessEngineConfigurationTest.java    From herd with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example #8
Source File: AbstractProcessEngineAutoConfiguration.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
@Bean
public SpringAsyncExecutor springAsyncExecutor(TaskExecutor taskExecutor) {
  return new SpringAsyncExecutor(taskExecutor, springRejectedJobsHandler());
}
 
Example #9
Source File: AbstractProcessEngineAutoConfiguration.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
protected SpringProcessEngineConfiguration baseSpringProcessEngineConfiguration(DataSource dataSource, PlatformTransactionManager platformTransactionManager,
                                                                                SpringAsyncExecutor springAsyncExecutor) throws IOException {

  List<Resource> procDefResources = this.discoverProcessDefinitionResources(
      this.resourceLoader, this.activitiProperties.getProcessDefinitionLocationPrefix(),
      this.activitiProperties.getProcessDefinitionLocationSuffixes(),
      this.activitiProperties.isCheckProcessDefinitions());

  SpringProcessEngineConfiguration conf = super.processEngineConfigurationBean(
      procDefResources.toArray(new Resource[procDefResources.size()]), dataSource, 
      platformTransactionManager, springAsyncExecutor);

  conf.setDeploymentName(defaultText(activitiProperties.getDeploymentName(), conf.getDeploymentName()));
  conf.setDatabaseSchema(defaultText(activitiProperties.getDatabaseSchema(), conf.getDatabaseSchema()));
  conf.setDatabaseSchemaUpdate(defaultText(activitiProperties.getDatabaseSchemaUpdate(), conf.getDatabaseSchemaUpdate()));
  
  conf.setDbIdentityUsed(activitiProperties.isDbIdentityUsed());
  conf.setDbHistoryUsed(activitiProperties.isDbHistoryUsed());
  
  conf.setAsyncExecutorActivate(activitiProperties.isAsyncExecutorActivate());
  
  conf.setMailServerHost(activitiProperties.getMailServerHost());
  conf.setMailServerPort(activitiProperties.getMailServerPort());
  conf.setMailServerUsername(activitiProperties.getMailServerUserName());
  conf.setMailServerPassword(activitiProperties.getMailServerPassword());
  conf.setMailServerDefaultFrom(activitiProperties.getMailServerDefaultFrom());
  conf.setMailServerUseSSL(activitiProperties.isMailServerUseSsl());
  conf.setMailServerUseTLS(activitiProperties.isMailServerUseTls());
  
  conf.setHistoryLevel(activitiProperties.getHistoryLevel());

  if (activitiProperties.getCustomMybatisMappers() != null) {
    conf.setCustomMybatisMappers(getCustomMybatisMapperClasses(activitiProperties.getCustomMybatisMappers()));
  }

  if (activitiProperties.getCustomMybatisXMLMappers() != null) {
    conf.setCustomMybatisXMLMappers(new HashSet<String>(activitiProperties.getCustomMybatisXMLMappers()));
  }

  if (activitiProperties.getCustomMybatisMappers() != null) {
    conf.setCustomMybatisMappers(getCustomMybatisMapperClasses(activitiProperties.getCustomMybatisMappers()));
  }

  if (activitiProperties.getCustomMybatisXMLMappers() != null) {
    conf.setCustomMybatisXMLMappers(new HashSet<String>(activitiProperties.getCustomMybatisXMLMappers()));
  }
  
  if (processEngineConfigurationConfigurer != null) {
  	processEngineConfigurationConfigurer.configure(conf);
  }
  //从ActivitiEngineConfiguration copy来的
  FormEngineConfiguration formEngineConfiguration = new FormEngineConfiguration();
  formEngineConfiguration.setDataSource(dataSource);

  FormEngineConfigurator formEngineConfigurator = new FormEngineConfigurator();
  formEngineConfigurator.setFormEngineConfiguration(formEngineConfiguration);
  conf.addConfigurator(formEngineConfigurator);

  DmnEngineConfiguration dmnEngineConfiguration = new DmnEngineConfiguration();
  dmnEngineConfiguration.setDataSource(dataSource);

  DmnEngineConfigurator dmnEngineConfigurator = new DmnEngineConfigurator();
  dmnEngineConfigurator.setDmnEngineConfiguration(dmnEngineConfiguration);
  conf.addConfigurator(dmnEngineConfigurator);

  return conf;
}