Class CompletionServiceLatch

java.lang.Object
dev.getelements.elements.rt.util.CompletionServiceLatch

public class CompletionServiceLatch extends Object
This is a latch-type object which will allow the caller to wrap Runnable and Callable<?> instances which can be later monitored for the completion of all tasks.
  • Constructor Details

    • CompletionServiceLatch

      public CompletionServiceLatch()
    • CompletionServiceLatch

      public CompletionServiceLatch(Semaphore semaphore)
  • Method Details

    • enqueue

      public <FutureT extends Future<T>, T> FutureT enqueue(Callable<T> callable, Function<Callable<T>,FutureT> futureSupplier)
      Wraps a Callable<T> and returns it. If stop() has been called, then this throws an instance of IllegalStateException.
      Type Parameters:
      T -
      Parameters:
      callable - the Callable<T> to wrap
      Returns:
      a wrapped Callable<T> instance
    • enqueue

      public <FutureT extends Future<T>, T> FutureT enqueue(Runnable runnable, Function<Runnable,FutureT> futureSupplier)
      Wraps a Runnable and returns it. If stop() has been called, then this throws an instance of IllegalStateException.
      Parameters:
      runnable - the Runnable to wrap
      Returns:
      a wrapped Runnable instance
    • stop

      public void stop()
      Stops the latch and prevents it from accepting any more jobs. Before stopping, this will wait for all current tasks to finish