Java Code Examples for org.camunda.bpm.engine.ProcessEngine#getProcessEngineConfiguration()

The following examples show how to use org.camunda.bpm.engine.ProcessEngine#getProcessEngineConfiguration() . 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: CamundaReactor.java    From camunda-bpm-reactor with Apache License 2.0 6 votes vote down vote up
/**
 * Gets EventBus from given process engine via plugin.
 *
 * @param processEngine the process engine
 * @return the camunda eventBus
 */
public static CamundaEventBus eventBus(final ProcessEngine processEngine) {
  final ProcessEngineConfigurationImpl configuration = (ProcessEngineConfigurationImpl) processEngine.getProcessEngineConfiguration();
  final List<ProcessEnginePlugin> plugins = Optional.ofNullable(configuration.getProcessEnginePlugins()).orElse(Collections.EMPTY_LIST);

  final Function<List<ProcessEnginePlugin>, Optional<CamundaEventBus>> filterReactorPlugin = l -> l.stream()
    .filter(plugin -> plugin instanceof ReactorProcessEnginePlugin)
    .map(ReactorProcessEnginePlugin.class::cast)
    .map(ReactorProcessEnginePlugin::getEventBus)
    .findFirst();

  Optional<CamundaEventBus> reactorProcessEnginePlugin = filterReactorPlugin.apply(plugins);
  if (reactorProcessEnginePlugin.isPresent()) {
    return reactorProcessEnginePlugin.get();
  }

  return plugins.stream()
    .filter(plugin -> plugin instanceof CompositeProcessEnginePlugin)
    .map(CompositeProcessEnginePlugin.class::cast)
    .map(CompositeProcessEnginePlugin::getPlugins)
    .map(filterReactorPlugin)
    .flatMap(o -> o.map(Stream::of).orElseGet(Stream::empty))
    .findFirst()
    .orElseThrow(illegalState("No eventBus found. Make sure the Reactor plugin is configured correctly."));
}
 
Example 2
Source File: InvoiceProcessApplication.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
/**
 * In a @PostDeploy Hook you can interact with the process engine and access
 * the processes the application has deployed.
 */
@PostDeploy
public void startFirstProcess(ProcessEngine processEngine) {
  createUsers(processEngine);

  //enable metric reporting
  ProcessEngineConfigurationImpl processEngineConfiguration = (ProcessEngineConfigurationImpl) processEngine.getProcessEngineConfiguration();
  processEngineConfiguration.setDbMetricsReporterActivate(true);
  processEngineConfiguration.getDbMetricsReporter().setReporterId("REPORTER");

  startProcessInstances(processEngine, "invoice", 1);
  startProcessInstances(processEngine, "invoice", null);

  //disable reporting
  processEngineConfiguration.setDbMetricsReporterActivate(false);
}
 
Example 3
Source File: PlatformJobExecutorActivateTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldNotAutoActivateIfConfigured() {

  // given
  JobExecutorXmlImpl jobExecutorXml = defineJobExecutor();
  ProcessEngineXmlImpl processEngineXml = defineProcessEngine();
  // activate set to false
  processEngineXml.getProperties()
    .put("jobExecutorActivate", "false");
  BpmPlatformXmlImpl bpmPlatformXml = new BpmPlatformXmlImpl(jobExecutorXml, Collections.<ProcessEngineXml>singletonList(processEngineXml));

  // when
  deployPlatform(bpmPlatformXml);

  try {
    ProcessEngine processEngine = getProcessEngine(ENGINE_NAME);
    ProcessEngineConfigurationImpl processEngineConfiguration = (ProcessEngineConfigurationImpl) processEngine.getProcessEngineConfiguration();
    // then
    assertEquals(false, processEngineConfiguration.getJobExecutor().isActive());
  }
  finally {
    undeployPlatform();
  }
}
 
Example 4
Source File: TestHelper.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
private static boolean databaseCheck(ProcessEngine processEngine, RequiredDatabase annotation) {

    ProcessEngineConfigurationImpl processEngineConfiguration = (ProcessEngineConfigurationImpl) processEngine.getProcessEngineConfiguration();
    String actualDbType = processEngineConfiguration.getDbSqlSessionFactory().getDatabaseType();

    String[] excludes = annotation.excludes();

    if (excludes != null) {
      for (String exclude : excludes) {
        if (exclude.equals(actualDbType)) {
          return false;
        }
      }
    }

    return true;
  }
 
