Class DefaultAutoCloseableRegistry
- All Implemented Interfaces:
AutoCloseable,AutoCloseableRegistry
AutoCloseableRegistry implementation.- Author:
- Laird Nelson
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()final booleanclosed()newChild()Returns a newDefaultAutoCloseableRegistryinstance that is not closed, has no registrations yet, and is registered with thisDefaultAutoCloseableRegistry.final booleanregister(AutoCloseable closeable) If thisDefaultAutoCloseableRegistryis not closed, and if the suppliedAutoCloseablehas not yet been registered, registers it such that it will be closed when thisDefaultAutoCloseableRegistryis closed, and returnstrue.
-
Constructor Details
-
DefaultAutoCloseableRegistry
public DefaultAutoCloseableRegistry()Creates a newDefaultAutoCloseableRegistry.
-
-
Method Details
-
newChild
Returns a newDefaultAutoCloseableRegistryinstance that is not closed, has no registrations yet, and is registered with thisDefaultAutoCloseableRegistry.- Specified by:
newChildin interfaceAutoCloseableRegistry- Returns:
- a new, unclosed
DefaultAutoCloseableRegistryregistered with thisDefaultAutoCloseableRegistry - Throws:
IllegalStateException- if thisDefaultAutoCloseableRegistryis closed- See Also:
- Idempotency:
- Overrides of this method must return new, distinct
DefaultAutoCloseableRegistryinstances. - 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 thisDefaultAutoCloseableRegistryand closes its registrants.AutoCloseable.close()is called on all registrants, even in the presence of exceptions.RuntimeExceptions 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:
closein interfaceAutoCloseable- Specified by:
closein 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
Returnstrueif and only if thisDefaultAutoCloseableRegistryis 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
falseuntil an invocation of theclose()method has successfully completed, and will returntruethereafter.- Specified by:
closedin interfaceAutoCloseableRegistry- Returns:
trueif and only if thisDefaultAutoCloseableRegistryis closed- See Also:
- Idempotency:
- This method is idempotent.
- Thread Safety:
- This method is safe for concurrent use by multiple threads.
-
register
If thisDefaultAutoCloseableRegistryis not closed, and if the suppliedAutoCloseablehas not yet been registered, registers it such that it will be closed when thisDefaultAutoCloseableRegistryis closed, and returnstrue.This method takes no action and returns
falsein all other cases.- Specified by:
registerin interfaceAutoCloseableRegistry- Parameters:
closeable- theAutoCloseableto register; must not benull- Returns:
trueif and only if thisDefaultAutoCloseableRegistryis not closed and the suppliedAutoCloseableis not already registered and registration completed successfully;falsein all other cases- Throws:
NullPointerException- ifcloseableisnull- Idempotency:
- This method is idempotent.
- Thread Safety:
- This method is safe for concurrent use by multiple threads.
-