Class ShutdownableExecutorServiceImpl<E extends ExecutorService>
java.lang.Object
java.util.concurrent.AbstractExecutorService
com.linkedin.alpini.base.registry.impl.ShutdownableExecutorServiceImpl<E>
- All Implemented Interfaces:
ExecutorService
,Shutdownable
,ShutdownableExecutorService
,ShutdownableResource
,Executor
,ExecutorService
- Direct Known Subclasses:
ShutdownableScheduledExecutorServiceImpl
public class ShutdownableExecutorServiceImpl<E extends ExecutorService>
extends AbstractExecutorService
implements ShutdownableExecutorService
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionfinal boolean
awaitTermination
(long timeout, TimeUnit unit) final void
invokeAll
(Collection<? extends Callable<T>> tasks) invokeAll
(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) final <T> T
invokeAny
(Collection<? extends Callable<T>> tasks) final <T> T
invokeAny
(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) final boolean
Returns true if this resource has been shut down.final boolean
Returns true if the resource has completed shutting down.void
shutdown()
Starts the shutdown process.final AsyncFuture<?>
Submits a Runnable task for execution and returns a Future representing that task.final <T> AsyncFuture<T>
Submits a Runnable task for execution and returns a Future representing that task.final <T> AsyncFuture<T>
Submits a value-returning task for execution and returns a Future representing the pending results of the task.final <T extends ExecutorService>
TReturns an object that implements the given interface to allow access to non-standard methods, or standard methods not exposed by the proxy.final void
Waits for shutdown to completefinal void
waitForShutdown
(long timeoutInMs) Waits for shutdown to complete with a timeoutMethods inherited from class java.util.concurrent.AbstractExecutorService
newTaskFor, newTaskFor
-
Field Details
-
_e
-
-
Constructor Details
-
ShutdownableExecutorServiceImpl
-
-
Method Details
-
execute
-
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 interfaceExecutorService
- Specified by:
shutdown
in interfaceShutdownable
- See Also:
-
shutdownNow
- Specified by:
shutdownNow
in interfaceExecutorService
- See Also:
-
isShutdown
public final boolean isShutdown()Description copied from interface:ShutdownableResource
Returns true if this resource has been shut down.- Specified by:
isShutdown
in interfaceExecutorService
- Specified by:
isShutdown
in interfaceShutdownableResource
- Returns:
- true if this resource has been shut down
- See Also:
-
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 interfaceExecutorService
- Specified by:
isTerminated
in interfaceShutdownableResource
- Returns:
- true if the resource has completed shutting down.
- See Also:
-
waitForShutdown
Description copied from interface:Shutdownable
Waits for shutdown to complete- Specified by:
waitForShutdown
in interfaceShutdownable
- Throws:
InterruptedException
- when the wait is interruptedIllegalStateException
- when the method is invoked when the shutdown has yet to be started- See Also:
-
waitForShutdown
public final void waitForShutdown(long timeoutInMs) throws InterruptedException, IllegalStateException, TimeoutException Description copied from interface:Shutdownable
Waits for shutdown to complete with a timeout- Specified by:
waitForShutdown
in interfaceShutdownable
- Parameters:
timeoutInMs
- number of milliseconds to wait before throwing TimeoutException- Throws:
InterruptedException
- when the wait is interruptedIllegalStateException
- when the method is invoked when the shutdown has yet to be startedTimeoutException
- when the operation times out- See Also:
-
awaitTermination
public final boolean awaitTermination(long timeout, @Nonnull TimeUnit unit) throws InterruptedException - Specified by:
awaitTermination
in interfaceExecutorService
- Throws:
InterruptedException
- See Also:
-
submit
Description copied from interface:ExecutorService
Submits a Runnable task for execution and returns a Future representing that task. The Future'sget
method will returnnull
upon successful completion.- Specified by:
submit
in interfaceExecutorService
- Specified by:
submit
in interfaceExecutorService
- Overrides:
submit
in classAbstractExecutorService
- Parameters:
task
- the task to submit- Returns:
- a Future representing pending completion of the task
- See Also:
-
submit
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'sget
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
toCallable
form so they can be submitted.- Specified by:
submit
in interfaceExecutorService
- Specified by:
submit
in interfaceExecutorService
- Overrides:
submit
in classAbstractExecutorService
- 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:
-
submit
Description copied from interface:ExecutorService
Submits a Runnable task for execution and returns a Future representing that task. The Future'sget
method will return the given result upon successful completion.- Specified by:
submit
in interfaceExecutorService
- Specified by:
submit
in interfaceExecutorService
- Overrides:
submit
in classAbstractExecutorService
- Type Parameters:
T
- the type of the result- Parameters:
task
- the task to submitresult
- the result to return- Returns:
- a Future representing pending completion of the task
- See Also:
-
invokeAll
@Nonnull public final <T> List<Future<T>> invokeAll(@Nonnull Collection<? extends Callable<T>> tasks) throws InterruptedException - Specified by:
invokeAll
in interfaceExecutorService
- Overrides:
invokeAll
in classAbstractExecutorService
- Throws:
InterruptedException
- See Also:
-
invokeAll
@Nonnull public final <T> List<Future<T>> invokeAll(@Nonnull Collection<? extends Callable<T>> tasks, long timeout, @Nonnull TimeUnit unit) throws InterruptedException - Specified by:
invokeAll
in interfaceExecutorService
- Overrides:
invokeAll
in classAbstractExecutorService
- Throws:
InterruptedException
- See Also:
-
invokeAny
public final <T> T invokeAny(@Nonnull Collection<? extends Callable<T>> tasks) throws InterruptedException, ExecutionException - Specified by:
invokeAny
in interfaceExecutorService
- Overrides:
invokeAny
in classAbstractExecutorService
- Throws:
InterruptedException
ExecutionException
- See Also:
-
invokeAny
public final <T> T invokeAny(@Nonnull Collection<? extends Callable<T>> tasks, long timeout, @Nonnull TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException - Specified by:
invokeAny
in interfaceExecutorService
- Overrides:
invokeAny
in classAbstractExecutorService
- Throws:
InterruptedException
ExecutionException
TimeoutException
- See Also:
-
unwrap
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 interfaceShutdownableExecutorService
- 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:
-