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);
}
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;
}
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;
}
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;
}
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();
}
}
Aggregations