/** * the callable function will run as soon as the currently active set of futures is less than the * maxConcurrency limit. * * @param callable - a function that creates a future. * @return a proxy future that completes with the future created by the input function. This * future will be immediately failed with {@link CapacityReachedException} if the soft queue * size limit is exceeded. */ public CompletableFuture<T> add(final Callable<? extends CompletionStage<T>> callable) { requireNonNull(callable); final CompletableFuture<T> response = new CompletableFuture<>(); final Job<T> job = new Job<>(callable, response); if (!queue.offer(job)) { final String message = "Queue size has reached capacity: " + maxQueueSize; return CompletableFutures.exceptionallyCompletedFuture(new CapacityReachedException(message)); } pump(); return response; }
/** * the callable function will run as soon as the currently active set of futures is less than the * maxConcurrency limit. * * @param callable - a function that creates a future. * @return a proxy future that completes with the future created by the input function. This * future will be immediately failed with {@link CapacityReachedException} if the soft queue * size limit is exceeded. */ public CompletableFuture<T> add(final Callable<? extends CompletionStage<T>> callable) { requireNonNull(callable); final CompletableFuture<T> response = new CompletableFuture<>(); final Job<T> job = new Job<>(callable, response); if (!queue.offer(job)) { final String message = "Queue size has reached capacity: " + maxQueueSize; return CompletableFutures.exceptionallyCompletedFuture(new CapacityReachedException(message)); } pump(); return response; }