Class DefaultDestructorTree
java.lang.Object
org.microbean.reference.DefaultDestructorTree
- All Implemented Interfaces:
AutoCloseable,DestructorRegistry,DestructorTree
A straightforward
DestructorTree implementation.- Author:
- Laird Nelson
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.microbean.reference.DestructorRegistry
DestructorRegistry.Destructor -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes thisDefaultDestructorTreeand destroys its registrants by running their destructors supplied at registration time.newChild()Creates a new child instance of this implementation, or a subtype, registers it with this implementation, using a method reference to itsDestructorTree.close()method as theDestructorRegistry.Destructor, and returns it.final booleanregister(Object reference, DestructorRegistry.Destructor destructor) If thisDefaultDestructorTreeis not closed, and if the suppliedreferencehas not yet been registered, registers it such that it will be destroyed by the supplieddestructorwhen thisDefaultDestructorTreeis closed, and returnstrue.Removes the supplied contextual instance and theDestructorRegistry.Destructorthat was registered with it.
-
Constructor Details
-
DefaultDestructorTree
public DefaultDestructorTree()Creates a newDefaultDestructorTree.
-
-
Method Details
-
newChild
Description copied from interface:DestructorTreeCreates a new child instance of this implementation, or a subtype, registers it with this implementation, using a method reference to itsDestructorTree.close()method as theDestructorRegistry.Destructor, and returns it.- Specified by:
newChildin interfaceDestructorTree- Returns:
- a new (non-
null) child instance of this implementation, or a subtype, registered with this implementation such thatclosingthis implementation will also close the child instance - See Also:
-
close
Closes thisDefaultDestructorTreeand destroys its registrants by running their destructors supplied at registration time.DestructorRegistry.Destructor.destroy()is called on all registrants, even in the presence of exceptions.RuntimeExceptions consequently thrown may 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, this
DefaultDestructorTreeis deemed to be irrevocably closed. Invoking this method again will have no effect.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceDestructorTree- 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.
-
register
If thisDefaultDestructorTreeis not closed, and if the suppliedreferencehas not yet been registered, registers it such that it will be destroyed by the supplieddestructorwhen thisDefaultDestructorTreeis closed, and returnstrue.This method takes no action and returns
falsein all other cases.- Specified by:
registerin interfaceDestructorRegistry- Parameters:
reference- a contextual reference that will be destroyed later; ifnullthen no action will be taken andfalsewill be returneddestructor- aDestructorRegistry.Destructorthat, when run, will destroy the suppliedreferencein some way; ifnullthen no action will be taken andfalsewill be returned; if non-nullmust be idempotent and safe for concurrent use by multiple threads- Returns:
trueif and only if thisDefaultDestructorTreeis not closed, and the suppliedreferenceis not already registered and registration completed successfully;falsein all other cases- See Also:
- Idempotency:
- This method is idempotent.
- Thread Safety:
- This method is safe for concurrent use by multiple threads.
-
remove
Description copied from interface:DestructorTreeRemoves the supplied contextual instance and theDestructorRegistry.Destructorthat was registered with it.The
DestructorRegistry.Destructor.destroy()will not be invoked by implementations of this method.- Specified by:
removein interfaceDestructorTree- Parameters:
reference- the contextual instance to remove; may benullin which casenullwill be returned- Returns:
- a
DestructorRegistry.Destructorregistered with the supplied instance, ornullif no suchDestructorRegistry.Destructorexists
-