Search in sources :

Example 1 with AsyncExecutor

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);
}
Also used : AsyncExecutor(org.activiti.engine.impl.asyncexecutor.AsyncExecutor)

Example 2 with AsyncExecutor

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);
}
Also used : TransactionListener(org.activiti.engine.impl.cfg.TransactionListener) AsyncJobAddedNotification(org.activiti.engine.impl.jobexecutor.AsyncJobAddedNotification) AsyncExecutor(org.activiti.engine.impl.asyncexecutor.AsyncExecutor)

Example 3 with AsyncExecutor

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();
    }
}
Also used : AsyncExecutor(org.activiti.engine.impl.asyncexecutor.AsyncExecutor) DefaultAsyncJobExecutor(org.activiti.engine.impl.asyncexecutor.DefaultAsyncJobExecutor)

Example 4 with AsyncExecutor

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();
            }
        }
    }
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) Timer(java.util.Timer) JobExecutor(org.activiti.engine.impl.jobexecutor.JobExecutor) AsyncExecutor(org.activiti.engine.impl.asyncexecutor.AsyncExecutor)

Example 5 with AsyncExecutor

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();
        }
    }
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) Timer(java.util.Timer) JobExecutor(org.activiti.engine.impl.jobexecutor.JobExecutor) ActivitiException(org.activiti.engine.ActivitiException) AsyncExecutor(org.activiti.engine.impl.asyncexecutor.AsyncExecutor)

Aggregations

AsyncExecutor (org.activiti.engine.impl.asyncexecutor.AsyncExecutor)8 Timer (java.util.Timer)5 JobExecutor (org.activiti.engine.impl.jobexecutor.JobExecutor)5 ActivitiException (org.activiti.engine.ActivitiException)4 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 DefaultAsyncJobExecutor (org.activiti.engine.impl.asyncexecutor.DefaultAsyncJobExecutor)1 TransactionListener (org.activiti.engine.impl.cfg.TransactionListener)1 AsyncJobAddedNotification (org.activiti.engine.impl.jobexecutor.AsyncJobAddedNotification)1 ClientProtocolException (org.apache.http.client.ClientProtocolException)1