Class AbstractShutdownableResource<R>
java.lang.Object
com.linkedin.alpini.base.registry.AbstractShutdownableResource<R>
- All Implemented Interfaces:
Shutdownable
,ShutdownableResource
- Direct Known Subclasses:
SyncShutdownableAdapter
public abstract class AbstractShutdownableResource<R>
extends Object
implements ShutdownableResource
A simplified implementation of a
ShutdownableResource
.-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected abstract Runnable
constructShutdown
(R object) The constructed runnable must callsignalShutdownInitiated()
method to indicate that shutdown has started.final boolean
Returns true if this resource has been shut down.final boolean
Returns true if the resource has completed shutting down.final void
shutdown()
Starts the shutdown process.protected final void
Called by the Runnable to indicate that shutdown has started.final String
toString()
final void
Waits for shutdown to completefinal void
waitForShutdown
(long timeoutInMs) Waits for shutdown to complete with a timeout
-
Constructor Details
-
AbstractShutdownableResource
-
-
Method Details
-
signalShutdownInitiated
protected final void signalShutdownInitiated()Called by the Runnable to indicate that shutdown has started. -
constructShutdown
The constructed runnable must callsignalShutdownInitiated()
method to indicate that shutdown has started.- Parameters:
object
- Object to be shutdown- Returns:
- Runnable instance
-
isShutdown
public final boolean isShutdown()Returns true if this resource has been shut down.- Specified by:
isShutdown
in interfaceShutdownableResource
- Returns:
- true if this resource has been shut down
-
isTerminated
public final boolean isTerminated()Returns true if the resource has completed shutting down. Note that isTerminated is never true unless shutdown was called first.- Specified by:
isTerminated
in interfaceShutdownableResource
- Returns:
- true if the resource has completed shutting down.
-
shutdown
public final void shutdown()Starts the shutdown process. The Runnable returned by constructShutdown() must callsignalShutdownInitiated()
.- Specified by:
shutdown
in interfaceShutdownable
-
waitForShutdown
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 start
-
waitForShutdown
public final void waitForShutdown(long timeoutInMs) throws InterruptedException, IllegalStateException, TimeoutException 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 startTimeoutException
- when the operation times out
-
toString
-