- All Implemented Interfaces:
AutoCloseable
,AutoCloseableRegistry
AutoCloseableRegistry
implementation.- Author:
- Laird Nelson
- See Also:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
final boolean
closed()
newChild()
Returns a newDefaultAutoCloseableRegistry
instance that is not closed, has no registrations yet, and is registered with thisDefaultAutoCloseableRegistry
.final boolean
register
(AutoCloseable closeable) If thisDefaultAutoCloseableRegistry
is not closed, and if the suppliedAutoCloseable
has not yet been registered, registers it such that it will be closed when thisDefaultAutoCloseableRegistry
is closed, and returnstrue
.
-
Constructor Details
-
DefaultAutoCloseableRegistry
public DefaultAutoCloseableRegistry()Creates a newDefaultAutoCloseableRegistry
.
-
-
Method Details
-
newChild
Returns a newDefaultAutoCloseableRegistry
instance that is not closed, has no registrations yet, and is registered with thisDefaultAutoCloseableRegistry
.- Specified by:
newChild
in interfaceAutoCloseableRegistry
- Returns:
- a new, unclosed
DefaultAutoCloseableRegistry
registered with thisDefaultAutoCloseableRegistry
- Throws:
IllegalStateException
- if thisDefaultAutoCloseableRegistry
is closed- See Also:
- Idempotency:
- Overrides of this method must return new, distinct
DefaultAutoCloseableRegistry
instances. - Nullability:
- This method does not, and its overrides must not, return
null
. - Thread Safety:
- This method is, and its overrides must be, safe for concurrent use by multiple threads.
-
close
Closes thisDefaultAutoCloseableRegistry
and closes its registrants.AutoCloseable.close()
is called on all registrants, even in the presence of exceptions.RuntimeException
s consequently thrown may therefore contain suppressed exceptions.Overrides of this method wishing to add semantics to this behavior should perform that work before calling
super.close()
.Overrides of this method must call
super.close()
or undefined behavior may result.After any successful invocation of this method, an invocation of the
closed()
method will forever after returntrue
.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceAutoCloseableRegistry
- See Also:
- Idempotency:
- This method is, and its overrides must be, idempotent.
- Thread Safety:
- This method is, and its overrides must be, safe for concurrent use by multiple threads.
-
closed
Returnstrue
if and only if thisDefaultAutoCloseableRegistry
is closed.Once an invocation of this method has returned
true
, on any thread, subsequent invocations must also returntrue
, on any thread.This method will return
false
until an invocation of theclose()
method has successfully completed, and will returntrue
thereafter.- Specified by:
closed
in interfaceAutoCloseableRegistry
- Returns:
true
if and only if thisDefaultAutoCloseableRegistry
is closed- See Also:
- Idempotency:
- This method is idempotent.
- Thread Safety:
- This method is safe for concurrent use by multiple threads.
-
register
If thisDefaultAutoCloseableRegistry
is not closed, and if the suppliedAutoCloseable
has not yet been registered, registers it such that it will be closed when thisDefaultAutoCloseableRegistry
is closed, and returnstrue
.This method takes no action and returns
false
in all other cases.- Specified by:
register
in interfaceAutoCloseableRegistry
- Parameters:
closeable
- theAutoCloseable
to register; must not benull
- Returns:
true
if and only if thisDefaultAutoCloseableRegistry
is not closed and the suppliedAutoCloseable
is not already registered and registration completed successfully;false
in all other cases- Throws:
NullPointerException
- ifcloseable
isnull
- Idempotency:
- This method is idempotent.
- Thread Safety:
- This method is safe for concurrent use by multiple threads.
-