- All Superinterfaces:
AutoCloseable
- All Known Implementing Classes:
DefaultAutoCloseableRegistry
A reigstry of
AutoCloseable
instances that itself is AutoCloseable
.
Closing an AutoCloseableRegistry
closes its
registrants.
- Author:
- Laird Nelson
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
boolean
closed()
newChild()
Returns a newAutoCloseableRegistry
instance that is not closed, has no registrations yet, and is registered with thisAutoCloseableRegistry
.boolean
register
(AutoCloseable closeable) If thisAutoCloseableRegistry
is not closed, and if the suppliedAutoCloseable
has not yet been registered, registers it such that it will be closed when thisAutoCloseableRegistry
is closed, and returnstrue
.
-
Method Details
-
newChild
Returns a newAutoCloseableRegistry
instance that is not closed, has no registrations yet, and is registered with thisAutoCloseableRegistry
.The new
AutoCloseableRegistry
child therefore functions as an intermediate or leaf node in a tree ofAutoCloseable
implementations, such that if any node of the tree is closed, all of its descendants will be closed as well.- Returns:
- a new, unclosed
AutoCloseableRegistry
registered with thisAutoCloseableRegistry
that functions as an intermediate or leaf node in a tree of such nodes - Throws:
IllegalStateException
- if thisAutoCloseableRegistry
is closed- See Also:
- Idempotency:
- All successful invocations of implementations of this method must return new, distinct
AutoCloseableRegistry
instances. - Nullability:
- Implementations of this method must not return
null
. - Thread Safety:
- Implementations of this method must be safe for concurrent use by multiple threads.
-
close
void close()Closes thisAutoCloseableRegistry
and closes its registrants.After any successful invocation of this method, an invocation of the
closed()
method must forever after returntrue
.- Specified by:
close
in interfaceAutoCloseable
- See Also:
- Idempotency:
- Implementations of this method must be idempotent.
- Thread Safety:
- Implementations of this method must be safe for concurrent use by multiple threads.
-
closed
boolean closed()Returnstrue
if and only if thisAutoCloseableRegistry
is closed.Once an invocation of this method has returned
true
, on any thread, subsequent invocations must also returntrue
, on any thread.An implementation of this method must return
false
until an invocation of theclose()
method has successfully completed, and must returntrue
thereafter.- Returns:
true
if and only if thisAutoCloseableRegistry
is closed- See Also:
- Idempotency:
- Implementations of this method must be idempotent.
- Thread Safety:
- Implementations of this method must be safe for concurrent use by multiple threads.
-
register
If thisAutoCloseableRegistry
is not closed, and if the suppliedAutoCloseable
has not yet been registered, registers it such that it will be closed when thisAutoCloseableRegistry
is closed, and returnstrue
.This method takes no action and returns
false
in all other cases.- Parameters:
closeable
- theAutoCloseable
to register; must not benull
- Returns:
true
if and only if thisAutoCloseableRegistry
is not closed and the suppliedAutoCloseable
is not already registered and registration completed successfully;false
in all other cases- Throws:
NullPointerException
- ifcloseable
isnull
- Idempotency:
- Implementations of this method must be idempotent.
- Thread Safety:
- Implementations of this method must be safe for concurrent use by multiple threads.
-