Search in sources :

Example 6 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 7 with AsyncExecutor

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();
        }
    }
}
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 8 with AsyncExecutor

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();
        }
    }
}
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

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