T - public class ReferenceImpl<T> extends Object implements Reference<T>
Reference
TODO Avoid needless synchronization; a ConcurrentHashMap may help;
ref.equals could do only reference comparison| Modifier and Type | Field and Description |
|---|---|
protected StackTraceElement[] |
aquisitionStackTrace |
protected Map<Reference<T>,Object> |
childRefs |
protected Object |
comment |
protected boolean |
isReleased |
protected ReferenceImpl<T> |
parent |
protected AutoCloseable |
releaseAction
The release action differs for references:
On the root reference, the releaseAction releases the wrapped resource
On a child reference, the releaseAction releases itself from the parent
|
protected T |
value |
| Constructor and Description |
|---|
ReferenceImpl(ReferenceImpl<T> parent,
T value,
AutoCloseable releaseAction,
Object comment) |
| Modifier and Type | Method and Description |
|---|---|
Reference<T> |
acquire(Object comment)
Acquire a new reference with a given comment object
Acquiration fails if isAlive() returns false
|
protected void |
checkRelease() |
void |
close() |
static <T> Reference<T> |
create(T value,
AutoCloseable releaseAction,
Object comment) |
static <T> Reference<T> |
createClosed() |
protected void |
finalize()
TODO Switch to Java 9 Cleaner once we upgrade
|
T |
get()
Get the referent
|
StackTraceElement[] |
getAquisitionStackTrace()
Optional operation.
|
Object |
getComment() |
boolean |
isAlive()
A reference may itself be released, but references to it may keep it alive
|
boolean |
isClosed()
Check whether this reference is closed / released
|
protected void |
release(Object childRef) |
String |
toString() |
protected T value
protected AutoCloseable releaseAction
protected Object comment
protected ReferenceImpl<T> parent
protected boolean isReleased
protected StackTraceElement[] aquisitionStackTrace
public ReferenceImpl(ReferenceImpl<T> parent, T value, AutoCloseable releaseAction, Object comment)
protected void finalize()
throws Throwable
public Object getComment()
public Reference<T> acquire(Object comment)
Referenceprotected void release(Object childRef)
public boolean isAlive()
Referencepublic void close()
close in interface AutoCloseableprotected void checkRelease()
public static <T> Reference<T> create(T value, AutoCloseable releaseAction, Object comment)
public static <T> Reference<T> createClosed()
public boolean isClosed()
Referencepublic StackTraceElement[] getAquisitionStackTrace()
ReferencegetAquisitionStackTrace in interface Reference<T>Copyright © 2020. All rights reserved.