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 java.lang.Object implements ShutdownableResource
A simplified implementation of aShutdownableResource
.
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractShutdownableResource(R object)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract java.lang.Runnable
constructShutdown(R object)
The constructed runnable must callsignalShutdownInitiated()
method to indicate that shutdown has started.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.protected void
signalShutdownInitiated()
Called by the Runnable to indicate that shutdown has started.java.lang.String
toString()
void
waitForShutdown()
Waits for shutdown to completevoid
waitForShutdown(long timeoutInMs)
Waits for shutdown to complete with a timeout
-
-
-
Constructor Detail
-
AbstractShutdownableResource
protected AbstractShutdownableResource(R object)
-
-
Method Detail
-
signalShutdownInitiated
protected final void signalShutdownInitiated()
Called by the Runnable to indicate that shutdown has started.
-
constructShutdown
protected abstract java.lang.Runnable constructShutdown(R object)
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
public final void waitForShutdown() throws java.lang.InterruptedException, java.lang.IllegalStateException
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 start
-
waitForShutdown
public final void waitForShutdown(long timeoutInMs) throws java.lang.InterruptedException, java.lang.IllegalStateException, java.util.concurrent.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:
java.lang.InterruptedException
- when the wait is interruptedjava.lang.IllegalStateException
- when the method is invoked when the shutdown has yet to startjava.util.concurrent.TimeoutException
- when the operation times out
-
toString
public final java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-