/** * Schedules a task. * * @param taskId the task id, used for looking up results and canceling the task * @param task the task * @param recurs <tt>true</tt> if this is a recurring task * @param intervalMillis number of milliseconds between executions of a recurring task, measured * between the end of the last execution and the start of the next * @param delayMillis number of milliseconds to wait before the first execution */ public void schedule( Object taskId, Callable<V> task, boolean recurs, long intervalMillis, long delayMillis) { ZimbraLog.scheduler.debug("Scheduling task %s", taskId); TaskRunner<V> runner = new TaskRunner<V>(taskId, task, recurs, intervalMillis, mCallbacks); runner.mSchedule = mThreadPool.schedule(runner, delayMillis, TimeUnit.MILLISECONDS); mRunnerMap.put(taskId, runner); }
/** * Returns the <tt>Callable</tt> object for the given <tt>taskId</tt>, or <tt>null</tt> if no * matching task exists. */ public Callable<V> getTask(Object taskId) { TaskRunner<V> runner = mRunnerMap.get(taskId); if (runner == null) { return null; } if (runner.mSchedule.isCancelled()) { return null; } return runner.getTask(); }
/** * Cancels a task. * * @return the task, or <tt>null</tt> if the task couldn't be found. */ public Callable<V> cancel(Object taskId, boolean mayInterruptIfRunning) { // Don't remove the task runner, so that users can get the last result // after a task has been canceled. TaskRunner<V> runner = mRunnerMap.get(taskId); if (runner == null) { return null; } ZimbraLog.scheduler.debug("Cancelling task %s", taskId); runner.mSchedule.cancel(mayInterruptIfRunning); return runner.getTask(); }
// Most of the tests in this file were written when task event // notification was done synchronously in TaskRunner. Reproduce that // behavior here for simplicity. void notify(SchedulableTask task, Schedule.EventType eventType) { if (doImmediateNotify) { task.callback.taskEvent(task, eventType); } else { super.notify(task, eventType); } }
public synchronized boolean stop() { // 停止任务,并取消和线程的绑定,并移除block runner,再次启动的时候创建新的block runner if (!isRunning) { return true; } if (currentRunner != null) { currentRunner.stop(); } currentRunner = null; isRunning = false; return true; }
public TaskRunner create( final long delay, final String containerId, final TaskRunner.Listener listener) { return TaskRunner.builder() .delayMillis(delay) .config(taskConfig) .docker(docker) .healthChecker(healthChecker.orNull()) .existingContainerId(containerId) .listener(new BroadcastingListener(concat(this.listeners, asList(listener)))) .registrar(registrar) .build(); }
public synchronized boolean start() { // 如果已经启动了,则直接返回,否则开启任务 if (isRunning) { return true; } if (executor == null || executor.isShutdown()) { return false; } isRunning = true; currentRunner = new TaskRunner(); Future<TaskRunner> f = executor.submit(currentRunner, currentRunner); currentRunner.boundFutrue(f); return true; }
void removeTask(StepTask task) { removedTasks.add(task); super.removeTask(task); }
void removeChunk(Schedule.Chunk chunk) { removedChunks.add(chunk); super.removeChunk(chunk); }