Java Code Examples for org.activiti.spring.SpringProcessEngineConfiguration#setAsyncExecutor()

The following examples show how to use org.activiti.spring.SpringProcessEngineConfiguration#setAsyncExecutor() . 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: ServiceSpringModuleConfig.java    From herd with Apache License 2.0 4 votes vote down vote up
/**
 * Gets the Activiti Process Engine Configuration.
 *
 * @param activitiAsyncExecutor the async executor to set on the configuration.
 *
 * @return the Activiti Process Engine Configuration.
 */
@Bean
public SpringProcessEngineConfiguration activitiProcessEngineConfiguration(AsyncExecutor activitiAsyncExecutor)
{
    // Initialize a new process engine configuration for Activiti that is Spring enabled.
    SpringProcessEngineConfiguration configuration = new SpringProcessEngineConfiguration();

    // Share the herd data source and transaction manager with Activiti so all DB operations between the herd schema and the Activiti schema will occur
    // within the same transaction that can be committed or rolled back together.
    configuration.setDataSource(herdDataSource);
    configuration.setTransactionManager(herdTransactionManager);

    // Set the database schema update approach. This will be different for the main application and JUnits which is why we get it from a bean
    // via the method below.
    configuration.setDatabaseSchemaUpdate(getActivitiDbSchemaUpdateParamBeanName());

    // Enable the async executor so threads can be picked up and worked on.
    configuration.setAsyncExecutorActivate(true);

    // Explicitly wire in our "Spring" async executor which in turn is configured with our own task executor.
    configuration.setAsyncExecutorEnabled(true);
    configuration.setAsyncExecutor(activitiAsyncExecutor);

    // Set the allowed beans to an empty map so the Activiti workflows won't be able to call any arbitrary bean (e.g. services, etc.).
    configuration.setBeans(new HashMap<>());

    // Explicitly set a custom herd delegate interceptor that allows us to autowire in Spring beans onto our Java delegate tasks.
    configuration.setDelegateInterceptor(herdDelegateInterceptor);

    // Explicitly set a custom herd command invoker that allows us to perform specialized logging for asynchronous tasks.
    configuration.setCommandInvoker(herdCommandInvoker);

    // Initialize the scripting engines.
    initScriptingEngines(configuration);

    // Set the default "from" field for Activiti mail
    String mailServerDefaultFrom = configurationHelper.getProperty(ConfigurationValue.ACTIVITI_DEFAULT_MAIL_FROM);
    configuration.setMailServerDefaultFrom(mailServerDefaultFrom);
    // Set the mail server hostname for Activiti mail
    String mailServerHost = configurationHelper.getProperty(ConfigurationValue.ACTIVITI_MAIL_SERVER_HOST);
    configuration.setMailServerHost(mailServerHost);
    // Set the mail server port number for Activiti mail
    int mailServerPort = configurationHelper.getProperty(ConfigurationValue.ACTIVITI_MAIL_SERVER_PORT, Integer.class);
    configuration.setMailServerPort(mailServerPort);
    LOGGER.info("Activiti mail server configurations: activitiMailServerDefaultFrom=\"{}\" activitiMailServerHost=\"{}\" activitiMailServerPort={}",
        mailServerDefaultFrom, mailServerHost, mailServerPort);

    // Attach a custom herd process engine configurator that will allow us to modify the configuration before the engine is built.
    List<ProcessEngineConfigurator> herdConfigurators = new ArrayList<>();
    herdConfigurators.add(herdProcessEngineConfigurator);
    configuration.setConfigurators(herdConfigurators);

    // Return the configuration.
    return configuration;
}