T
- the type of the closeable resourcepublic abstract class AbstractHandleableCloseable<T extends HandleableCloseable<T>> extends Object implements HandleableCloseable<T>
close()
method is idempotent; implements the registry of close handlers.HandleableCloseable.Key
Modifier | Constructor and Description |
---|---|
protected |
AbstractHandleableCloseable(Executor executor)
Basic constructor.
|
protected |
AbstractHandleableCloseable(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.
|
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(IOException cause)
Call if an async close has failed.
|
protected void |
finalize()
Finalize this closeable instance.
|
protected Executor |
getExecutor()
Get the executor to use for handler invocation.
|
protected boolean |
isOpen()
Read the status of this resource.
|
protected AbstractHandleableCloseable(Executor executor)
executor
- the executor used to execute the close notification handlersprotected AbstractHandleableCloseable(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 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 failedIOException
public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
close
in interface HandleableCloseable<T extends HandleableCloseable<T>>
IOException
- if the close failedprotected void closeComplete()
protected void closeFailed(IOException cause)
cause
- the failure causepublic void awaitClosed() throws InterruptedException
awaitClosed
in interface HandleableCloseable<T extends HandleableCloseable<T>>
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 handlerprotected Executor getExecutor()
protected void finalize() throws Throwable
protected void checkOpen() throws NotOpenException
NotOpenException
- if not openCopyright © 2012 JBoss by Red Hat. All Rights Reserved.