Example 5
Source File: PlatformJobExecutorActivateTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldAutoActivateIfNoPropertySet() {

  // given
  JobExecutorXmlImpl jobExecutorXml = defineJobExecutor();
  ProcessEngineXmlImpl processEngineXml = defineProcessEngine();
  BpmPlatformXmlImpl bpmPlatformXml = new BpmPlatformXmlImpl(jobExecutorXml, Collections.<ProcessEngineXml>singletonList(processEngineXml));

  // when
  deployPlatform(bpmPlatformXml);

  try {
    ProcessEngine processEngine = getProcessEngine(ENGINE_NAME);
    ProcessEngineConfigurationImpl processEngineConfiguration = (ProcessEngineConfigurationImpl) processEngine.getProcessEngineConfiguration();
    // then
    assertEquals(true, processEngineConfiguration.getJobExecutor().isActive());
  }
  finally {
    undeployPlatform();
  }


}
 
Example 6
Source File: HistoryCleanupOnEngineBootstrapTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testHistoryCleanupJobScheduled() throws ParseException {

  final ProcessEngineConfigurationImpl standaloneInMemProcessEngineConfiguration = (ProcessEngineConfigurationImpl)ProcessEngineConfiguration.createStandaloneInMemProcessEngineConfiguration();
  standaloneInMemProcessEngineConfiguration.setHistoryCleanupBatchWindowStartTime("23:00");
  standaloneInMemProcessEngineConfiguration.setHistoryCleanupBatchWindowEndTime("01:00");
  standaloneInMemProcessEngineConfiguration.setJdbcUrl("jdbc:h2:mem:camunda" + getClass().getSimpleName() + "testHistoryCleanupJobScheduled");

  ProcessEngine engine = standaloneInMemProcessEngineConfiguration
    .buildProcessEngine();

  try {
    final List<Job> historyCleanupJobs = engine.getHistoryService().findHistoryCleanupJobs();
    assertFalse(historyCleanupJobs.isEmpty());
    final ProcessEngineConfigurationImpl processEngineConfiguration = (ProcessEngineConfigurationImpl) engine.getProcessEngineConfiguration();
    for (Job historyCleanupJob : historyCleanupJobs) {
      assertEquals(processEngineConfiguration.getBatchWindowManager().getCurrentOrNextBatchWindow(ClockUtil.getCurrentTime(), processEngineConfiguration).getStart(), historyCleanupJob.getDuedate());
    }
  } finally {
    closeProcessEngine(engine);
  }
}
 
Example 7
Source File: HistoryCleanupOnEngineBootstrapTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
protected void closeProcessEngine(ProcessEngine processEngine) {
  ProcessEngineConfigurationImpl configuration = (ProcessEngineConfigurationImpl) processEngine.getProcessEngineConfiguration();
  final HistoryService historyService = processEngine.getHistoryService();
  configuration.getCommandExecutorTxRequired().execute((Command<Void>) commandContext -> {

    List<Job> jobs = historyService.findHistoryCleanupJobs();
    for (Job job: jobs) {
      commandContext.getJobManager().deleteJob((JobEntity) job);
      commandContext.getHistoricJobLogManager().deleteHistoricJobLogByJobId(job.getId());
    }

    //cleanup "detached" historic job logs
    final List<HistoricJobLog> list = historyService.createHistoricJobLogQuery().list();
    for (HistoricJobLog jobLog: list) {
      commandContext.getHistoricJobLogManager().deleteHistoricJobLogByJobId(jobLog.getJobId());
    }

    commandContext.getMeterLogManager().deleteAll();

    return null;
  });

  processEngine.close();
}
 
