use of org.activiti.engine.impl.asyncexecutor.AsyncExecutor in project Activiti by Activiti.
the class JobEntityManager method hintAsyncExecutor.
protected void hintAsyncExecutor(JobEntity job) {
AsyncExecutor asyncExecutor = Context.getProcessEngineConfiguration().getAsyncExecutor();
// notify job executor:
TransactionListener transactionListener = new AsyncJobAddedNotification(job, asyncExecutor);
Context.getCommandContext().getTransactionContext().addTransactionListener(TransactionState.COMMITTED, transactionListener);
}
use of org.activiti.engine.impl.asyncexecutor.AsyncExecutor in project Activiti by Activiti.
the class BaseSpringRestTestCase method waitForJobExecutorToProcessAllJobs.
public void waitForJobExecutorToProcessAllJobs(long maxMillisToWait, long intervalMillis) {
JobExecutor jobExecutor = null;
AsyncExecutor asyncExecutor = null;
if (processEngineConfiguration.isAsyncExecutorEnabled() == false) {
jobExecutor = processEngineConfiguration.getJobExecutor();
jobExecutor.start();
} else {
asyncExecutor = processEngineConfiguration.getAsyncExecutor();
asyncExecutor.start();
}
try {
Timer timer = new Timer();
InteruptTask task = new InteruptTask(Thread.currentThread());
timer.schedule(task, maxMillisToWait);
boolean areJobsAvailable = true;
try {
while (areJobsAvailable && !task.isTimeLimitExceeded()) {
Thread.sleep(intervalMillis);
areJobsAvailable = areJobsAvailable();
}
} catch (InterruptedException e) {
} finally {
timer.cancel();
}
if (areJobsAvailable) {
throw new ActivitiException("time limit of " + maxMillisToWait + " was exceeded");
}
} finally {
if (processEngineConfiguration.isAsyncExecutorEnabled() == false) {
jobExecutor.shutdown();
} else {
asyncExecutor.shutdown();
}
}
}
use of org.activiti.engine.impl.asyncexecutor.AsyncExecutor in project Activiti by Activiti.
the class BaseSpringRestTestCase method waitForJobExecutorOnCondition.
public void waitForJobExecutorOnCondition(long maxMillisToWait, long intervalMillis, Callable<Boolean> condition) {
JobExecutor jobExecutor = null;
AsyncExecutor asyncExecutor = null;
if (processEngineConfiguration.isAsyncExecutorEnabled() == false) {
jobExecutor = processEngineConfiguration.getJobExecutor();
jobExecutor.start();
} else {
asyncExecutor = processEngineConfiguration.getAsyncExecutor();
asyncExecutor.start();
}
try {
Timer timer = new Timer();
InteruptTask task = new InteruptTask(Thread.currentThread());
timer.schedule(task, maxMillisToWait);
boolean conditionIsViolated = true;
try {
while (conditionIsViolated) {
Thread.sleep(intervalMillis);
conditionIsViolated = !condition.call();
}
} catch (InterruptedException e) {
} catch (Exception e) {
throw new ActivitiException("Exception while waiting on condition: " + e.getMessage(), e);
} finally {
timer.cancel();
}
if (conditionIsViolated) {
throw new ActivitiException("time limit of " + maxMillisToWait + " was exceeded");
}
} finally {
if (processEngineConfiguration.isAsyncExecutorEnabled() == false) {
jobExecutor.shutdown();
} else {
asyncExecutor.shutdown();
}
}
}
Aggregations