Search in sources :

Example 11 with JobExecutor

use of org.activiti.engine.impl.jobexecutor.JobExecutor 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();
        }
    }
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) Timer(java.util.Timer) JobExecutor(org.activiti.engine.impl.jobexecutor.JobExecutor) ActivitiException(org.activiti.engine.ActivitiException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ClientProtocolException(org.apache.http.client.ClientProtocolException) IOException(java.io.IOException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) AsyncExecutor(org.activiti.engine.impl.asyncexecutor.AsyncExecutor)

Aggregations

JobExecutor (org.activiti.engine.impl.jobexecutor.JobExecutor)11 Timer (java.util.Timer)9 ActivitiException (org.activiti.engine.ActivitiException)9 AsyncExecutor (org.activiti.engine.impl.asyncexecutor.AsyncExecutor)5 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 IOException (java.io.IOException)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 JobAddedNotification (org.activiti.engine.impl.jobexecutor.JobAddedNotification)2 ClientProtocolException (org.apache.http.client.ClientProtocolException)2 ProcessEngineConfiguration (org.activiti.engine.ProcessEngineConfiguration)1 ActivitiEventDispatcher (org.activiti.engine.delegate.event.ActivitiEventDispatcher)1 DurationHelper (org.activiti.engine.impl.calendar.DurationHelper)1 TransactionContext (org.activiti.engine.impl.cfg.TransactionContext)1 TransactionListener (org.activiti.engine.impl.cfg.TransactionListener)1 AsyncJobAddedNotification (org.activiti.engine.impl.jobexecutor.AsyncJobAddedNotification)1 JobEntity (org.activiti.engine.impl.persistence.entity.JobEntity)1 ActivityImpl (org.activiti.engine.impl.pvm.process.ActivityImpl)1