Example 8
Source File: EnterLicenseKeyConfiguration.java    From camunda-bpm-spring-boot-starter with Apache License 2.0 5 votes vote down vote up
@Override
public void postProcessEngineBuild(ProcessEngine processEngine) {
  // if version is not enterprise
  if (!version.isEnterprise()) {
    return;
  }

  // try to load the license from the provided URL
  URL fileUrl = camundaBpmProperties.getLicenseFile();
  Optional<String> licenseKey = readLicenseKeyFromUrl(fileUrl);

  // if not, try to find the license key on the classpath
  if (!licenseKey.isPresent()) {
    fileUrl = EnterLicenseKeyConfiguration.class.getClassLoader().getResource(DEFAULT_LICENSE_FILE);
    licenseKey = readLicenseKeyFromUrl(fileUrl);
  }

  // if no license key is provided, return
  if (!licenseKey.isPresent()) {
    return;
  }

  // if a license key is already present in the database, return
  Optional<String> existingLicenseKey = Optional.ofNullable(getLicenseKey(processEngine));
  if (existingLicenseKey.isPresent()) {
    return;
  }

  Optional<String> finalLicenseKey = licenseKey;
  ProcessEngineConfigurationImpl processEngineConfiguration =
    (ProcessEngineConfigurationImpl) processEngine.getProcessEngineConfiguration();
  processEngineConfiguration.getCommandExecutorTxRequired().execute((Command<Void>) commandContext -> {
    setLicenseKey(processEngine, finalLicenseKey.get());
    return null;
  });

  LOG.enterLicenseKey(fileUrl);
}
 
Example 9
Source File: TestJobExecutorActivateFalse_JBOSS.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldNotActiateJobExecutor() {

  ProcessEngine processEngine = processEngineService.getProcessEngine("jobExecutorActivate-FALSE-engine");
  ProcessEngineConfiguration configuration = processEngine.getProcessEngineConfiguration();
  JobExecutor jobExecutor = ((ProcessEngineConfigurationImpl)configuration).getJobExecutor();
  assertFalse(jobExecutor.isActive());

  processEngine = processEngineService.getProcessEngine("jobExecutorActivate-UNDEFINED-engine");
  configuration = processEngine.getProcessEngineConfiguration();
  jobExecutor = ((ProcessEngineConfigurationImpl)configuration).getJobExecutor();
  assertTrue(jobExecutor.isActive());

}
 
Example 10
Source File: DefaultLoadGenerator.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws InterruptedException {

    final Properties properties = PerfTestProcessEngine.loadProperties();
    final ProcessEngine processEngine = PerfTestProcessEngine.getInstance();

    final LoadGeneratorConfiguration config = new LoadGeneratorConfiguration();
    config.setColor(Boolean.parseBoolean(properties.getProperty("loadGenerator.colorOutput", "false")));
    config.setNumberOfIterations(Integer.parseInt(properties.getProperty("loadGenerator.numberOfIterations", "10000")));

    final List<BpmnModelInstance> modelInstances = createProcesses(config.getNumberOfIterations());

    Runnable[] setupTasks = new Runnable[] {
        new DeployModelInstancesTask(processEngine, modelInstances)
    };
    config.setSetupTasks(setupTasks);

    ProcessEngineConfigurationImpl processEngineConfiguration = (ProcessEngineConfigurationImpl) processEngine.getProcessEngineConfiguration();
    processEngineConfiguration.setMetricsEnabled(true);
    processEngineConfiguration.getDbMetricsReporter().setReporterId(REPORTER_ID);
    final Runnable[] workerRunnables = new Runnable[2];
    Process process = modelInstances.get(0).getModelElementsByType(Process.class).iterator().next();
    String processDefKey = process.getId();
    workerRunnables[0] = new StartProcessInstanceTask(processEngine, processDefKey);
    workerRunnables[1] = new GenerateMetricsTask(processEngine);
    config.setWorkerTasks(workerRunnables);

    new LoadGenerator(config).execute();

    System.out.println(processEngine.getHistoryService().createHistoricProcessInstanceQuery().count()+ " Process Instances in DB");
    processEngineConfiguration.setMetricsEnabled(false);
  }
 
Example 11
Source File: ExecutionTree.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public static ExecutionTree forExecution(final String executionId, ProcessEngine processEngine) {
  ProcessEngineConfigurationImpl configuration = (ProcessEngineConfigurationImpl)
      processEngine.getProcessEngineConfiguration();

  CommandExecutor commandExecutor = configuration.getCommandExecutorTxRequired();

  ExecutionTree executionTree = commandExecutor.execute(new Command<ExecutionTree>() {
    public ExecutionTree execute(CommandContext commandContext) {
      ExecutionEntity execution = commandContext.getExecutionManager().findExecutionById(executionId);
      return ExecutionTree.forExecution(execution);
    }
  });

  return executionTree;
}
 
