Search in sources :

Example 11 with ProcessEngineImpl

use of org.camunda.bpm.engine.impl.ProcessEngineImpl in project camunda-bpm-platform by camunda.

the class SequentialJobAcquisitionRunnable method run.

public synchronized void run() {
    LOG.startingToAcquireJobs(jobExecutor.getName());
    JobAcquisitionStrategy acquisitionStrategy = initializeAcquisitionStrategy();
    while (!isInterrupted) {
        acquisitionContext.reset();
        acquisitionContext.setAcquisitionTime(System.currentTimeMillis());
        Iterator<ProcessEngineImpl> engineIterator = jobExecutor.engineIterator();
        try {
            while (engineIterator.hasNext()) {
                ProcessEngineImpl currentProcessEngine = engineIterator.next();
                if (!jobExecutor.hasRegisteredEngine(currentProcessEngine)) {
                    // if engine has been unregistered meanwhile
                    continue;
                }
                AcquiredJobs acquiredJobs = acquireJobs(acquisitionContext, acquisitionStrategy, currentProcessEngine);
                executeJobs(acquisitionContext, currentProcessEngine, acquiredJobs);
            }
        } catch (Exception e) {
            LOG.exceptionDuringJobAcquisition(e);
            acquisitionContext.setAcquisitionException(e);
        }
        acquisitionContext.setJobAdded(isJobAdded);
        configureNextAcquisitionCycle(acquisitionContext, acquisitionStrategy);
        // The clear had to be done after the configuration, since a hint can be
        // appear in the suspend and the flag shouldn't be cleaned in this case.
        // The loop will restart after suspend with the isJobAdded flag and
        // reconfigure with this flag
        clearJobAddedNotification();
        long waitTime = acquisitionStrategy.getWaitTime();
        // wait the requested wait time minus the time that acquisition itself took
        // this makes the intervals of job acquisition more constant and therefore predictable
        waitTime = Math.max(0, (acquisitionContext.getAcquisitionTime() + waitTime) - System.currentTimeMillis());
        suspendAcquisition(waitTime);
    }
    LOG.stoppedJobAcquisition(jobExecutor.getName());
}
Also used : ProcessEngineImpl(org.camunda.bpm.engine.impl.ProcessEngineImpl)

Example 12 with ProcessEngineImpl

use of org.camunda.bpm.engine.impl.ProcessEngineImpl in project camunda-bpm-platform by camunda.

the class DatabaseHistoryPropertyAutoTest method secondEngineCopiesHistoryLevelFromFirst.

@Test
public void secondEngineCopiesHistoryLevelFromFirst() {
    // given
    buildEngine(config("true", ProcessEngineConfiguration.HISTORY_FULL));
    // when
    ProcessEngineImpl processEngineTwo = buildEngine(config("true", ProcessEngineConfiguration.HISTORY_AUTO));
    // then
    assertThat(processEngineTwo.getProcessEngineConfiguration().getHistory(), is(ProcessEngineConfiguration.HISTORY_AUTO));
    assertThat(processEngineTwo.getProcessEngineConfiguration().getHistoryLevel(), is(HistoryLevel.HISTORY_LEVEL_FULL));
}
Also used : ProcessEngineImpl(org.camunda.bpm.engine.impl.ProcessEngineImpl) Test(org.junit.Test)

Example 13 with ProcessEngineImpl

use of org.camunda.bpm.engine.impl.ProcessEngineImpl in project camunda-bpm-platform by camunda.

the class DatabaseHistoryPropertyAutoTest method buildEngine.

protected ProcessEngineImpl buildEngine(ProcessEngineConfigurationImpl engineConfiguration) {
    ProcessEngineImpl engine = (ProcessEngineImpl) engineConfiguration.buildProcessEngine();
    processEngines.add(engine);
    return engine;
}
Also used : ProcessEngineImpl(org.camunda.bpm.engine.impl.ProcessEngineImpl)

Example 14 with ProcessEngineImpl

use of org.camunda.bpm.engine.impl.ProcessEngineImpl in project camunda-bpm-platform by camunda.

the class DmnDisabledTest method createProcessEngineImpl.

protected static ProcessEngineImpl createProcessEngineImpl(boolean dmnEnabled) {
    StandaloneInMemProcessEngineConfiguration config = (StandaloneInMemProcessEngineConfiguration) new CustomStandaloneInMemProcessEngineConfiguration().setProcessEngineName("database-dmn-test-engine").setDatabaseSchemaUpdate("false").setHistory(ProcessEngineConfiguration.HISTORY_FULL).setJdbcUrl("jdbc:h2:mem:DatabaseDmnTest");
    config.setDmnEnabled(dmnEnabled);
    return (ProcessEngineImpl) config.buildProcessEngine();
}
Also used : StandaloneInMemProcessEngineConfiguration(org.camunda.bpm.engine.impl.cfg.StandaloneInMemProcessEngineConfiguration) ProcessEngineImpl(org.camunda.bpm.engine.impl.ProcessEngineImpl)

