Class WeightedListeningExecutorService
- java.lang.Object
-
- java.util.concurrent.AbstractExecutorService
-
- com.google.common.util.concurrent.AbstractListeningExecutorService
-
- com.facebook.buck.util.concurrent.WeightedListeningExecutorService
-
- All Implemented Interfaces:
com.google.common.util.concurrent.ListeningExecutorService
,Executor
,ExecutorService
public class WeightedListeningExecutorService extends com.google.common.util.concurrent.AbstractListeningExecutorService
AListeningExecutorService
which gates execution using aListeningMultiSemaphore
and allows resources to be assigned to submitted tasks.NOTE: If futures for submitted jobs are cancelled while they are running, it's possible that the semaphore will be released for that cancelled job before it is finished, meaning more jobs may be scheduled than expected.
-
-
Constructor Summary
Constructors Constructor Description WeightedListeningExecutorService(ListeningMultiSemaphore semaphore, ResourceAmounts defaultValues, com.google.common.util.concurrent.ListeningExecutorService delegate)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
awaitTermination(long timeout, TimeUnit unit)
void
execute(Runnable command)
boolean
isShutdown()
boolean
isTerminated()
void
shutdown()
List<Runnable>
shutdownNow()
com.google.common.util.concurrent.ListenableFuture<?>
submit(Runnable task)
com.google.common.util.concurrent.ListenableFuture<?>
submit(Runnable task, ResourceAmounts amounts)
<T> com.google.common.util.concurrent.ListenableFuture<T>
submit(Runnable task, T result)
<T> com.google.common.util.concurrent.ListenableFuture<T>
submit(Runnable task, T result, ResourceAmounts amounts)
<T> com.google.common.util.concurrent.ListenableFuture<T>
submit(Callable<T> task)
<T> com.google.common.util.concurrent.ListenableFuture<T>
submit(Callable<T> task, ResourceAmounts amounts)
WeightedListeningExecutorService
withDefaultAmounts(ResourceAmounts newDefaultAmounts)
Creates a new service that has different default resource amounts.-
Methods inherited from class com.google.common.util.concurrent.AbstractListeningExecutorService
newTaskFor, newTaskFor
-
Methods inherited from class java.util.concurrent.AbstractExecutorService
invokeAll, invokeAll, invokeAny, invokeAny
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.util.concurrent.ExecutorService
invokeAny, invokeAny
-
-
-
-
Constructor Detail
-
WeightedListeningExecutorService
public WeightedListeningExecutorService(ListeningMultiSemaphore semaphore, ResourceAmounts defaultValues, com.google.common.util.concurrent.ListeningExecutorService delegate)
-
-
Method Detail
-
withDefaultAmounts
public WeightedListeningExecutorService withDefaultAmounts(ResourceAmounts newDefaultAmounts)
Creates a new service that has different default resource amounts. Useful when you need to propagate explicit default amounts when you submit the job through execute(), Futures.transform() and similar calls.- Parameters:
newDefaultAmounts
- new default amounts- Returns:
- Service that uses the same semaphore and delegate but with the given default resource amounts.
-
submit
public com.google.common.util.concurrent.ListenableFuture<?> submit(Runnable task, ResourceAmounts amounts)
-
submit
@Nonnull public com.google.common.util.concurrent.ListenableFuture<?> submit(Runnable task)
- Specified by:
submit
in interfaceExecutorService
- Specified by:
submit
in interfacecom.google.common.util.concurrent.ListeningExecutorService
- Overrides:
submit
in classcom.google.common.util.concurrent.AbstractListeningExecutorService
-
submit
public <T> com.google.common.util.concurrent.ListenableFuture<T> submit(Runnable task, @Nullable T result, ResourceAmounts amounts)
-
submit
@Nonnull public <T> com.google.common.util.concurrent.ListenableFuture<T> submit(Runnable task, @Nullable T result)
- Specified by:
submit
in interfaceExecutorService
- Specified by:
submit
in interfacecom.google.common.util.concurrent.ListeningExecutorService
- Overrides:
submit
in classcom.google.common.util.concurrent.AbstractListeningExecutorService
-
submit
public <T> com.google.common.util.concurrent.ListenableFuture<T> submit(Callable<T> task, ResourceAmounts amounts)
-
submit
@Nonnull public <T> com.google.common.util.concurrent.ListenableFuture<T> submit(Callable<T> task)
- Specified by:
submit
in interfaceExecutorService
- Specified by:
submit
in interfacecom.google.common.util.concurrent.ListeningExecutorService
- Overrides:
submit
in classcom.google.common.util.concurrent.AbstractListeningExecutorService
-
awaitTermination
public final boolean awaitTermination(long timeout, @Nonnull TimeUnit unit) throws InterruptedException
- Throws:
InterruptedException
-
isShutdown
public final boolean isShutdown()
-
isTerminated
public final boolean isTerminated()
-
shutdown
public final void shutdown()
-
-