Interface AutoCloseableRegistry
- 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 TypeMethodDescriptionvoidclose()booleanclosed()newChild()Returns a newAutoCloseableRegistryinstance that is not closed, has no registrations yet, and is registered with thisAutoCloseableRegistry.booleanregister(AutoCloseable closeable) If thisAutoCloseableRegistryis not closed, and if the suppliedAutoCloseablehas not yet been registered, registers it such that it will be closed when thisAutoCloseableRegistryis closed, and returnstrue.
-
Method Details
-
newChild
Returns a newAutoCloseableRegistryinstance that is not closed, has no registrations yet, and is registered with thisAutoCloseableRegistry.The new
AutoCloseableRegistrychild therefore functions as an intermediate or leaf node in a tree ofAutoCloseableimplementations, such that if any node of the tree is closed, all of its descendants will be closed as well.- Returns:
- a new, unclosed
AutoCloseableRegistryregistered with thisAutoCloseableRegistrythat functions as an intermediate or leaf node in a tree of such nodes - Throws:
IllegalStateException- if thisAutoCloseableRegistryis closed- See Also:
- Idempotency:
- All successful invocations of implementations of this method must return new, distinct
AutoCloseableRegistryinstances. - 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 thisAutoCloseableRegistryand closes its registrants.After any successful invocation of this method, an invocation of the
closed()method must forever after returntrue.- Specified by:
closein 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()Returnstrueif and only if thisAutoCloseableRegistryis 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
falseuntil an invocation of theclose()method has successfully completed, and must returntruethereafter.- Returns:
trueif and only if thisAutoCloseableRegistryis 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 thisAutoCloseableRegistryis not closed, and if the suppliedAutoCloseablehas not yet been registered, registers it such that it will be closed when thisAutoCloseableRegistryis closed, and returnstrue.This method takes no action and returns
falsein all other cases.- Parameters:
closeable- theAutoCloseableto register; must not benull- Returns:
trueif and only if thisAutoCloseableRegistryis not closed and the suppliedAutoCloseableis not already registered and registration completed successfully;falsein all other cases- Throws:
NullPointerException- ifcloseableisnull- Idempotency:
- Implementations of this method must be idempotent.
- Thread Safety:
- Implementations of this method must be safe for concurrent use by multiple threads.
-