use of org.activiti.engine.impl.asyncexecutor.AsyncExecutor in project Activiti by Activiti.
the class JobEntityManager method retryAsyncJob.
/*"Not used anymore. Will be removed in a future release." */
@Deprecated()
public void retryAsyncJob(JobEntity job) {
AsyncExecutor asyncExecutor = Context.getProcessEngineConfiguration().getAsyncExecutor();
try {
// If a job has to be retried, we wait for a certain amount of time,
// otherwise the job will be continuously be retried without delay (and thus seriously stressing the database).
Thread.sleep(asyncExecutor.getRetryWaitTimeInMillis());
} catch (InterruptedException e) {
}
asyncExecutor.executeAsyncJob(job);
}
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 ExecutorPerTenantAsyncExecutor method addTenantAsyncExecutor.
public void addTenantAsyncExecutor(String tenantId, boolean startExecutor) {
AsyncExecutor tenantExecutor = null;
if (tenantAwareAyncExecutorFactory == null) {
tenantExecutor = new DefaultAsyncJobExecutor();
} else {
tenantExecutor = tenantAwareAyncExecutorFactory.createAsyncExecutor(tenantId);
}
if (tenantExecutor instanceof DefaultAsyncJobExecutor) {
DefaultAsyncJobExecutor defaultAsyncJobExecutor = (DefaultAsyncJobExecutor) tenantExecutor;
defaultAsyncJobExecutor.setAsyncJobsDueRunnable(new TenantAwareAcquireAsyncJobsDueRunnable(defaultAsyncJobExecutor, tenantInfoHolder, tenantId));
defaultAsyncJobExecutor.setTimerJobRunnable(new TenantAwareAcquireTimerJobsRunnable(defaultAsyncJobExecutor, tenantInfoHolder, tenantId));
defaultAsyncJobExecutor.setExecuteAsyncRunnableFactory(new TenantAwareExecuteAsyncRunnableFactory(tenantInfoHolder, tenantId));
}
// Needs to be done for job executors created after boot. Doesn't hurt on boot.
tenantExecutor.setCommandExecutor(commandExecutor);
tenantExecutors.put(tenantId, tenantExecutor);
if (startExecutor) {
tenantExecutor.start();
}
}
use of org.activiti.engine.impl.asyncexecutor.AsyncExecutor in project Activiti by Activiti.
the class JobTestHelper method waitForJobExecutorToProcessAllJobs.
public static void waitForJobExecutorToProcessAllJobs(ProcessEngineConfiguration processEngineConfiguration, ManagementService managementService, long maxMillisToWait, long intervalMillis, boolean shutdownExecutorWhenFinished) {
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);
try {
areJobsAvailable = areJobsAvailable(managementService);
} catch (Throwable t) {
// Ignore, possible that exception occurs due to locking/updating of table on MSSQL when
// isolation level doesn't allow READ of the table
}
}
} catch (InterruptedException e) {
// ignore
} finally {
timer.cancel();
}
if (areJobsAvailable) {
throw new ActivitiException("time limit of " + maxMillisToWait + " was exceeded");
}
} finally {
if (shutdownExecutorWhenFinished) {
if (processEngineConfiguration.isAsyncExecutorEnabled() == false) {
jobExecutor.shutdown();
} else {
asyncExecutor.shutdown();
}
}
}
}
use of org.activiti.engine.impl.asyncexecutor.AsyncExecutor in project Activiti by Activiti.
the class JobTestHelper method waitForJobExecutorOnCondition.
public static void waitForJobExecutorOnCondition(ProcessEngineConfiguration processEngineConfiguration, 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) {
// ignore
} 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