Search in sources :

Example 1 with CommandExecutor

use of org.activiti.engine.impl.interceptor.CommandExecutor in project Activiti by Activiti.

the class JobQueryTest method createJobWithoutExceptionMsg.

private void createJobWithoutExceptionMsg() {
    CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutor();
    commandExecutor.execute(new Command<Void>() {

        public Void execute(CommandContext commandContext) {
            JobEntityManager jobManager = commandContext.getJobEntityManager();
            timerEntity = new TimerEntity();
            timerEntity.setLockOwner(UUID.randomUUID().toString());
            timerEntity.setDuedate(new Date());
            timerEntity.setRetries(0);
            StringWriter stringWriter = new StringWriter();
            NullPointerException exception = new NullPointerException();
            exception.printStackTrace(new PrintWriter(stringWriter));
            timerEntity.setExceptionStacktrace(stringWriter.toString());
            jobManager.insert(timerEntity);
            assertNotNull(timerEntity.getId());
            return null;
        }
    });
}
Also used : JobEntityManager(org.activiti.engine.impl.persistence.entity.JobEntityManager) CommandContext(org.activiti.engine.impl.interceptor.CommandContext) StringWriter(java.io.StringWriter) TimerEntity(org.activiti.engine.impl.persistence.entity.TimerEntity) CommandExecutor(org.activiti.engine.impl.interceptor.CommandExecutor) Date(java.util.Date) PrintWriter(java.io.PrintWriter)

Example 2 with CommandExecutor

use of org.activiti.engine.impl.interceptor.CommandExecutor in project Activiti by Activiti.

the class ProcessEngineConfigurationImpl method initIdGenerator.

// id generator /////////////////////////////////////////////////////////////
protected void initIdGenerator() {
    if (idGenerator == null) {
        CommandExecutor idGeneratorCommandExecutor = null;
        if (idGeneratorDataSource != null) {
            ProcessEngineConfigurationImpl processEngineConfiguration = new StandaloneProcessEngineConfiguration();
            processEngineConfiguration.setDataSource(idGeneratorDataSource);
            processEngineConfiguration.setDatabaseSchemaUpdate(DB_SCHEMA_UPDATE_FALSE);
            processEngineConfiguration.init();
            idGeneratorCommandExecutor = processEngineConfiguration.getCommandExecutor();
        } else if (idGeneratorDataSourceJndiName != null) {
            ProcessEngineConfigurationImpl processEngineConfiguration = new StandaloneProcessEngineConfiguration();
            processEngineConfiguration.setDataSourceJndiName(idGeneratorDataSourceJndiName);
            processEngineConfiguration.setDatabaseSchemaUpdate(DB_SCHEMA_UPDATE_FALSE);
            processEngineConfiguration.init();
            idGeneratorCommandExecutor = processEngineConfiguration.getCommandExecutor();
        } else {
            idGeneratorCommandExecutor = getCommandExecutor();
        }
        DbIdGenerator dbIdGenerator = new DbIdGenerator();
        dbIdGenerator.setIdBlockSize(idBlockSize);
        dbIdGenerator.setCommandExecutor(idGeneratorCommandExecutor);
        dbIdGenerator.setCommandConfig(getDefaultCommandConfig().transactionRequiresNew());
        idGenerator = dbIdGenerator;
    }
}
Also used : CommandExecutor(org.activiti.engine.impl.interceptor.CommandExecutor) DbIdGenerator(org.activiti.engine.impl.db.DbIdGenerator)

Example 3 with CommandExecutor

use of org.activiti.engine.impl.interceptor.CommandExecutor in project Activiti by Activiti.

the class StandaloneMybatisTransactionContext method fireTransactionEvent.

/**
   * Fires the event for the provided {@link TransactionState}.
   * 
   * @param transactionState The {@link TransactionState} for which the listeners will be called.
   * @param executeInNewContext If true, the listeners will be called in a new command context.
   *                            This is needed for example when firing the {@link TransactionState#COMMITTED}
   *                            event: the transaction is already committed and executing logic in the same
   *                            context could lead to strange behaviour (for example doing a {@link SqlSession#update(String)}
   *                            would actually roll back the update (as the MyBatis context is already committed
   *                            and the internal flags have not been correctly set).
   */
protected void fireTransactionEvent(TransactionState transactionState, boolean executeInNewContext) {
    if (stateTransactionListeners == null) {
        return;
    }
    final List<TransactionListener> transactionListeners = stateTransactionListeners.get(transactionState);
    if (transactionListeners == null) {
        return;
    }
    if (executeInNewContext) {
        CommandExecutor commandExecutor = commandContext.getProcessEngineConfiguration().getCommandExecutor();
        CommandConfig commandConfig = new CommandConfig(false, TransactionPropagation.REQUIRES_NEW);
        commandExecutor.execute(commandConfig, new Command<Void>() {

            public Void execute(CommandContext commandContext) {
                executeTransactionListeners(transactionListeners, commandContext);
                return null;
            }
        });
    } else {
        executeTransactionListeners(transactionListeners, commandContext);
    }
}
Also used : TransactionListener(org.activiti.engine.impl.cfg.TransactionListener) CommandConfig(org.activiti.engine.impl.interceptor.CommandConfig) CommandContext(org.activiti.engine.impl.interceptor.CommandContext) CommandExecutor(org.activiti.engine.impl.interceptor.CommandExecutor)