Example 15 with ProcessEngineImpl

use of org.camunda.bpm.engine.impl.ProcessEngineImpl in project camunda-bpm-platform by camunda.

the class PurgeDatabaseTest method assertAndEnsureCleanDb.

/**
 * Ensures that the database is clean after the test. This means the test has to remove
 * all resources it entered to the database.
 * If the DB is not clean, it is cleaned by performing a create a drop.
 *
 * @param processEngine the {@link ProcessEngine} to check
 * @param fail if true the method will throw an {@link AssertionError} if the database is not clean
 * @return the database summary if fail is set to false or null if database was clean
 * @throws AssertionError if the database was not clean and fail is set to true
 */
public static void assertAndEnsureCleanDb(ProcessEngine processEngine) {
    ProcessEngineConfigurationImpl processEngineConfiguration = ((ProcessEngineImpl) processEngine).getProcessEngineConfiguration();
    String databaseTablePrefix = processEngineConfiguration.getDatabaseTablePrefix().trim();
    Map<String, Long> tableCounts = processEngine.getManagementService().getTableCount();
    StringBuilder outputMessage = new StringBuilder();
    for (String tableName : tableCounts.keySet()) {
        String tableNameWithoutPrefix = tableName.replace(databaseTablePrefix, "");
        if (!TABLENAMES_EXCLUDED_FROM_DB_CLEAN_CHECK.contains(tableNameWithoutPrefix)) {
            Long count = tableCounts.get(tableName);
            if (count != 0L) {
                outputMessage.append("\t").append(tableName).append(": ").append(count).append(" record(s)\n");
            }
        }
    }
    if (outputMessage.length() > 0) {
        outputMessage.insert(0, "DB NOT CLEAN: \n");
        /**
         * skip drop and recreate if a table prefix is used
         */
        if (databaseTablePrefix.isEmpty()) {
            processEngineConfiguration.getCommandExecutorSchemaOperations().execute(new Command<Object>() {

                public Object execute(CommandContext commandContext) {
                    PersistenceSession persistenceSession = commandContext.getSession(PersistenceSession.class);
                    persistenceSession.dbSchemaDrop();
                    persistenceSession.dbSchemaCreate();
                    HistoryLevelSetupCommand.dbCreateHistoryLevel(commandContext);
                    return null;
                }
            });
        }
        Assert.fail(outputMessage.toString());
    }
}
Also used : CommandContext(org.camunda.bpm.engine.impl.interceptor.CommandContext) PersistenceSession(org.camunda.bpm.engine.impl.db.PersistenceSession) ProcessEngineConfigurationImpl(org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl) ProcessEngineImpl(org.camunda.bpm.engine.impl.ProcessEngineImpl)

Aggregations

ProcessEngineImpl (org.camunda.bpm.engine.impl.ProcessEngineImpl)17 ProcessEngineConfigurationImpl (org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl)7 CommandContext (org.camunda.bpm.engine.impl.interceptor.CommandContext)5 CommandExecutor (org.camunda.bpm.engine.impl.interceptor.CommandExecutor)3 Charset (java.nio.charset.Charset)2 CachePurgeReport (org.camunda.bpm.engine.impl.persistence.deploy.cache.CachePurgeReport)2 Test (org.junit.Test)2 Date (java.util.Date)1 ProcessEngine (org.camunda.bpm.engine.ProcessEngine)1 ProcessEngineConfiguration (org.camunda.bpm.engine.ProcessEngineConfiguration)1 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)1 RepositoryService (org.camunda.bpm.engine.RepositoryService)1 ManagementServiceImpl (org.camunda.bpm.engine.impl.ManagementServiceImpl)1 StandaloneInMemProcessEngineConfiguration (org.camunda.bpm.engine.impl.cfg.StandaloneInMemProcessEngineConfiguration)1 AcquireJobsCmd (org.camunda.bpm.engine.impl.cmd.AcquireJobsCmd)1 PersistenceSession (org.camunda.bpm.engine.impl.db.PersistenceSession)1 JobExecutor (org.camunda.bpm.engine.impl.jobexecutor.JobExecutor)1 DatabasePurgeReport (org.camunda.bpm.engine.impl.management.DatabasePurgeReport)1 PurgeReport (org.camunda.bpm.engine.impl.management.PurgeReport)1 Deployment (org.camunda.bpm.engine.repository.Deployment)1