Search in sources :

Example 1 with SuspendedJobEntity

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

the class AbstractSetProcessInstanceStateCmd method execute.

public Void execute(CommandContext commandContext) {
    if (processInstanceId == null) {
        throw new ActivitiIllegalArgumentException("ProcessInstanceId cannot be null.");
    }
    ExecutionEntity executionEntity = commandContext.getExecutionEntityManager().findById(processInstanceId);
    if (executionEntity == null) {
        throw new ActivitiObjectNotFoundException("Cannot find processInstance for id '" + processInstanceId + "'.", Execution.class);
    }
    if (!executionEntity.isProcessInstanceType()) {
        throw new ActivitiException("Cannot set suspension state for execution '" + processInstanceId + "': not a process instance.");
    }
    SuspensionStateUtil.setSuspensionState(executionEntity, getNewState());
    commandContext.getExecutionEntityManager().update(executionEntity, false);
    // All child executions are suspended
    Collection<ExecutionEntity> childExecutions = commandContext.getExecutionEntityManager().findChildExecutionsByProcessInstanceId(processInstanceId);
    for (ExecutionEntity childExecution : childExecutions) {
        if (!childExecution.getId().equals(processInstanceId)) {
            SuspensionStateUtil.setSuspensionState(childExecution, getNewState());
            commandContext.getExecutionEntityManager().update(childExecution, false);
        }
    }
    // All tasks are suspended
    List<TaskEntity> tasks = commandContext.getTaskEntityManager().findTasksByProcessInstanceId(processInstanceId);
    for (TaskEntity taskEntity : tasks) {
        SuspensionStateUtil.setSuspensionState(taskEntity, getNewState());
        commandContext.getTaskEntityManager().update(taskEntity, false);
    }
    // All jobs are suspended
    if (getNewState() == SuspensionState.ACTIVE) {
        List<SuspendedJobEntity> suspendedJobs = commandContext.getSuspendedJobEntityManager().findJobsByProcessInstanceId(processInstanceId);
        for (SuspendedJobEntity suspendedJob : suspendedJobs) {
            commandContext.getJobManager().activateSuspendedJob(suspendedJob);
        }
    } else {
        List<TimerJobEntity> timerJobs = commandContext.getTimerJobEntityManager().findJobsByProcessInstanceId(processInstanceId);
        for (TimerJobEntity timerJob : timerJobs) {
            commandContext.getJobManager().moveJobToSuspendedJob(timerJob);
        }
        List<JobEntity> jobs = commandContext.getJobEntityManager().findJobsByProcessInstanceId(processInstanceId);
        for (JobEntity job : jobs) {
            commandContext.getJobManager().moveJobToSuspendedJob(job);
        }
    }
    return null;
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) TaskEntity(org.activiti.engine.impl.persistence.entity.TaskEntity) SuspendedJobEntity(org.activiti.engine.impl.persistence.entity.SuspendedJobEntity) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException) SuspendedJobEntity(org.activiti.engine.impl.persistence.entity.SuspendedJobEntity) JobEntity(org.activiti.engine.impl.persistence.entity.JobEntity) TimerJobEntity(org.activiti.engine.impl.persistence.entity.TimerJobEntity) ExecutionEntity(org.activiti.engine.impl.persistence.entity.ExecutionEntity) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) TimerJobEntity(org.activiti.engine.impl.persistence.entity.TimerJobEntity)

Example 2 with SuspendedJobEntity

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

the class DefaultJobManager method activateSuspendedJob.

@Override
public AbstractJobEntity activateSuspendedJob(SuspendedJobEntity job) {
    AbstractJobEntity activatedJob = null;
    if (Job.JOB_TYPE_TIMER.equals(job.getJobType())) {
        activatedJob = createTimerJobFromOtherJob(job);
        processEngineConfiguration.getTimerJobEntityManager().insert((TimerJobEntity) activatedJob);
    } else {
        activatedJob = createExecutableJobFromOtherJob(job);
        JobEntity jobEntity = (JobEntity) activatedJob;
        processEngineConfiguration.getJobEntityManager().insert(jobEntity);
        triggerExecutorIfNeeded(jobEntity);
    }
    processEngineConfiguration.getSuspendedJobEntityManager().delete(job);
    return activatedJob;
}
Also used : DeadLetterJobEntity(org.activiti.engine.impl.persistence.entity.DeadLetterJobEntity) SuspendedJobEntity(org.activiti.engine.impl.persistence.entity.SuspendedJobEntity) AbstractJobEntity(org.activiti.engine.impl.persistence.entity.AbstractJobEntity) JobEntity(org.activiti.engine.impl.persistence.entity.JobEntity) TimerJobEntity(org.activiti.engine.impl.persistence.entity.TimerJobEntity) AbstractJobEntity(org.activiti.engine.impl.persistence.entity.AbstractJobEntity)

