Search in sources :

Example 1 with SkippedException

use of javax.enterprise.concurrent.SkippedException in project tomee by apache.

the class TriggerTask method invoke.

public T invoke() throws Exception {
    return invoke(new Callable<T>() {

        @Override
        public T call() throws Exception {
            final long wait = nextDelay(trigger.getNextRunTime(lastExecution, scheduledTime));
            if (wait > 0) {
                Thread.sleep(wait);
            }
            // else if wait < 0 then ??
            final Date now = new Date();
            try {
                final boolean skip = trigger.skipRun(lastExecution, now);
                if (!skip) {
                    result = doInvoke();
                    taskDone(future, executor, delegate, null);
                    lastExecution = new LastExecutionImpl(id, result, scheduledTime, now, new Date());
                } else {
                    result = null;
                    skipped = true;
                    running.set(false);
                }
            } catch (final RuntimeException re) {
                final SkippedException skippedException = new SkippedException(re);
                taskAborted(skippedException);
                throw skippedException;
            }
            final ScheduledFuture<T> future = executorService.schedule(this, trigger.getNextRunTime(lastExecution, scheduledTime).getTime() - ManagedScheduledExecutorServiceImpl.nowMs(), TimeUnit.MILLISECONDS);
            futureRef.set(future);
            taskSubmitted(future, executorService, delegate);
            return result;
        }
    });
}
Also used : SkippedException(javax.enterprise.concurrent.SkippedException) SkippedException(javax.enterprise.concurrent.SkippedException) Date(java.util.Date) ScheduledFuture(java.util.concurrent.ScheduledFuture)

Aggregations

Date (java.util.Date)1 ScheduledFuture (java.util.concurrent.ScheduledFuture)1 SkippedException (javax.enterprise.concurrent.SkippedException)1