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); }
@Override protected void done() { run(onComplete); }
/** * Closes the tracker and the underlying store. * * @throws IOException */ @Override public void close() throws IOException { store.close(); new ExecutorCloser(scheduler).close(); }
@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); }
/** * 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 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 public void run() { currentTask = new NotifyingFutureTask(task); executor.execute(currentTask); } };
/** * Run a task concurrently in 2 threads for 1 second. * * @param message the message * @param task the task * @throws Exception the first exception that is thrown (if any) */ public static void run(String message, Task task) throws Exception { run(message, task, 2, 1000); }
@Override public void close() throws IOException { new ExecutorCloser(scheduledExecutor).close(); new ExecutorCloser(executor).close(); } }
public static NotifyingFutureTask completed() { NotifyingFutureTask f = new NotifyingFutureTask(NOP); f.run(); return f; } }
/** * 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); 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); }
@Override protected void done() { run(onComplete); }
@Test public void test() throws Exception { Concurrent.run("cache", new Concurrent.Task() { @Override public void call() throws Exception { int k = value++ % 10; Data v = cache.get(k); Assert.assertEquals(k, v.value); } }); }
@Override protected void after() { try { store.close(); } finally { new ExecutorCloser(executor).close(); } }
public static NotifyingFutureTask completed() { NotifyingFutureTask f = new NotifyingFutureTask(NOP); f.run(); return f; } }
/** * 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); }