Search in sources :

Example 1 with JobEntity

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

the class ProcessDefinitionInfoComponent method initSuspensionStateInformation.

protected void initSuspensionStateInformation() {
    List<Job> jobs = managementService.createJobQuery().processDefinitionId(processDefinition.getId()).orderByJobDuedate().asc().list();
    List<JobEntity> suspensionStateJobs = new ArrayList<JobEntity>();
    // TODO: this is a hack (ie the cast to JobEntity)... we must clean this in the engine!
    for (Job job : jobs) {
        JobEntity jobEntity = (JobEntity) job;
        if (jobEntity.getJobHandlerType().equals(TimerSuspendProcessDefinitionHandler.TYPE) || jobEntity.getJobHandlerType().equals(TimerActivateProcessDefinitionHandler.TYPE)) {
            suspensionStateJobs.add(jobEntity);
        }
    }
    if (!suspensionStateJobs.isEmpty()) {
        // Header
        Label suspensionStateTitle = new Label(i18nManager.getMessage(Messages.PROCESS_HEADER_SUSPENSION_STATE));
        suspensionStateTitle.addStyleName(ExplorerLayout.STYLE_H3);
        addComponent(suspensionStateTitle);
        addEmptySpace(this);
        // Actual suspend/activation jobs
        for (JobEntity jobEntity : suspensionStateJobs) {
            if (jobEntity.getJobHandlerType().equals(TimerSuspendProcessDefinitionHandler.TYPE)) {
                Label suspendLabel = new Label(i18nManager.getMessage(Messages.PROCESS_SCHEDULED_SUSPEND, Constants.DEFAULT_TIME_FORMATTER.format(jobEntity.getDuedate())), Label.CONTENT_XHTML);
                addComponent(suspendLabel);
            } else if (jobEntity.getJobHandlerType().equals(TimerActivateProcessDefinitionHandler.TYPE)) {
                Label suspendLabel = new Label(i18nManager.getMessage(Messages.PROCESS_SCHEDULED_ACTIVATE, Constants.DEFAULT_TIME_FORMATTER.format(jobEntity.getDuedate())), Label.CONTENT_XHTML);
                addComponent(suspendLabel);
            }
        }
    }
    addEmptySpace(this);
}
Also used : JobEntity(org.activiti.engine.impl.persistence.entity.JobEntity) ArrayList(java.util.ArrayList) Label(com.vaadin.ui.Label) Job(org.activiti.engine.runtime.Job)

Example 2 with JobEntity

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

the class AcquireAsyncJobsDueCmd method execute.

public AcquiredJobEntities execute(CommandContext commandContext) {
    AcquiredJobEntities acquiredJobs = new AcquiredJobEntities();
    List<JobEntity> jobs = commandContext.getJobEntityManager().findAsyncJobsDueToExecute(new Page(0, asyncExecutor.getMaxAsyncJobsDuePerAcquisition()));
    for (JobEntity job : jobs) {
        lockJob(commandContext, job, asyncExecutor.getAsyncJobLockTimeInMillis());
        acquiredJobs.addJob(job);
    }
    return acquiredJobs;
}
Also used : AcquiredJobEntities(org.activiti.engine.impl.asyncexecutor.AcquiredJobEntities) JobEntity(org.activiti.engine.impl.persistence.entity.JobEntity) Page(org.activiti.engine.impl.Page)

Example 3 with JobEntity

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

the class AcquireJobsCmd method execute.

public AcquiredJobs execute(CommandContext commandContext) {
    String lockOwner = jobExecutor.getLockOwner();
    int lockTimeInMillis = jobExecutor.getLockTimeInMillis();
    int maxNonExclusiveJobsPerAcquisition = jobExecutor.getMaxJobsPerAcquisition();
    AcquiredJobs acquiredJobs = new AcquiredJobs();
    List<JobEntity> jobs = commandContext.getJobEntityManager().findNextJobsToExecute(new Page(0, maxNonExclusiveJobsPerAcquisition));
    for (JobEntity job : jobs) {
        List<String> jobIds = new ArrayList<String>();
        if (job != null && !acquiredJobs.contains(job.getId())) {
            if (job instanceof MessageEntity && job.isExclusive() && job.getProcessInstanceId() != null) {
                // wait to get exclusive jobs within 100ms
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                }
                // acquire all exclusive jobs in the same process instance
                // (includes the current job)
                List<JobEntity> exclusiveJobs = commandContext.getJobEntityManager().findExclusiveJobsToExecute(job.getProcessInstanceId());
                for (JobEntity exclusiveJob : exclusiveJobs) {
                    if (exclusiveJob != null) {
                        lockJob(commandContext, exclusiveJob, lockOwner, lockTimeInMillis);
                        jobIds.add(exclusiveJob.getId());
                    }
                }
            } else {
                lockJob(commandContext, job, lockOwner, lockTimeInMillis);
                jobIds.add(job.getId());
            }
        }
        acquiredJobs.addJobIdBatch(jobIds);
    }
    return acquiredJobs;
}
Also used : JobEntity(org.activiti.engine.impl.persistence.entity.JobEntity) MessageEntity(org.activiti.engine.impl.persistence.entity.MessageEntity) ArrayList(java.util.ArrayList) AcquiredJobs(org.activiti.engine.impl.jobexecutor.AcquiredJobs) Page(org.activiti.engine.impl.Page)

