T - the type of the closeable resourcepublic abstract class AbstractHandleableCloseable<T extends HandleableCloseable<T>> extends java.lang.Object implements HandleableCloseable<T>
close() method is idempotent; implements the registry of close handlers.| Modifier and Type | Class and Description |
|---|---|
(package private) class |
AbstractHandleableCloseable.CloseHandlerTask |
private static class |
AbstractHandleableCloseable.KeyImpl<T extends HandleableCloseable<T>> |
(package private) static class |
AbstractHandleableCloseable.LeakThrowable |
private static class |
AbstractHandleableCloseable.NullKey |
(package private) static class |
AbstractHandleableCloseable.State |
HandleableCloseable.Key| Modifier and Type | Field and Description |
|---|---|
private boolean |
autoClose |
private java.lang.StackTraceElement[] |
backtrace |
private java.util.Map<HandleableCloseable.Key,CloseHandler<? super T>> |
closeHandlers |
private java.lang.Object |
closeLock |
private java.util.concurrent.Executor |
executor |
private java.io.IOException |
failure |
private static boolean |
LEAK_DEBUGGING |
private static org.jboss.logging.Logger |
log |
private AbstractHandleableCloseable.State |
state |
| Modifier | Constructor and Description |
|---|---|
protected |
AbstractHandleableCloseable(java.util.concurrent.Executor executor)
Basic constructor.
|
protected |
AbstractHandleableCloseable(java.util.concurrent.Executor executor,
boolean autoClose)
Basic constructor.
|
| Modifier and Type | Method and Description |
|---|---|
HandleableCloseable.Key |
addCloseHandler(CloseHandler<? super T> handler)
Add a handler that will be called upon close.
|
void |
awaitClosed()
Wait for a resource close to complete.
|
void |
awaitClosedUninterruptibly()
Wait for a resource close to complete.
|
protected void |
checkOpen()
Check if open, throwing an exception if it is not.
|
private static <T extends java.io.IOException> |
clone(T original) |
void |
close()
Close this resource.
|
protected void |
closeAction()
Called exactly once when the
close() method is invoked; the actual close operation should take place here. |
void |
closeAsync()
Asynchronously close this resource.
|
protected void |
closeComplete()
Call when close is complete.
|
protected void |
closeFailed(java.io.IOException cause)
Call if an async close has failed.
|
protected void |
finalize()
Finalize this closeable instance.
|
protected java.util.concurrent.Executor |
getExecutor()
Get the executor to use for handler invocation.
|
protected boolean |
isOpen()
Read the status of this resource.
|
private static void |
runCloseTask(java.lang.Runnable task) |
private static final org.jboss.logging.Logger log
private static final boolean LEAK_DEBUGGING
private final java.util.concurrent.Executor executor
private final java.lang.StackTraceElement[] backtrace
private final boolean autoClose
private final java.lang.Object closeLock
private AbstractHandleableCloseable.State state
private java.io.IOException failure
private java.util.Map<HandleableCloseable.Key,CloseHandler<? super T extends HandleableCloseable<T>>> closeHandlers
protected AbstractHandleableCloseable(java.util.concurrent.Executor executor)
executor - the executor used to execute the close notification handlersprotected AbstractHandleableCloseable(java.util.concurrent.Executor executor,
boolean autoClose)
executor - the executor used to execute the close notification handlersautoClose - true if this instance should automatically close on finalizeprotected boolean isOpen()
true.true if the resource is still openprotected void closeAction()
throws java.io.IOException
close() method is invoked; the actual close operation should take place here.
This method must call closeComplete(), directly or indirectly, for the close operation to finish
(it may happen in another thread but it must happen).
This method should not expect the closeComplete() call to be made from another thread from the same thread pool
that may cause close(). As close will block, this can result in situations where all threads in the pool are
blocked on close() method calls, which means the closeComplete() will never be run.RemotingException - if the close failedjava.io.IOExceptionpublic void close()
throws java.io.IOException
close in interface java.io.Closeableclose in interface java.lang.AutoCloseableclose in interface HandleableCloseable<T extends HandleableCloseable<T>>java.io.IOException - if the close failedprivate static <T extends java.io.IOException> T clone(T original)
protected void closeComplete()
protected void closeFailed(java.io.IOException cause)
cause - the failure causepublic void awaitClosed()
throws java.lang.InterruptedException
awaitClosed in interface HandleableCloseable<T extends HandleableCloseable<T>>java.lang.InterruptedException - if the operation is interruptedpublic void awaitClosedUninterruptibly()
awaitClosedUninterruptibly in interface HandleableCloseable<T extends HandleableCloseable<T>>public void closeAsync()
closeAsync in interface HandleableCloseable<T extends HandleableCloseable<T>>public HandleableCloseable.Key addCloseHandler(CloseHandler<? super T> handler)
addCloseHandler in interface HandleableCloseable<T extends HandleableCloseable<T>>handler - the close handlerprivate static void runCloseTask(java.lang.Runnable task)
protected java.util.concurrent.Executor getExecutor()
protected void finalize()
throws java.lang.Throwable
finalize in class java.lang.Objectjava.lang.Throwableprotected void checkOpen()
throws NotOpenException
NotOpenException - if not open