@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); }
@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); }
private void addTask(Callable<Void> task){ checkIfClosed(true); queue.add(task); currentTask.onComplete(completionHandler); }
private void addTask(Callable<Void> task){ checkIfClosed(true); queue.add(task); currentTask.onComplete(completionHandler); }
/** FOR TESTING ONLY * @throws InterruptedException **/ boolean waitUntilStopped(int timeout, TimeUnit unit) throws InterruptedException { long done = System.currentTimeMillis() + unit.toMillis(timeout); boolean added = false; while(done > System.currentTimeMillis()) { synchronized(this) { if (!added) { added = queue.offer(STOP); if (added) { currentTask.onComplete(completionHandler); } } if (added && queue.size() == 0) { return true; } wait(1); } } return false; } }
/** FOR TESTING ONLY * @throws InterruptedException **/ boolean waitUntilStopped(int timeout, TimeUnit unit) throws InterruptedException { long done = System.currentTimeMillis() + unit.toMillis(timeout); boolean added = false; while(done > System.currentTimeMillis()) { synchronized(this) { if (!added) { added = queue.offer(STOP); if (added) { currentTask.onComplete(completionHandler); } } if (added && queue.size() == 0) { return true; } wait(1); } } return false; } }
currentTask.onComplete(completionHandler); added(queue.size());
currentTask.onComplete(completionHandler); added(queue.size());
@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); }
@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); }