use of org.activiti.engine.impl.persistence.entity.JobEntity in project Activiti by Activiti.
the class AcquireTimerJobsRunnable method run.
public synchronized void run() {
log.info("starting to acquire async jobs due");
final CommandExecutor commandExecutor = asyncExecutor.getCommandExecutor();
while (!isInterrupted) {
try {
AcquiredJobEntities acquiredJobs = commandExecutor.execute(new AcquireTimerJobsCmd(asyncExecutor.getLockOwner(), asyncExecutor.getTimerLockTimeInMillis(), asyncExecutor.getMaxTimerJobsPerAcquisition()));
boolean allJobsSuccessfullyOffered = true;
for (JobEntity job : acquiredJobs.getJobs()) {
boolean jobSuccessFullyOffered = asyncExecutor.executeAsyncJob(job);
if (!jobSuccessFullyOffered) {
allJobsSuccessfullyOffered = false;
}
}
// if all jobs were executed
millisToWait = asyncExecutor.getDefaultTimerJobAcquireWaitTimeInMillis();
int jobsAcquired = acquiredJobs.size();
if (jobsAcquired >= asyncExecutor.getMaxTimerJobsPerAcquisition()) {
millisToWait = 0;
}
// If the queue was full, we wait too (even if we got enough jobs back), as not overload the queue
if (millisToWait == 0 && !allJobsSuccessfullyOffered) {
millisToWait = asyncExecutor.getDefaultQueueSizeFullWaitTimeInMillis();
}
} catch (ActivitiOptimisticLockingException optimisticLockingException) {
if (log.isDebugEnabled()) {
log.debug("Optimistic locking exception during timer job acquisition. If you have multiple timer executors running against the same database, " + "this exception means that this thread tried to acquire a timer job, which already was acquired by another timer executor acquisition thread." + "This is expected behavior in a clustered environment. " + "You can ignore this message if you indeed have multiple timer executor acquisition threads running against the same database. " + "Exception message: {}", optimisticLockingException.getMessage());
}
} catch (Throwable e) {
log.error("exception during timer job acquisition: {}", e.getMessage(), e);
millisToWait = asyncExecutor.getDefaultTimerJobAcquireWaitTimeInMillis();
}
if (millisToWait > 0) {
try {
if (log.isDebugEnabled()) {
log.debug("timer job acquisition thread sleeping for {} millis", millisToWait);
}
synchronized (MONITOR) {
if (!isInterrupted) {
isWaiting.set(true);
MONITOR.wait(millisToWait);
}
}
if (log.isDebugEnabled()) {
log.debug("timer job acquisition thread woke up");
}
} catch (InterruptedException e) {
if (log.isDebugEnabled()) {
log.debug("timer job acquisition wait interrupted");
}
} finally {
isWaiting.set(false);
}
}
}
log.info("stopped async job due acquisition");
}
use of org.activiti.engine.impl.persistence.entity.JobEntity in project Activiti by Activiti.
the class JobQueryTest method setRetries.
//helper ////////////////////////////////////////////////////////////
private void setRetries(final String processInstanceId, final int retries) {
final Job job = managementService.createJobQuery().processInstanceId(processInstanceId).singleResult();
commandExecutor.execute(new Command<Void>() {
public Void execute(CommandContext commandContext) {
JobEntity timer = commandContext.getDbSqlSession().selectById(JobEntity.class, job.getId());
timer.setRetries(retries);
return null;
}
});
}
use of org.activiti.engine.impl.persistence.entity.JobEntity in project Activiti by Activiti.
the class JobDetailPanel method addJobState.
protected void addJobState() {
Label processDefinitionHeader = new Label(i18nManager.getMessage(Messages.JOB_HEADER_EXECUTION));
processDefinitionHeader.addStyleName(ExplorerLayout.STYLE_H3);
processDefinitionHeader.addStyleName(ExplorerLayout.STYLE_DETAIL_BLOCK);
processDefinitionHeader.setWidth(100, UNITS_PERCENTAGE);
addComponent(processDefinitionHeader);
VerticalLayout layout = new VerticalLayout();
layout.setSpacing(true);
layout.setSizeFull();
layout.setMargin(true, false, true, false);
addDetailComponent(layout);
setDetailExpandRatio(layout, 1.0f);
// Exceptions
if (job.getExceptionMessage() != null) {
// Number of retries
Label retrieslabel = new Label(getRetriesLabel(job));
layout.addComponent(retrieslabel);
// Exception
Label exceptionMessageLabel = new Label(i18nManager.getMessage(Messages.JOB_ERROR) + ": " + job.getExceptionMessage());
exceptionMessageLabel.addStyleName(ExplorerLayout.STYLE_JOB_EXCEPTION_MESSAGE);
layout.addComponent(exceptionMessageLabel);
// Add Exception stacktrace
String stack = managementService.getJobExceptionStacktrace(job.getId());
Label stackTraceLabel = new Label(stack);
stackTraceLabel.setContentMode(Label.CONTENT_PREFORMATTED);
stackTraceLabel.addStyleName(ExplorerLayout.STYLE_JOB_EXCEPTION_TRACE);
stackTraceLabel.setSizeFull();
Panel stackPanel = new Panel();
stackPanel.setWidth(100, UNITS_PERCENTAGE);
stackPanel.setSizeFull();
stackPanel.setScrollable(true);
stackPanel.addComponent(stackTraceLabel);
layout.addComponent(stackPanel);
layout.setExpandRatio(stackPanel, 1.0f);
} else {
if (job.getProcessDefinitionId() != null) {
// This is a hack .. need to cleanify this in the engine
JobEntity jobEntity = (JobEntity) job;
if (jobEntity.getJobHandlerType().equals(TimerSuspendProcessDefinitionHandler.TYPE)) {
addLinkToProcessDefinition(layout, i18nManager.getMessage(Messages.JOB_SUSPEND_PROCESSDEFINITION), false);
} else if (jobEntity.getJobHandlerType().equals(TimerActivateProcessDefinitionHandler.TYPE)) {
addLinkToProcessDefinition(layout, i18nManager.getMessage(Messages.JOB_ACTIVATE_PROCESSDEFINITION), true);
} else {
addNotYetExecutedLabel(layout);
}
} else {
addNotYetExecutedLabel(layout);
}
}
}
use of org.activiti.engine.impl.persistence.entity.JobEntity in project Activiti by Activiti.
the class JobExecutorCmdHappyTest method testJobCommandsWithTimer.
public void testJobCommandsWithTimer() {
// clock gets automatically reset in LogTestCase.runTest
processEngineConfiguration.getClock().setCurrentTime(new Date(SOME_TIME));
CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutor();
String jobId = commandExecutor.execute(new Command<String>() {
public String execute(CommandContext commandContext) {
TimerEntity timer = createTweetTimer("i'm coding a test", new Date(SOME_TIME + (10 * SECOND)));
commandContext.getJobEntityManager().schedule(timer);
return timer.getId();
}
});
AcquiredJobEntities acquiredJobs = commandExecutor.execute(new AcquireTimerJobsCmd("testLockOwner", 10000, 5));
assertEquals(0, acquiredJobs.size());
processEngineConfiguration.getClock().setCurrentTime(new Date(SOME_TIME + (20 * SECOND)));
acquiredJobs = commandExecutor.execute(new AcquireTimerJobsCmd("testLockOwner", 10000, 5));
assertEquals(1, acquiredJobs.size());
JobEntity job = acquiredJobs.getJobs().iterator().next();
assertEquals(jobId, job.getId());
assertEquals(0, tweetHandler.getMessages().size());
commandExecutor.execute(new ExecuteAsyncJobCmd(job));
assertEquals("i'm coding a test", tweetHandler.getMessages().get(0));
assertEquals(1, tweetHandler.getMessages().size());
}
use of org.activiti.engine.impl.persistence.entity.JobEntity in project Activiti by Activiti.
the class HazelCastDistributedQueueBasedAsyncExecutor method initJobQueueListener.
protected void initJobQueueListener() {
jobQueueListenerThread = new Thread(new Runnable() {
public void run() {
while (isActive) {
JobEntity job = null;
try {
// Blocking
job = jobQueue.take();
} catch (InterruptedException e1) {
logger.info("jobQueueListenerThread interrupted. This is fine if the job executor is shutting down");
// Do nothing, this can happen when shutting down
} catch (HazelcastInstanceNotActiveException notActiveException) {
logger.info("Hazel cast not active exception caught. This is fine if the job executor is shutting down");
}
if (job != null) {
executorService.execute(new ExecuteAsyncRunnable(job, commandExecutor));
}
}
}
});
jobQueueListenerThread.start();
}
Aggregations