Search in sources :

Example 1 with JobExecutor

use of org.activiti.engine.impl.jobexecutor.JobExecutor in project Activiti by Activiti.

the class CdiActivitiTestCase method waitForJobExecutorToProcessAllJobs.

//////////////////////// copied from AbstractActivitiTestcase
public void waitForJobExecutorToProcessAllJobs(long maxMillisToWait, long intervalMillis) {
    JobExecutor jobExecutor = processEngineConfiguration.getJobExecutor();
    jobExecutor.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 {
        jobExecutor.shutdown();
    }
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) Timer(java.util.Timer) JobExecutor(org.activiti.engine.impl.jobexecutor.JobExecutor)

Example 2 with JobExecutor

use of org.activiti.engine.impl.jobexecutor.JobExecutor in project Activiti by Activiti.

the class CdiActivitiTestCase method waitForJobExecutorOnCondition.

public void waitForJobExecutorOnCondition(long maxMillisToWait, long intervalMillis, Callable<Boolean> condition) {
    JobExecutor jobExecutor = processEngineConfiguration.getJobExecutor();
    jobExecutor.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 {
        jobExecutor.shutdown();
    }
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) Timer(java.util.Timer) JobExecutor(org.activiti.engine.impl.jobexecutor.JobExecutor) ActivitiException(org.activiti.engine.ActivitiException)

Example 3 with JobExecutor

use of org.activiti.engine.impl.jobexecutor.JobExecutor in project Activiti by Activiti.

the class JobEntityManager method hintJobExecutor.

protected void hintJobExecutor(JobEntity job) {
    JobExecutor jobExecutor = Context.getProcessEngineConfiguration().getJobExecutor();
    // notify job executor:      
    TransactionListener transactionListener = new JobAddedNotification(jobExecutor);
    Context.getCommandContext().getTransactionContext().addTransactionListener(TransactionState.COMMITTED, transactionListener);
}
Also used : TransactionListener(org.activiti.engine.impl.cfg.TransactionListener) JobExecutor(org.activiti.engine.impl.jobexecutor.JobExecutor) JobAddedNotification(org.activiti.engine.impl.jobexecutor.JobAddedNotification) AsyncJobAddedNotification(org.activiti.engine.impl.jobexecutor.AsyncJobAddedNotification)

Example 4 with JobExecutor

use of org.activiti.engine.impl.jobexecutor.JobExecutor in project Activiti by Activiti.

the class BaseJPARestTestCase method waitForJobExecutorOnCondition.

public void waitForJobExecutorOnCondition(long maxMillisToWait, long intervalMillis, Callable<Boolean> condition) {
    JobExecutor jobExecutor = processEngineConfiguration.getJobExecutor();
    jobExecutor.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 {
        jobExecutor.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)

Example 5 with JobExecutor

use of org.activiti.engine.impl.jobexecutor.JobExecutor in project Activiti by Activiti.

the class BaseJPARestTestCase method waitForJobExecutorToProcessAllJobs.

public void waitForJobExecutorToProcessAllJobs(long maxMillisToWait, long intervalMillis) {
    JobExecutor jobExecutor = processEngineConfiguration.getJobExecutor();
    jobExecutor.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 {
        jobExecutor.shutdown();
    }
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) Timer(java.util.Timer) JobExecutor(org.activiti.engine.impl.jobexecutor.JobExecutor)

Aggregations

JobExecutor (org.activiti.engine.impl.jobexecutor.JobExecutor)7 Timer (java.util.Timer)6 ActivitiException (org.activiti.engine.ActivitiException)6 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 IOException (java.io.IOException)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 AsyncExecutor (org.activiti.engine.impl.asyncexecutor.AsyncExecutor)2 ClientProtocolException (org.apache.http.client.ClientProtocolException)2 TransactionListener (org.activiti.engine.impl.cfg.TransactionListener)1 AsyncJobAddedNotification (org.activiti.engine.impl.jobexecutor.AsyncJobAddedNotification)1 JobAddedNotification (org.activiti.engine.impl.jobexecutor.JobAddedNotification)1