Class WeightedListeningExecutorService

  • All Implemented Interfaces:
    com.google.common.util.concurrent.ListeningExecutorService, Executor, ExecutorService

    public class WeightedListeningExecutorService
    extends com.google.common.util.concurrent.AbstractListeningExecutorService
    A ListeningExecutorService which gates execution using a ListeningMultiSemaphore 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 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 interface ExecutorService
        Specified by:
        submit in interface com.google.common.util.concurrent.ListeningExecutorService
        Overrides:
        submit in class com.google.common.util.concurrent.AbstractListeningExecutorService
      • submit

        @Nonnull
        public <T> com.google.common.util.concurrent.ListenableFuture<T> submit​(Runnable task,
                                                                                @Nullable
                                                                                T result)
        Specified by:
        submit in interface ExecutorService
        Specified by:
        submit in interface com.google.common.util.concurrent.ListeningExecutorService
        Overrides:
        submit in class com.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 interface ExecutorService
        Specified by:
        submit in interface com.google.common.util.concurrent.ListeningExecutorService
        Overrides:
        submit in class com.google.common.util.concurrent.AbstractListeningExecutorService
      • isShutdown

        public final boolean isShutdown()
      • isTerminated

        public final boolean isTerminated()
      • shutdown

        public final void shutdown()