Example 12
Source File: TestHelper.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public static String assertAndEnsureNoProcessApplicationsRegistered(ProcessEngine processEngine) {
  ProcessEngineConfigurationImpl engineConfiguration = (ProcessEngineConfigurationImpl) processEngine.getProcessEngineConfiguration();
  ProcessApplicationManager processApplicationManager = engineConfiguration.getProcessApplicationManager();

  if (processApplicationManager.hasRegistrations()) {
    processApplicationManager.clearRegistrations();
    return "There are still process applications registered";
  }
  else {
    return null;
  }

}
 
Example 13
Source File: TestHelper.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
private static boolean historyLevelCheck(ProcessEngine processEngine, RequiredHistoryLevel annotation) {
  ProcessEngineConfigurationImpl processEngineConfiguration = (ProcessEngineConfigurationImpl) processEngine.getProcessEngineConfiguration();

  HistoryLevel requiredHistoryLevel = getHistoryLevelForName(processEngineConfiguration.getHistoryLevels(), annotation.value());
  HistoryLevel currentHistoryLevel = processEngineConfiguration.getHistoryLevel();

  return currentHistoryLevel.getId() >= requiredHistoryLevel.getId();
}
 
Example 14
Source File: GenerateMetricsTask.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
public GenerateMetricsTask(ProcessEngine processEngine) {
  this.processEngineConfiguration = (ProcessEngineConfigurationImpl) processEngine.getProcessEngineConfiguration();
}
 
Example 15
Source File: CamundaSpringBootUtil.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
public static SpringProcessEngineConfiguration get(ProcessEngine processEngine) {
  return (SpringProcessEngineConfiguration) processEngine.getProcessEngineConfiguration();
}
 
Example 16
Source File: SentryScenarioTest.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
protected CaseSentryPartQueryImpl createCaseSentryPartQuery() {
  ProcessEngine processEngine = rule.getProcessEngine();
  ProcessEngineConfigurationImpl processEngineConfiguration = (ProcessEngineConfigurationImpl) processEngine.getProcessEngineConfiguration();
  CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutorTxRequiresNew();
  return new CaseSentryPartQueryImpl(commandExecutor);
}
 
Example 17
Source File: CamundaSpringBootUtil.java    From camunda-bpm-spring-boot-starter with Apache License 2.0 4 votes vote down vote up
public static SpringProcessEngineConfiguration get(ProcessEngine processEngine) {
  return (SpringProcessEngineConfiguration) processEngine.getProcessEngineConfiguration();
}
 
Example 18
Source File: HistoryCleanupScenario.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
@DescribesScenario("initHistoryCleanup")
@Times(1)
public static ScenarioSetup initHistoryCleanup() {
  return new ScenarioSetup() {
    public void execute(ProcessEngine engine, String scenarioName) {

      for (int i = 0; i < 60; i++) {
        if (i % 4 == 0) {
          ClockUtil.setCurrentTime(FIXED_DATE);

          engine.getRuntimeService().startProcessInstanceByKey("oneTaskProcess_710", "HistoryCleanupScenario");

          String taskId = engine.getTaskService().createTaskQuery()
            .processInstanceBusinessKey("HistoryCleanupScenario")
            .singleResult()
            .getId();


          ClockUtil.setCurrentTime(addMinutes(FIXED_DATE, i));

          engine.getTaskService().complete(taskId);
        }
      }

      ProcessEngineConfigurationImpl configuration =
        ((ProcessEngineConfigurationImpl) engine.getProcessEngineConfiguration());

      configuration.setHistoryCleanupBatchWindowStartTime("13:00");
      configuration.setHistoryCleanupBatchWindowEndTime("14:00");
      configuration.setHistoryCleanupDegreeOfParallelism(3);
      configuration.initHistoryCleanup();

      engine.getHistoryService().cleanUpHistoryAsync();

      List<Job> jobs = engine.getHistoryService().findHistoryCleanupJobs();

      for (int i = 0; i < 4; i++) {
        Job jobOne = jobs.get(0);
        engine.getManagementService().executeJob(jobOne.getId());

        Job jobTwo = jobs.get(1);
        engine.getManagementService().executeJob(jobTwo.getId());

        Job jobThree = jobs.get(2);
        engine.getManagementService().executeJob(jobThree.getId());
      }

      ClockUtil.reset();
    }
  };
}