Class ShutdownableExecutorServiceImpl<E extends ExecutorService>

    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected E _e  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean awaitTermination​(long timeout, java.util.concurrent.TimeUnit unit)  
      void execute​(java.lang.Runnable command)  
      <T> java.util.List<java.util.concurrent.Future<T>> invokeAll​(java.util.Collection<? extends java.util.concurrent.Callable<T>> tasks)  
      <T> java.util.List<java.util.concurrent.Future<T>> invokeAll​(java.util.Collection<? extends java.util.concurrent.Callable<T>> tasks, long timeout, java.util.concurrent.TimeUnit unit)  
      <T> T invokeAny​(java.util.Collection<? extends java.util.concurrent.Callable<T>> tasks)  
      <T> T invokeAny​(java.util.Collection<? extends java.util.concurrent.Callable<T>> tasks, long timeout, java.util.concurrent.TimeUnit unit)  
      boolean isShutdown()
      Returns true if this resource has been shut down.
      boolean isTerminated()
      Returns true if the resource has completed shutting down.
      void shutdown()
      Starts the shutdown process.
      java.util.List<java.lang.Runnable> shutdownNow()  
      AsyncFuture<?> submit​(java.lang.Runnable task)
      Submits a Runnable task for execution and returns a Future representing that task.
      <T> AsyncFuture<T> submit​(java.lang.Runnable task, T result)
      Submits a Runnable task for execution and returns a Future representing that task.
      <T> AsyncFuture<T> submit​(java.util.concurrent.Callable<T> task)
      Submits a value-returning task for execution and returns a Future representing the pending results of the task.
      <T extends ExecutorService>
      T
      unwrap​(java.lang.Class<T> clazz)
      Returns an object that implements the given interface to allow access to non-standard methods, or standard methods not exposed by the proxy.
      void waitForShutdown()
      Waits for shutdown to complete
      void waitForShutdown​(long timeoutInMs)
      Waits for shutdown to complete with a timeout
      • Methods inherited from class java.util.concurrent.AbstractExecutorService

        newTaskFor, newTaskFor
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ShutdownableExecutorServiceImpl

        public ShutdownableExecutorServiceImpl​(@Nonnull
                                               E executor)
    • Method Detail

      • execute

        public final void execute​(@Nonnull
                                  java.lang.Runnable command)
        Specified by:
        execute in interface java.util.concurrent.Executor
        See Also:
        Executor.execute(Runnable)
      • shutdown

        public void shutdown()
        Description copied from interface: Shutdownable
        Starts the shutdown process. It is recommended to perform the actual shutdown activity in a separate thread from the thread that calls shutdown
        Specified by:
        shutdown in interface java.util.concurrent.ExecutorService
        Specified by:
        shutdown in interface Shutdownable
        See Also:
        ExecutorService.shutdown()
      • shutdownNow

        @Nonnull
        public final java.util.List<java.lang.Runnable> shutdownNow()
        Specified by:
        shutdownNow in interface java.util.concurrent.ExecutorService
        See Also:
        ExecutorService.shutdownNow()
      • isShutdown

        public final boolean isShutdown()
        Description copied from interface: ShutdownableResource
        Returns true if this resource has been shut down.
        Specified by:
        isShutdown in interface java.util.concurrent.ExecutorService
        Specified by:
        isShutdown in interface ShutdownableResource
        Returns:
        true if this resource has been shut down
        See Also:
        ExecutorService.isShutdown()
      • isTerminated

        public final boolean isTerminated()
        Description copied from interface: ShutdownableResource
        Returns true if the resource has completed shutting down. Note that isTerminated is never true unless shutdown was called first.
        Specified by:
        isTerminated in interface java.util.concurrent.ExecutorService
        Specified by:
        isTerminated in interface ShutdownableResource
        Returns:
        true if the resource has completed shutting down.
        See Also:
        ExecutorService.isTerminated()
      • waitForShutdown

        public final void waitForShutdown()
                                   throws java.lang.InterruptedException,
                                          java.lang.IllegalStateException
        Description copied from interface: Shutdownable
        Waits for shutdown to complete
        Specified by:
        waitForShutdown in interface Shutdownable
        Throws:
        java.lang.InterruptedException - when the wait is interrupted
        java.lang.IllegalStateException - when the method is invoked when the shutdown has yet to be started
        See Also:
        Shutdownable.waitForShutdown()
      • waitForShutdown

        public final void waitForShutdown​(long timeoutInMs)
                                   throws java.lang.InterruptedException,
                                          java.lang.IllegalStateException,
                                          java.util.concurrent.TimeoutException
        Description copied from interface: Shutdownable
        Waits for shutdown to complete with a timeout
        Specified by:
        waitForShutdown in interface Shutdownable
        Parameters:
        timeoutInMs - number of milliseconds to wait before throwing TimeoutException
        Throws:
        java.lang.InterruptedException - when the wait is interrupted
        java.lang.IllegalStateException - when the method is invoked when the shutdown has yet to be started
        java.util.concurrent.TimeoutException - when the operation times out
        See Also:
        Shutdownable.waitForShutdown(long)
      • awaitTermination

        public final boolean awaitTermination​(long timeout,
                                              @Nonnull
                                              java.util.concurrent.TimeUnit unit)
                                       throws java.lang.InterruptedException
        Specified by:
        awaitTermination in interface java.util.concurrent.ExecutorService
        Throws:
        java.lang.InterruptedException
        See Also:
        ExecutorService.awaitTermination(long, java.util.concurrent.TimeUnit)
      • submit

        @Nonnull
        public final AsyncFuture<?> submit​(@Nonnull
                                           java.lang.Runnable task)
        Description copied from interface: ExecutorService
        Submits a Runnable task for execution and returns a Future representing that task. The Future's get method will return null upon successful completion.
        Specified by:
        submit in interface ExecutorService
        Specified by:
        submit in interface java.util.concurrent.ExecutorService
        Overrides:
        submit in class java.util.concurrent.AbstractExecutorService
        Parameters:
        task - the task to submit
        Returns:
        a Future representing pending completion of the task
        See Also:
        ExecutorService.submit(Runnable)
      • submit

        @Nonnull
        public final <T> AsyncFuture<T> submit​(@Nonnull
                                               java.util.concurrent.Callable<T> task)
        Description copied from interface: ExecutorService
        Submits a value-returning task for execution and returns a Future representing the pending results of the task. The Future's get method will return the task's result upon successful completion.

        If you would like to immediately block waiting for a task, you can use constructions of the form result = exec.submit(aCallable).get();

        Note: The Executors class includes a set of methods that can convert some other common closure-like objects, for example, PrivilegedAction to Callable form so they can be submitted.

        Specified by:
        submit in interface ExecutorService
        Specified by:
        submit in interface java.util.concurrent.ExecutorService
        Overrides:
        submit in class java.util.concurrent.AbstractExecutorService
        Type Parameters:
        T - the type of the task's result
        Parameters:
        task - the task to submit
        Returns:
        a Future representing pending completion of the task
        See Also:
        ExecutorService.submit(Callable)
      • submit

        @Nonnull
        public final <T> AsyncFuture<T> submit​(@Nonnull
                                               java.lang.Runnable task,
                                               T result)
        Description copied from interface: ExecutorService
        Submits a Runnable task for execution and returns a Future representing that task. The Future's get method will return the given result upon successful completion.
        Specified by:
        submit in interface ExecutorService
        Specified by:
        submit in interface java.util.concurrent.ExecutorService
        Overrides:
        submit in class java.util.concurrent.AbstractExecutorService
        Type Parameters:
        T - the type of the result
        Parameters:
        task - the task to submit
        result - the result to return
        Returns:
        a Future representing pending completion of the task
        See Also:
        ExecutorService.submit(Runnable, Object)
      • invokeAll

        @Nonnull
        public final <T> java.util.List<java.util.concurrent.Future<T>> invokeAll​(@Nonnull
                                                                                  java.util.Collection<? extends java.util.concurrent.Callable<T>> tasks)
                                                                           throws java.lang.InterruptedException
        Specified by:
        invokeAll in interface java.util.concurrent.ExecutorService
        Overrides:
        invokeAll in class java.util.concurrent.AbstractExecutorService
        Throws:
        java.lang.InterruptedException
        See Also:
        ExecutorService.invokeAll(Collection)
      • invokeAll

        @Nonnull
        public final <T> java.util.List<java.util.concurrent.Future<T>> invokeAll​(@Nonnull
                                                                                  java.util.Collection<? extends java.util.concurrent.Callable<T>> tasks,
                                                                                  long timeout,
                                                                                  @Nonnull
                                                                                  java.util.concurrent.TimeUnit unit)
                                                                           throws java.lang.InterruptedException
        Specified by:
        invokeAll in interface java.util.concurrent.ExecutorService
        Overrides:
        invokeAll in class java.util.concurrent.AbstractExecutorService
        Throws:
        java.lang.InterruptedException
        See Also:
        ExecutorService.invokeAll(Collection, long, TimeUnit)
      • invokeAny

        public final <T> T invokeAny​(@Nonnull
                                     java.util.Collection<? extends java.util.concurrent.Callable<T>> tasks)
                              throws java.lang.InterruptedException,
                                     java.util.concurrent.ExecutionException
        Specified by:
        invokeAny in interface java.util.concurrent.ExecutorService
        Overrides:
        invokeAny in class java.util.concurrent.AbstractExecutorService
        Throws:
        java.lang.InterruptedException
        java.util.concurrent.ExecutionException
        See Also:
        ExecutorService.invokeAny(Collection)
      • invokeAny

        public final <T> T invokeAny​(@Nonnull
                                     java.util.Collection<? extends java.util.concurrent.Callable<T>> tasks,
                                     long timeout,
                                     @Nonnull
                                     java.util.concurrent.TimeUnit unit)
                              throws java.lang.InterruptedException,
                                     java.util.concurrent.ExecutionException,
                                     java.util.concurrent.TimeoutException
        Specified by:
        invokeAny in interface java.util.concurrent.ExecutorService
        Overrides:
        invokeAny in class java.util.concurrent.AbstractExecutorService
        Throws:
        java.lang.InterruptedException
        java.util.concurrent.ExecutionException
        java.util.concurrent.TimeoutException
        See Also:
        ExecutorService.invokeAny(Collection, long, TimeUnit)
      • unwrap

        public final <T extends ExecutorService> T unwrap​(java.lang.Class<T> clazz)
        Description copied from interface: ShutdownableExecutorService
        Returns an object that implements the given interface to allow access to non-standard methods, or standard methods not exposed by the proxy.
        Specified by:
        unwrap in interface ShutdownableExecutorService
        Parameters:
        clazz - A Class defining an interface that the result must implement.
        Returns:
        an object that implements the interface. May be a proxy for the actual implementing object.
        See Also:
        ShutdownableExecutorService.unwrap(Class)