public final class CloseableRegistry extends Object implements Closeable
Closeable
s that is closed in order. Registered
closeables are strongly-referenced and should be unregistered if they are
closed before the registry is closed.
The list is ordered by ascending priority; closeables with priority closer to
Integer.MIN_VALUE
are closed sooner.
Constructor and Description |
---|
CloseableRegistry() |
Modifier and Type | Method and Description |
---|---|
void |
close() |
boolean |
register(Closeable closeable)
Registers
closeable with the default priority, 0 . |
boolean |
register(Closeable closeable,
int priority)
Registers
closeable with the given priority. |
boolean |
unregister(Closeable closeable)
Removes
closeable from this registry. |
public boolean register(Closeable closeable)
closeable
with the default priority, 0
.true
if the closeable was registered or false
if
the registry is closedpublic boolean register(Closeable closeable, int priority)
closeable
with the given priority.true
if the closeable was registered or false
if
the registry is closedpublic boolean unregister(Closeable closeable)
closeable
from this registry.true
if the closeable was removed or false
if the
registry is closed or the closeable was not registered.public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
IOException