/** * Wait forever for waitable to finish. Periodically reports progress. * * @param waitable Waitable which we wait for * @param progressable Progressable for reporting progress (Job context) * @param <T> Result type * @return Result of waitable */ private static <T> T waitForever(Waitable<T> waitable, Progressable progressable) { return waitForever(waitable, progressable, DEFUALT_MSEC_PERIOD); }
/** * Wait for {@link ChannelGroupFuture} to finish, while periodically * reporting progress. * * @param future ChannelGroupFuture * @param progressable Progressable for reporting progress (Job context) */ public static void awaitChannelGroupFuture(ChannelGroupFuture future, Progressable progressable) { waitForever(new ChannelGroupFutureWaitable(future), progressable); }
/** * Wait for {@link ChannelFuture} to finish, while periodically * reporting progress. * * @param future ChannelFuture * @param progressable Progressable for reporting progress (Job context) */ public static void awaitChannelFuture(ChannelFuture future, Progressable progressable) { waitForever(new ChannelFutureWaitable(future), progressable); }
/** * Wait for executor tasks to terminate, while periodically reporting * progress. * * @param executor Executor which we are waiting for * @param progressable Progressable for reporting progress (Job context) */ public static void awaitExecutorTermination(ExecutorService executor, Progressable progressable) { waitForever(new ExecutorServiceWaitable(executor), progressable); }
/** * Wait for the result of the future to be ready, while periodically * reporting progress. * * @param <T> Type of the return value of the future * @param future Future * @param progressable Progressable for reporting progress (Job context) * @return Computed result of the future. */ public static <T> T getFutureResult(Future<T> future, Progressable progressable) { return waitForever(new FutureWaitable<T>(future), progressable); }
/** * Wait for executor tasks to terminate, while periodically reporting * progress. * * @param executor Executor which we are waiting for * @param progressable Progressable for reporting progress (Job context) * @param msecsPeriod How often to report progress */ public static void awaitExecutorTermination(ExecutorService executor, Progressable progressable, int msecsPeriod) { waitForever(new ExecutorServiceWaitable(executor), progressable, msecsPeriod); }
/** * Wait to acquire enough permits from {@link Semaphore}, while periodically * reporting progress. * * @param semaphore Semaphore * @param permits How many permits to acquire * @param progressable Progressable for reporting progress (Job context) */ public static void awaitSemaphorePermits(final Semaphore semaphore, int permits, Progressable progressable) { while (true) { waitForever(new SemaphoreWaitable(semaphore, permits), progressable); // Verify permits were not taken by another thread, // if they were keep looping if (semaphore.tryAcquire(permits)) { return; } } }
/** * Wait for executorgroup to terminate, while periodically reporting progress * * @param group ExecutorGroup whose termination we are awaiting * @param progressable Progressable for reporting progress (Job context) */ public static void awaitTerminationFuture(EventExecutorGroup group, Progressable progressable) { waitForever(new FutureWaitable<>(group.terminationFuture()), progressable); }