Search in sources :

Example 1 with TimerJobEntityManager

use of org.activiti.engine.impl.persistence.entity.TimerJobEntityManager in project Activiti by Activiti.

the class DefaultJobManager method executeTimerJob.

protected void executeTimerJob(JobEntity timerEntity) {
    TimerJobEntityManager timerJobEntityManager = processEngineConfiguration.getTimerJobEntityManager();
    VariableScope variableScope = null;
    if (timerEntity.getExecutionId() != null) {
        variableScope = getExecutionEntityManager().findById(timerEntity.getExecutionId());
    }
    if (variableScope == null) {
        variableScope = NoExecutionVariableScope.getSharedInstance();
    }
    // set endDate if it was set to the definition
    restoreExtraData(timerEntity, variableScope);
    if (timerEntity.getDuedate() != null && !isValidTime(timerEntity, timerEntity.getDuedate(), variableScope)) {
        if (logger.isDebugEnabled()) {
            logger.debug("Timer {} fired. but the dueDate is after the endDate.  Deleting timer.", timerEntity.getId());
        }
        processEngineConfiguration.getJobEntityManager().delete(timerEntity);
        return;
    }
    executeJobHandler(timerEntity);
    processEngineConfiguration.getJobEntityManager().delete(timerEntity);
    if (logger.isDebugEnabled()) {
        logger.debug("Timer {} fired. Deleting timer.", timerEntity.getId());
    }
    if (timerEntity.getRepeat() != null) {
        TimerJobEntity newTimerJobEntity = timerJobEntityManager.createAndCalculateNextTimer(timerEntity, variableScope);
        if (newTimerJobEntity != null) {
            scheduleTimerJob(newTimerJobEntity);
        }
    }
}
Also used : TimerJobEntity(org.activiti.engine.impl.persistence.entity.TimerJobEntity) TimerJobEntityManager(org.activiti.engine.impl.persistence.entity.TimerJobEntityManager) VariableScope(org.activiti.engine.delegate.VariableScope) NoExecutionVariableScope(org.activiti.engine.impl.el.NoExecutionVariableScope)

Example 2 with TimerJobEntityManager

use of org.activiti.engine.impl.persistence.entity.TimerJobEntityManager in project Activiti by Activiti.

the class DestroyScopeOperation method deleteAllScopeJobs.

private void deleteAllScopeJobs(ExecutionEntity scopeExecution, TimerJobEntityManager timerJobEntityManager) {
    Collection<TimerJobEntity> timerJobsForExecution = timerJobEntityManager.findJobsByExecutionId(scopeExecution.getId());
    for (TimerJobEntity job : timerJobsForExecution) {
        timerJobEntityManager.delete(job);
    }
    JobEntityManager jobEntityManager = commandContext.getJobEntityManager();
    Collection<JobEntity> jobsForExecution = jobEntityManager.findJobsByExecutionId(scopeExecution.getId());
    for (JobEntity job : jobsForExecution) {
        jobEntityManager.delete(job);
    }
    SuspendedJobEntityManager suspendedJobEntityManager = commandContext.getSuspendedJobEntityManager();
    Collection<SuspendedJobEntity> suspendedJobsForExecution = suspendedJobEntityManager.findJobsByExecutionId(scopeExecution.getId());
    for (SuspendedJobEntity job : suspendedJobsForExecution) {
        suspendedJobEntityManager.delete(job);
    }
    DeadLetterJobEntityManager deadLetterJobEntityManager = commandContext.getDeadLetterJobEntityManager();
    Collection<DeadLetterJobEntity> deadLetterJobsForExecution = deadLetterJobEntityManager.findJobsByExecutionId(scopeExecution.getId());
    for (DeadLetterJobEntity job : deadLetterJobsForExecution) {
        deadLetterJobEntityManager.delete(job);
    }
}
Also used : DeadLetterJobEntity(org.activiti.engine.impl.persistence.entity.DeadLetterJobEntity) SuspendedJobEntity(org.activiti.engine.impl.persistence.entity.SuspendedJobEntity) JobEntity(org.activiti.engine.impl.persistence.entity.JobEntity) TimerJobEntity(org.activiti.engine.impl.persistence.entity.TimerJobEntity) TimerJobEntityManager(org.activiti.engine.impl.persistence.entity.TimerJobEntityManager) JobEntityManager(org.activiti.engine.impl.persistence.entity.JobEntityManager) DeadLetterJobEntityManager(org.activiti.engine.impl.persistence.entity.DeadLetterJobEntityManager) SuspendedJobEntityManager(org.activiti.engine.impl.persistence.entity.SuspendedJobEntityManager) DeadLetterJobEntityManager(org.activiti.engine.impl.persistence.entity.DeadLetterJobEntityManager) SuspendedJobEntity(org.activiti.engine.impl.persistence.entity.SuspendedJobEntity) SuspendedJobEntityManager(org.activiti.engine.impl.persistence.entity.SuspendedJobEntityManager) TimerJobEntity(org.activiti.engine.impl.persistence.entity.TimerJobEntity) DeadLetterJobEntity(org.activiti.engine.impl.persistence.entity.DeadLetterJobEntity)

Example 3 with TimerJobEntityManager

use of org.activiti.engine.impl.persistence.entity.TimerJobEntityManager in project Activiti by Activiti.

the class DestroyScopeOperation method run.