Example 3 with SuspendedJobEntity

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

the class DefaultJobManager method moveJobToTimerJob.

@Override
public TimerJobEntity moveJobToTimerJob(AbstractJobEntity job) {
    TimerJobEntity timerJob = createTimerJobFromOtherJob(job);
    boolean insertSuccesful = processEngineConfiguration.getTimerJobEntityManager().insertTimerJobEntity(timerJob);
    if (insertSuccesful) {
        if (job instanceof JobEntity) {
            processEngineConfiguration.getJobEntityManager().delete((JobEntity) job);
        } else if (job instanceof SuspendedJobEntity) {
            processEngineConfiguration.getSuspendedJobEntityManager().delete((SuspendedJobEntity) job);
        }
        return timerJob;
    }
    return null;
}
Also used : DeadLetterJobEntity(org.activiti.engine.impl.persistence.entity.DeadLetterJobEntity) SuspendedJobEntity(org.activiti.engine.impl.persistence.entity.SuspendedJobEntity) AbstractJobEntity(org.activiti.engine.impl.persistence.entity.AbstractJobEntity) JobEntity(org.activiti.engine.impl.persistence.entity.JobEntity) TimerJobEntity(org.activiti.engine.impl.persistence.entity.TimerJobEntity) SuspendedJobEntity(org.activiti.engine.impl.persistence.entity.SuspendedJobEntity) TimerJobEntity(org.activiti.engine.impl.persistence.entity.TimerJobEntity)

Example 4 with SuspendedJobEntity

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

the class DefaultJobManager method moveJobToSuspendedJob.

@Override
public SuspendedJobEntity moveJobToSuspendedJob(AbstractJobEntity job) {
    SuspendedJobEntity suspendedJob = createSuspendedJobFromOtherJob(job);
    processEngineConfiguration.getSuspendedJobEntityManager().insert(suspendedJob);
    if (job instanceof TimerJobEntity) {
        processEngineConfiguration.getTimerJobEntityManager().delete((TimerJobEntity) job);
    } else if (job instanceof JobEntity) {
        processEngineConfiguration.getJobEntityManager().delete((JobEntity) job);
    }
    return suspendedJob;
}
Also used : DeadLetterJobEntity(org.activiti.engine.impl.persistence.entity.DeadLetterJobEntity) SuspendedJobEntity(org.activiti.engine.impl.persistence.entity.SuspendedJobEntity) AbstractJobEntity(org.activiti.engine.impl.persistence.entity.AbstractJobEntity) JobEntity(org.activiti.engine.impl.persistence.entity.JobEntity) TimerJobEntity(org.activiti.engine.impl.persistence.entity.TimerJobEntity) SuspendedJobEntity(org.activiti.engine.impl.persistence.entity.SuspendedJobEntity) TimerJobEntity(org.activiti.engine.impl.persistence.entity.TimerJobEntity)

Example 5 with SuspendedJobEntity

use of org.activiti.engine.impl.persistence.entity.SuspendedJobEntity 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)

Aggregations

SuspendedJobEntity (org.activiti.engine.impl.persistence.entity.SuspendedJobEntity)6 JobEntity (org.activiti.engine.impl.persistence.entity.JobEntity)5 TimerJobEntity (org.activiti.engine.impl.persistence.entity.TimerJobEntity)5 DeadLetterJobEntity (org.activiti.engine.impl.persistence.entity.DeadLetterJobEntity)4 AbstractJobEntity (org.activiti.engine.impl.persistence.entity.AbstractJobEntity)3 ActivitiException (org.activiti.engine.ActivitiException)1 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)1 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)1 DeadLetterJobEntityManager (org.activiti.engine.impl.persistence.entity.DeadLetterJobEntityManager)1 ExecutionEntity (org.activiti.engine.impl.persistence.entity.ExecutionEntity)1 JobEntityManager (org.activiti.engine.impl.persistence.entity.JobEntityManager)1 SuspendedJobEntityManager (org.activiti.engine.impl.persistence.entity.SuspendedJobEntityManager)1 TaskEntity (org.activiti.engine.impl.persistence.entity.TaskEntity)1 TimerJobEntityManager (org.activiti.engine.impl.persistence.entity.TimerJobEntityManager)1