public static NotifyingFutureTask completed() { NotifyingFutureTask f = new NotifyingFutureTask(NOP); f.run(); return f; } }
@Override public void scheduleQueuedDocsProcessing() { // Set the completion handler on the currently running task. Multiple calls // to onComplete are not a problem here since we always pass the same value. // Thus there is no question as to which of the handlers will effectively run. currentTask.onComplete(completionHandler); }
/** * Set the on complete handler. The handler will run exactly once after * the task terminated. If the task has already terminated at the time of * this method call the handler will execute immediately. * <p> * Note: there is no guarantee to which handler will run when the method * is called multiple times with different arguments. * </p> * @param onComplete listener to invoke upon completion */ public void onComplete(Runnable onComplete) { this.onComplete = onComplete; if (isDone()) { run(onComplete); } }
@Test public void onCompletion() throws Exception{ CountingCallable callable = new CountingCallable(); CountingRunnable runnable = new CountingRunnable(); NotifyingFutureTask nft = new NotifyingFutureTask(callable); nft.onComplete(runnable); nft.run(); assertEquals(1, callable.count); assertEquals(1, runnable.count); nft.run(); assertEquals("Callback should be invoked only once", 1, runnable.count); }
@Override public void run() { currentTask = new NotifyingFutureTask(task); executor.execute(currentTask); } };
@Test public void completed() throws Exception{ CountingRunnable runnable = new CountingRunnable(); NotifyingFutureTask nft = NotifyingFutureTask.completed(); nft.onComplete(runnable); assertEquals("Callback should still be invoked if already done", 1, runnable.count); }
@Override protected void done() { run(onComplete); }
@Override public void run() { currentTask = new NotifyingFutureTask(task); executor.execute(currentTask); } };
@Override protected void done() { run(onComplete); }
public static NotifyingFutureTask completed() { NotifyingFutureTask f = new NotifyingFutureTask(NOP); f.run(); return f; } }
@Override public void run() { currentTask = new NotifyingFutureTask(task); executor.execute(currentTask); } };
@Override public void scheduleQueuedDocsProcessing() { // Set the completion handler on the currently running task. Multiple calls // to onComplete are not a problem here since we always pass the same value. // Thus there is no question as to which of the handlers will effectively run. currentTask.onComplete(completionHandler); }
/** * Set the on complete handler. The handler will run exactly once after * the task terminated. If the task has already terminated at the time of * this method call the handler will execute immediately. * <p> * Note: there is no guarantee to which handler will run when the method * is called multiple times with different arguments. * </p> * @param onComplete listener to invoke upon completion */ public void onComplete(Runnable onComplete) { this.onComplete = onComplete; if (isDone()) { run(onComplete); } }
@Override protected void done() { run(onComplete); }
public static NotifyingFutureTask completed() { NotifyingFutureTask f = new NotifyingFutureTask(NOP); f.run(); return f; } }
@Override public void run() { currentTask = new NotifyingFutureTask(task); try { executor.execute(currentTask); } catch (RejectedExecutionException e){ checkIfClosed(false); throw e; } } };
private void addTask(Callable<Void> task){ checkIfClosed(true); queue.add(task); currentTask.onComplete(completionHandler); }
/** * Set the on complete handler. The handler will run exactly once after * the task terminated. If the task has already terminated at the time of * this method call the handler will execute immediately. * <p> * Note: there is no guarantee to which handler will run when the method * is called multiple times with different arguments. * </p> * @param onComplete listener to invoke upon completion */ public void onComplete(Runnable onComplete) { this.onComplete = onComplete; if (isDone()) { run(onComplete); } }
@Override public void run() { currentTask = new NotifyingFutureTask(task); try { executor.execute(currentTask); } catch (RejectedExecutionException e){ checkIfClosed(false); throw e; } } };
private void addTask(Callable<Void> task){ checkIfClosed(true); queue.add(task); currentTask.onComplete(completionHandler); }