@Override
public void run() {
    // Find the actual scope that needs to be destroyed.
    // This could be the incoming execution, or the first parent execution where isScope = true
    // Find parent scope execution
    ExecutionEntity scopeExecution = execution.isScope() ? execution : findFirstParentScopeExecution(execution);
    if (scopeExecution == null) {
        throw new ActivitiException("Programmatic error: no parent scope execution found for boundary event");
    }
    ExecutionEntityManager executionEntityManager = commandContext.getExecutionEntityManager();
    deleteAllChildExecutions(executionEntityManager, scopeExecution);
    // Delete all scope tasks
    TaskEntityManager taskEntityManager = commandContext.getTaskEntityManager();
    deleteAllScopeTasks(scopeExecution, taskEntityManager);
    // Delete all scope jobs
    TimerJobEntityManager timerJobEntityManager = commandContext.getTimerJobEntityManager();
    deleteAllScopeJobs(scopeExecution, timerJobEntityManager);
    // Remove variables associated with this scope
    VariableInstanceEntityManager variableInstanceEntityManager = commandContext.getVariableInstanceEntityManager();
    removeAllVariablesFromScope(scopeExecution, variableInstanceEntityManager);
    commandContext.getHistoryManager().recordActivityEnd(scopeExecution, scopeExecution.getDeleteReason());
    executionEntityManager.delete(scopeExecution);
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) ExecutionEntity(org.activiti.engine.impl.persistence.entity.ExecutionEntity) TaskEntityManager(org.activiti.engine.impl.persistence.entity.TaskEntityManager) ExecutionEntityManager(org.activiti.engine.impl.persistence.entity.ExecutionEntityManager) TimerJobEntityManager(org.activiti.engine.impl.persistence.entity.TimerJobEntityManager) VariableInstanceEntityManager(org.activiti.engine.impl.persistence.entity.VariableInstanceEntityManager)

Example 4 with TimerJobEntityManager

use of org.activiti.engine.impl.persistence.entity.TimerJobEntityManager in project Activiti by Activiti.

the class JobExecutorTest method testBasicJobExecutorOperation.

public void testBasicJobExecutorOperation() throws Exception {
    CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutor();
    commandExecutor.execute(new Command<Void>() {

        public Void execute(CommandContext commandContext) {
            JobManager jobManager = commandContext.getJobManager();
            jobManager.execute(createTweetMessage("message-one"));
            jobManager.execute(createTweetMessage("message-two"));
            jobManager.execute(createTweetMessage("message-three"));
            jobManager.execute(createTweetMessage("message-four"));
            TimerJobEntityManager timerJobManager = commandContext.getTimerJobEntityManager();
            timerJobManager.insert(createTweetTimer("timer-one", new Date()));
            timerJobManager.insert(createTweetTimer("timer-one", new Date()));
            timerJobManager.insert(createTweetTimer("timer-two", new Date()));
            return null;
        }
    });
    GregorianCalendar currentCal = new GregorianCalendar();
    currentCal.add(Calendar.MINUTE, 1);
    processEngineConfiguration.getClock().setCurrentTime(currentCal.getTime());
    waitForJobExecutorToProcessAllJobs(50000L, 200L);
    Set<String> messages = new HashSet<String>(tweetHandler.getMessages());
    Set<String> expectedMessages = new HashSet<String>();
    expectedMessages.add("message-one");
    expectedMessages.add("message-two");
    expectedMessages.add("message-three");
    expectedMessages.add("message-four");
    expectedMessages.add("timer-one");
    expectedMessages.add("timer-two");
    assertThat(new TreeSet<String>(messages)).isEqualTo(new TreeSet<String>(expectedMessages));
}
Also used : CommandContext(org.activiti.engine.impl.interceptor.CommandContext) CommandExecutor(org.activiti.engine.impl.interceptor.CommandExecutor) GregorianCalendar(java.util.GregorianCalendar) JobManager(org.activiti.engine.impl.asyncexecutor.JobManager) TimerJobEntityManager(org.activiti.engine.impl.persistence.entity.TimerJobEntityManager) Date(java.util.Date) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet)

Aggregations

TimerJobEntityManager (org.activiti.engine.impl.persistence.entity.TimerJobEntityManager)4 TimerJobEntity (org.activiti.engine.impl.persistence.entity.TimerJobEntity)2 Date (java.util.Date)1 GregorianCalendar (java.util.GregorianCalendar)1 HashSet (java.util.HashSet)1 TreeSet (java.util.TreeSet)1 ActivitiException (org.activiti.engine.ActivitiException)1 VariableScope (org.activiti.engine.delegate.VariableScope)1 JobManager (org.activiti.engine.impl.asyncexecutor.JobManager)1 NoExecutionVariableScope (org.activiti.engine.impl.el.NoExecutionVariableScope)1 CommandContext (org.activiti.engine.impl.interceptor.CommandContext)1 CommandExecutor (org.activiti.engine.impl.interceptor.CommandExecutor)1 DeadLetterJobEntity (org.activiti.engine.impl.persistence.entity.DeadLetterJobEntity)1 DeadLetterJobEntityManager (org.activiti.engine.impl.persistence.entity.DeadLetterJobEntityManager)1 ExecutionEntity (org.activiti.engine.impl.persistence.entity.ExecutionEntity)1 ExecutionEntityManager (org.activiti.engine.impl.persistence.entity.ExecutionEntityManager)1 JobEntity (org.activiti.engine.impl.persistence.entity.JobEntity)1 JobEntityManager (org.activiti.engine.impl.persistence.entity.JobEntityManager)1 SuspendedJobEntity (org.activiti.engine.impl.persistence.entity.SuspendedJobEntity)1 SuspendedJobEntityManager (org.activiti.engine.impl.persistence.entity.SuspendedJobEntityManager)1