/** * Exact same as the submit counter part, except you can specify how many permits this task will * require/use (instead of defaulting to 1). The task will be scheduled out as far as necessary * to ensure it conforms to the set rate. * * @param permits resource permits for this task * @param task Runnable to execute when ready * @return Future that will indicate when the execution of this task has completed */ public ListenableFuture<?> submit(double permits, Runnable task) { return submit(permits, task, null); }
/** * Exact same as the submit counter part, except you can specify how many permits this task will * require/use (instead of defaulting to 1). The task will be scheduled out as far as necessary * to ensure it conforms to the set rate. * * @param permits resource permits for this task * @param task Runnable to execute when ready * @return Future that will indicate when the execution of this task has completed */ public ListenableFuture<?> submit(double permits, Runnable task) { return submit(permits, task, null); }
@Override public <T> ListenableFuture<T> submit(Runnable task, T result) { return submit(1, task, result); }
@Override public <T> ListenableFuture<T> submit(Callable<T> task) { return submit(1, task); }
@Override public <T> ListenableFuture<T> submit(Runnable task, T result) { return submit(1, task, result); }
@Override public <T> ListenableFuture<T> submit(Callable<T> task) { return submit(1, task); }
/** * Submit a callable to be run with a given thread key. * <p> * See also: {@link SubmitterExecutor#submit(Callable)} and * {@link RateLimiterExecutor#submit(double, Callable)}. * * @param <T> type of result returned from the future * @param permits resource permits for this task * @param taskKey object key where {@code equals()} will be used to determine execution thread * @param task Callable to be executed * @return Future to represent when the execution has occurred and provide the result from the callable */ public <T> ListenableFuture<T> submit(double permits, Object taskKey, Callable<T> task) { return limiterForKey(taskKey, (l) -> l.submit(permits, task)); }
/** * Submit a task to be run with a given thread key. * <p> * See also: {@link SubmitterExecutor#submit(Runnable, Object)} and * {@link RateLimiterExecutor#submit(double, Runnable, Object)}. * * @param <T> type of result returned from the future * @param permits resource permits for this task * @param taskKey object key where {@code equals()} will be used to determine execution thread * @param task Runnable to be executed * @param result Result to be returned from future when task completes * @return Future to represent when the execution has occurred and provide the given result */ public <T> ListenableFuture<T> submit(double permits, Object taskKey, Runnable task, T result) { // we go directly to the limiter here to get DoNothingRunnable optimizations (can't wrap task) return limiterForKey(taskKey, (l) -> l.submit(permits, task, result)); }
/** * Submit a callable to be run with a given thread key. * <p> * See also: {@link SubmitterExecutor#submit(Callable)} and * {@link RateLimiterExecutor#submit(double, Callable)}. * * @param <T> type of result returned from the future * @param permits resource permits for this task * @param taskKey object key where {@code equals()} will be used to determine execution thread * @param task Callable to be executed * @return Future to represent when the execution has occurred and provide the result from the callable */ public <T> ListenableFuture<T> submit(double permits, Object taskKey, Callable<T> task) { return limiterForKey(taskKey, (l) -> l.submit(permits, task)); }
/** * Submit a task to be run with a given thread key. * <p> * See also: {@link SubmitterExecutor#submit(Runnable, Object)} and * {@link RateLimiterExecutor#submit(double, Runnable, Object)}. * * @param <T> type of result returned from the future * @param permits resource permits for this task * @param taskKey object key where {@code equals()} will be used to determine execution thread * @param task Runnable to be executed * @param result Result to be returned from future when task completes * @return Future to represent when the execution has occurred and provide the given result */ public <T> ListenableFuture<T> submit(double permits, Object taskKey, Runnable task, T result) { // we go directly to the limiter here to get DoNothingRunnable optimizations (can't wrap task) return limiterForKey(taskKey, (l) -> l.submit(permits, task, result)); }
@Test public void submitRunnableWithPermitsFail() { try { limiter.submit(-1, DoNothingRunnable.instance()); fail("Exception should have thrown"); } catch (IllegalArgumentException e) { // expected } try { limiter.submit(1, (Runnable)null); fail("Exception should have thrown"); } catch (IllegalArgumentException e) { // expected } }
@Test public void submitCallableWithPermitsFail() { try { limiter.submit(-1, new TestCallable()); fail("Exception should have thrown"); } catch (IllegalArgumentException e) { // expected } try { limiter.submit(1, (Callable<?>)null); fail("Exception should have thrown"); } catch (IllegalArgumentException e) { // expected } }