private void scheduleNextRun() { Date nextRunTime = trigger.getNextRunTime(lastExecution, taskScheduledTime); if (nextRunTime == null) { // no more tasks to run for this Trigger done(null); // this will call task listeners set(null); // to update status of this Future to RAN return; } long ns = triggerTime(nextRunTime.getTime() - System.currentTimeMillis(), TimeUnit.MILLISECONDS); try { lock.lock(); ManagedTriggerSingleFutureTask<V> future = new ManagedTriggerSingleFutureTask(executor, callable, ns, nextRunTime.getTime(), this); delayedExecute(future); currentFuture = future; } finally { lock.unlock(); } }
@Override public void run() { if (controller.skipRun(new Date(scheduledRunTime))) { return; } long lastRunStartTime = System.currentTimeMillis(); Object lastResult = null; try { super.run(); lastResult = get(); } catch (Throwable t) { } long lastRunEndTime = System.currentTimeMillis(); controller.doneExecution(lastResult, scheduledRunTime, lastRunStartTime, lastRunEndTime); }
@Override public long getDelay(TimeUnit unit) { return getCurrentFuture().getDelay(unit); }
@Override public int compareTo(Delayed o) { return getCurrentFuture().compareTo(o); }
@Override public V get() throws InterruptedException, ExecutionException { if (skipped) { throw new SkippedException(); } return getCurrentFuture().get(); }
@Override public boolean cancel(boolean mayInterruptIfRunning) { super.cancel(mayInterruptIfRunning); // cancel the next scheduled task return getCurrentFuture().cancel(mayInterruptIfRunning); }
@Override public V get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { if (skipped) { throw new SkippedException(); } return getCurrentFuture().get(timeout, unit); }