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
,java.util.concurrent.Executor
,java.util.concurrent.ExecutorService
- Direct Known Subclasses:
ShutdownableScheduledExecutorServiceImpl
public class ShutdownableExecutorServiceImpl<E extends ExecutorService> extends java.util.concurrent.AbstractExecutorService implements ShutdownableExecutorService
-
-
Constructor Summary
Constructors Constructor Description ShutdownableExecutorServiceImpl(E executor)
-
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>
Tunwrap(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 completevoid
waitForShutdown(long timeoutInMs)
Waits for shutdown to complete with a timeout
-
-
-
Field Detail
-
_e
@Nonnull protected final E extends ExecutorService _e
-
-
Constructor Detail
-
ShutdownableExecutorServiceImpl
public ShutdownableExecutorServiceImpl(@Nonnull E executor)
-
-
Method Detail
-
execute
public final void execute(@Nonnull java.lang.Runnable command)
- Specified by:
execute
in interfacejava.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 interfacejava.util.concurrent.ExecutorService
- Specified by:
shutdown
in interfaceShutdownable
- See Also:
ExecutorService.shutdown()
-
shutdownNow
@Nonnull public final java.util.List<java.lang.Runnable> shutdownNow()
- Specified by:
shutdownNow
in interfacejava.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 interfacejava.util.concurrent.ExecutorService
- Specified by:
isShutdown
in interfaceShutdownableResource
- 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 interfacejava.util.concurrent.ExecutorService
- Specified by:
isTerminated
in interfaceShutdownableResource
- 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 interfaceShutdownable
- Throws:
java.lang.InterruptedException
- when the wait is interruptedjava.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 interfaceShutdownable
- Parameters:
timeoutInMs
- number of milliseconds to wait before throwing TimeoutException- Throws:
java.lang.InterruptedException
- when the wait is interruptedjava.lang.IllegalStateException
- when the method is invoked when the shutdown has yet to be startedjava.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 interfacejava.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'sget
method will returnnull
upon successful completion.- Specified by:
submit
in interfaceExecutorService
- Specified by:
submit
in interfacejava.util.concurrent.ExecutorService
- Overrides:
submit
in classjava.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'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 interfacejava.util.concurrent.ExecutorService
- Overrides:
submit
in classjava.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'sget
method will return the given result upon successful completion.- Specified by:
submit
in interfaceExecutorService
- Specified by:
submit
in interfacejava.util.concurrent.ExecutorService
- Overrides:
submit
in classjava.util.concurrent.AbstractExecutorService
- 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:
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 interfacejava.util.concurrent.ExecutorService
- Overrides:
invokeAll
in classjava.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 interfacejava.util.concurrent.ExecutorService
- Overrides:
invokeAll
in classjava.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 interfacejava.util.concurrent.ExecutorService
- Overrides:
invokeAny
in classjava.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 interfacejava.util.concurrent.ExecutorService
- Overrides:
invokeAny
in classjava.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 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:
ShutdownableExecutorService.unwrap(Class)
-
-