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 booleanawaitTermination(long timeout, java.util.concurrent.TimeUnit unit)voidexecute(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> TinvokeAny(java.util.Collection<? extends java.util.concurrent.Callable<T>> tasks)<T> TinvokeAny(java.util.Collection<? extends java.util.concurrent.Callable<T>> tasks, long timeout, java.util.concurrent.TimeUnit unit)booleanisShutdown()Returns true if this resource has been shut down.booleanisTerminated()Returns true if the resource has completed shutting down.voidshutdown()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.voidwaitForShutdown()Waits for shutdown to completevoidwaitForShutdown(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:
executein interfacejava.util.concurrent.Executor- See Also:
Executor.execute(Runnable)
-
shutdown
public void shutdown()
Description copied from interface:ShutdownableStarts the shutdown process. It is recommended to perform the actual shutdown activity in a separate thread from the thread that calls shutdown- Specified by:
shutdownin interfacejava.util.concurrent.ExecutorService- Specified by:
shutdownin interfaceShutdownable- See Also:
ExecutorService.shutdown()
-
shutdownNow
@Nonnull public final java.util.List<java.lang.Runnable> shutdownNow()
- Specified by:
shutdownNowin interfacejava.util.concurrent.ExecutorService- See Also:
ExecutorService.shutdownNow()
-
isShutdown
public final boolean isShutdown()
Description copied from interface:ShutdownableResourceReturns true if this resource has been shut down.- Specified by:
isShutdownin interfacejava.util.concurrent.ExecutorService- Specified by:
isShutdownin interfaceShutdownableResource- Returns:
- true if this resource has been shut down
- See Also:
ExecutorService.isShutdown()
-
isTerminated
public final boolean isTerminated()
Description copied from interface:ShutdownableResourceReturns true if the resource has completed shutting down. Note that isTerminated is never true unless shutdown was called first.- Specified by:
isTerminatedin interfacejava.util.concurrent.ExecutorService- Specified by:
isTerminatedin 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.IllegalStateExceptionDescription copied from interface:ShutdownableWaits for shutdown to complete- Specified by:
waitForShutdownin 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.TimeoutExceptionDescription copied from interface:ShutdownableWaits for shutdown to complete with a timeout- Specified by:
waitForShutdownin 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:
awaitTerminationin 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:ExecutorServiceSubmits a Runnable task for execution and returns a Future representing that task. The Future'sgetmethod will returnnullupon successful completion.- Specified by:
submitin interfaceExecutorService- Specified by:
submitin interfacejava.util.concurrent.ExecutorService- Overrides:
submitin 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:ExecutorServiceSubmits a value-returning task for execution and returns a Future representing the pending results of the task. The Future'sgetmethod 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
Executorsclass includes a set of methods that can convert some other common closure-like objects, for example,PrivilegedActiontoCallableform so they can be submitted.- Specified by:
submitin interfaceExecutorService- Specified by:
submitin interfacejava.util.concurrent.ExecutorService- Overrides:
submitin 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:ExecutorServiceSubmits a Runnable task for execution and returns a Future representing that task. The Future'sgetmethod will return the given result upon successful completion.- Specified by:
submitin interfaceExecutorService- Specified by:
submitin interfacejava.util.concurrent.ExecutorService- Overrides:
submitin 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:
invokeAllin interfacejava.util.concurrent.ExecutorService- Overrides:
invokeAllin 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:
invokeAllin interfacejava.util.concurrent.ExecutorService- Overrides:
invokeAllin 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:
invokeAnyin interfacejava.util.concurrent.ExecutorService- Overrides:
invokeAnyin classjava.util.concurrent.AbstractExecutorService- Throws:
java.lang.InterruptedExceptionjava.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:
invokeAnyin interfacejava.util.concurrent.ExecutorService- Overrides:
invokeAnyin classjava.util.concurrent.AbstractExecutorService- Throws:
java.lang.InterruptedExceptionjava.util.concurrent.ExecutionExceptionjava.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:ShutdownableExecutorServiceReturns an object that implements the given interface to allow access to non-standard methods, or standard methods not exposed by the proxy.- Specified by:
unwrapin 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)
-
-