Example 4 with JobEntity

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

the class AcquireTimerJobsCmd method execute.

public AcquiredJobEntities execute(CommandContext commandContext) {
    AcquiredJobEntities acquiredJobs = new AcquiredJobEntities();
    List<JobEntity> jobs = commandContext.getJobEntityManager().findNextTimerJobsToExecute(new Page(0, maxJobsPerAcquisition));
    for (JobEntity job : jobs) {
        if (job != null && !acquiredJobs.contains(job.getId())) {
            lockJob(commandContext, job, lockOwner, lockTimeInMillis);
            acquiredJobs.addJob(job);
        }
    }
    return acquiredJobs;
}
Also used : AcquiredJobEntities(org.activiti.engine.impl.asyncexecutor.AcquiredJobEntities) JobEntity(org.activiti.engine.impl.persistence.entity.JobEntity) Page(org.activiti.engine.impl.Page)

Example 5 with JobEntity

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

the class ExecuteJobsRunnable method handleSingleJob.

protected void handleSingleJob() {
    final SingleJobExecutorContext jobExecutorContext = new SingleJobExecutorContext();
    final List<JobEntity> currentProcessorJobQueue = jobExecutorContext.getCurrentProcessorJobQueue();
    final CommandExecutor commandExecutor = jobExecutor.getCommandExecutor();
    currentProcessorJobQueue.add(job);
    Context.setJobExecutorContext(jobExecutorContext);
    try {
        while (!currentProcessorJobQueue.isEmpty()) {
            JobEntity currentJob = currentProcessorJobQueue.remove(0);
            try {
                commandExecutor.execute(new ExecuteJobsCmd(currentJob));
            } catch (Throwable e) {
                log.error("exception during job execution: {}", e.getMessage(), e);
            } finally {
                jobExecutor.jobDone(currentJob);
            }
        }
    } finally {
        Context.removeJobExecutorContext();
    }
}
Also used : JobEntity(org.activiti.engine.impl.persistence.entity.JobEntity) CommandExecutor(org.activiti.engine.impl.interceptor.CommandExecutor) ExecuteJobsCmd(org.activiti.engine.impl.cmd.ExecuteJobsCmd)

Aggregations

JobEntity (org.activiti.engine.impl.persistence.entity.JobEntity)17 CommandExecutor (org.activiti.engine.impl.interceptor.CommandExecutor)5 Page (org.activiti.engine.impl.Page)3 AcquiredJobEntities (org.activiti.engine.impl.asyncexecutor.AcquiredJobEntities)3 CommandContext (org.activiti.engine.impl.interceptor.CommandContext)3 Job (org.activiti.engine.runtime.Job)3 Label (com.vaadin.ui.Label)2 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 ActivitiOptimisticLockingException (org.activiti.engine.ActivitiOptimisticLockingException)2 AcquireTimerJobsCmd (org.activiti.engine.impl.cmd.AcquireTimerJobsCmd)2 HazelcastInstanceNotActiveException (com.hazelcast.core.HazelcastInstanceNotActiveException)1 Panel (com.vaadin.ui.Panel)1 VerticalLayout (com.vaadin.ui.VerticalLayout)1 Calendar (java.util.Calendar)1 ActivitiException (org.activiti.engine.ActivitiException)1 ProcessEngineConfiguration (org.activiti.engine.ProcessEngineConfiguration)1 ActivitiEventDispatcher (org.activiti.engine.delegate.event.ActivitiEventDispatcher)1 ExecuteAsyncRunnable (org.activiti.engine.impl.asyncexecutor.ExecuteAsyncRunnable)1 DurationHelper (org.activiti.engine.impl.calendar.DurationHelper)1