Example 4 with CommandExecutor

use of org.activiti.engine.impl.interceptor.CommandExecutor in project Activiti by Activiti.

the class DbSchemaDrop method main.

public static void main(String[] args) {
    ProcessEngineImpl processEngine = (ProcessEngineImpl) ProcessEngines.getDefaultProcessEngine();
    CommandExecutor commandExecutor = processEngine.getProcessEngineConfiguration().getCommandExecutor();
    CommandConfig config = new CommandConfig().transactionNotSupported();
    commandExecutor.execute(config, new Command<Object>() {

        public Object execute(CommandContext commandContext) {
            commandContext.getSession(DbSqlSession.class).dbSchemaDrop();
            return null;
        }
    });
}
Also used : CommandConfig(org.activiti.engine.impl.interceptor.CommandConfig) CommandContext(org.activiti.engine.impl.interceptor.CommandContext) CommandExecutor(org.activiti.engine.impl.interceptor.CommandExecutor) ProcessEngineImpl(org.activiti.engine.impl.ProcessEngineImpl)

Example 5 with CommandExecutor

use of org.activiti.engine.impl.interceptor.CommandExecutor in project Activiti by Activiti.

the class AcquireJobsRunnableImpl method run.

public synchronized void run() {
    log.info("{} starting to acquire jobs", jobExecutor.getName());
    final CommandExecutor commandExecutor = jobExecutor.getCommandExecutor();
    while (!isInterrupted) {
        isJobAdded = false;
        int maxJobsPerAcquisition = jobExecutor.getMaxJobsPerAcquisition();
        try {
            AcquiredJobs acquiredJobs = commandExecutor.execute(jobExecutor.getAcquireJobsCmd());
            for (List<String> jobIds : acquiredJobs.getJobIdBatches()) {
                jobExecutor.executeJobs(jobIds);
            }
            // if all jobs were executed
            millisToWait = jobExecutor.getWaitTimeInMillis();
            int jobsAcquired = acquiredJobs.getJobIdBatches().size();
            if (jobsAcquired >= maxJobsPerAcquisition) {
                millisToWait = 0;
            }
        } catch (ActivitiOptimisticLockingException optimisticLockingException) {
            // See https://activiti.atlassian.net/browse/ACT-1390
            if (log.isDebugEnabled()) {
                log.debug("Optimistic locking exception during job acquisition. If you have multiple job executors running against the same database, " + "this exception means that this thread tried to acquire a job, which already was acquired by another job executor acquisition thread." + "This is expected behavior in a clustered environment. " + "You can ignore this message if you indeed have multiple job executor acquisition threads running against the same database. " + "Exception message: {}", optimisticLockingException.getMessage());
            }
        } catch (Throwable e) {
            log.error("exception during job acquisition: {}", e.getMessage(), e);
            millisToWait = jobExecutor.getWaitTimeInMillis();
        }
        if ((millisToWait > 0) && (!isJobAdded)) {
            try {
                if (log.isDebugEnabled()) {
                    log.debug("job acquisition thread sleeping for {} millis", millisToWait);
                }
                synchronized (MONITOR) {
                    if (!isInterrupted) {
                        isWaiting.set(true);
                        MONITOR.wait(millisToWait);
                    }
                }
                if (log.isDebugEnabled()) {
                    log.debug("job acquisition thread woke up");
                }
            } catch (InterruptedException e) {
                if (log.isDebugEnabled()) {
                    log.debug("job acquisition wait interrupted");
                }
            } finally {
                isWaiting.set(false);
            }
        }
    }
    log.info("{} stopped job acquisition", jobExecutor.getName());
}
Also used : CommandExecutor(org.activiti.engine.impl.interceptor.CommandExecutor) ActivitiOptimisticLockingException(org.activiti.engine.ActivitiOptimisticLockingException)

Aggregations

CommandExecutor (org.activiti.engine.impl.interceptor.CommandExecutor)36 CommandContext (org.activiti.engine.impl.interceptor.CommandContext)18 Deployment (org.activiti.engine.test.Deployment)11 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)10 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)8 SetProcessDefinitionVersionCmd (org.activiti.engine.impl.cmd.SetProcessDefinitionVersionCmd)8 CommandConfig (org.activiti.engine.impl.interceptor.CommandConfig)7 Date (java.util.Date)6 Execution (org.activiti.engine.runtime.Execution)6 DbSqlSession (org.activiti.engine.impl.db.DbSqlSession)5 JobEntity (org.activiti.engine.impl.persistence.entity.JobEntity)5 TimerEntity (org.activiti.engine.impl.persistence.entity.TimerEntity)5 ActivitiOptimisticLockingException (org.activiti.engine.ActivitiOptimisticLockingException)4 ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)4 ActivitiException (org.activiti.engine.ActivitiException)3 ProcessEngineImpl (org.activiti.engine.impl.ProcessEngineImpl)3 AcquireTimerJobsCmd (org.activiti.engine.impl.cmd.AcquireTimerJobsCmd)3 JobEntityManager (org.activiti.engine.impl.persistence.entity.JobEntityManager)3 ProcessDefinitionEntity (org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity)3 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)2