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
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal booleanawaitTermination(long timeout, TimeUnit unit) final voidinvokeAll(Collection<? extends Callable<T>> tasks) invokeAll(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) final <T> TinvokeAny(Collection<? extends Callable<T>> tasks) final <T> TinvokeAny(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) final booleanReturns true if this resource has been shut down.final booleanReturns true if the resource has completed shutting down.voidshutdown()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 voidWaits for shutdown to completefinal voidwaitForShutdown(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: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 interfaceExecutorService- Specified by:
shutdownin interfaceShutdownable- See Also:
-
shutdownNow
- Specified by:
shutdownNowin interfaceExecutorService- See Also:
-
isShutdown
public final boolean isShutdown()Description copied from interface:ShutdownableResourceReturns true if this resource has been shut down.- Specified by:
isShutdownin interfaceExecutorService- Specified by:
isShutdownin interfaceShutdownableResource- Returns:
- true if this resource has been shut down
- See Also:
-
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 interfaceExecutorService- Specified by:
isTerminatedin interfaceShutdownableResource- Returns:
- true if the resource has completed shutting down.
- See Also:
-
waitForShutdown
Description copied from interface:ShutdownableWaits for shutdown to complete- Specified by:
waitForShutdownin 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:ShutdownableWaits for shutdown to complete with a timeout- Specified by:
waitForShutdownin 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:
awaitTerminationin interfaceExecutorService- Throws:
InterruptedException- See Also:
-
submit
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 interfaceExecutorService- Overrides:
submitin classAbstractExecutorService- Parameters:
task- the task to submit- Returns:
- a Future representing pending completion of the task
- See Also:
-
submit
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 interfaceExecutorService- Overrides:
submitin 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: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 interfaceExecutorService- Overrides:
submitin 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:
invokeAllin interfaceExecutorService- Overrides:
invokeAllin 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:
invokeAllin interfaceExecutorService- Overrides:
invokeAllin classAbstractExecutorService- Throws:
InterruptedException- See Also:
-
invokeAny
public final <T> T invokeAny(@Nonnull Collection<? extends Callable<T>> tasks) throws InterruptedException, ExecutionException - Specified by:
invokeAnyin interfaceExecutorService- Overrides:
invokeAnyin classAbstractExecutorService- Throws:
InterruptedExceptionExecutionException- 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:
invokeAnyin interfaceExecutorService- Overrides:
invokeAnyin classAbstractExecutorService- Throws:
InterruptedExceptionExecutionExceptionTimeoutException- See Also:
-
unwrap
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:
-