forked from microbean/microbean-reference
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDestructorTree.java
More file actions
68 lines (63 loc) · 2.79 KB
/
DestructorTree.java
File metadata and controls
68 lines (63 loc) · 2.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/* -*- mode: Java; c-basic-offset: 2; indent-tabs-mode: nil; coding: utf-8-unix -*-
*
* Copyright © 2025–2026 microBean™.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
package org.microbean.reference;
/**
* A hierarchical {@link DestructorRegistry} that is {@link AutoCloseable}.
*
* <p>This interface is often used by {@link org.microbean.bean.ReferencesSelector} implementors, and normally by no
* other kinds of users.</p>
*
* @author <a href="https://about.me/lairdnelson" target="_top">Laird Nelson</a>
*
* @see #close()
*
* @see DestructorRegistry
*/
public interface DestructorTree extends AutoCloseable, DestructorRegistry {
/**
* Creates a new <dfn>child</dfn> instance of this implementation, or a subtype, {@linkplain #register(Object,
* Destructor) registers it} with this implementation, using a method reference to its {@link #close()} method as the
* {@link Destructor}, and returns it.
*
* @return a new (non-{@code null}) child instance of this implementation, or a subtype, {@linkplain #register(Object,
* Destructor) registered} with this implementation such that {@link #close() closing} this implementation will also
* {@linkplain #close() close} the child instance
*
* @see #close()
*
* @see #register(Object, Destructor)
*/
public DestructorTree newChild();
/**
* Closes this {@link DestructorTree} implementation by effectively {@linkplain #remove(Object) removing} all
* {@linkplain #register(Object, Destructor) registered} contextual instances and {@linkplain Destructor#destroy()
* running their affiliated <code>Destructor</code>s}.
*
* @see #remove(Object)
*/
@Override // AutoCloseable
public void close();
/**
* Removes the supplied contextual instance and the {@link Destructor} that was {@linkplain #register(Object,
* Destructor) registered with it}.
*
* <p>The {@link Destructor#destroy()} will not be invoked by implementations of this method.</p>
*
* @param instance the contextual instance to remove; may be {@code null} in which case {@code null} will be returned
*
* @return a {@link Destructor} {@linkplain #register(Object, Destructor) registered} with the supplied instance, or
* {@code null} if no such {@link Destructor} exists
*/
public Destructor remove(final Object instance);
}