public final class TracingReferenceCounted extends Object implements MonitorReferenceCounted
INIT, TMP| Modifier and Type | Method and Description |
|---|---|
void |
addReferenceChangeListener(ReferenceChangeListener referenceChangeListener)
Adds a
ReferenceChangeListener that will be notified whenever the reference count changes. |
StackTrace |
createdHere()
Retrieves the stack trace of the point where the object was created.
|
int |
refCount()
Returns the current reference count of the resource.
|
@NotNull List<String> |
referencesAsString() |
void |
release(ReferenceOwner id)
Releases the resource by decrementing its reference count by one.
|
void |
releaseLast(ReferenceOwner id)
Releases the resource and ensures that this release is the last usage of the resource.
|
void |
removeReferenceChangeListener(ReferenceChangeListener referenceChangeListener)
Removes a
ReferenceChangeListener previously added via ReferenceCounted.addReferenceChangeListener(ReferenceChangeListener). |
void |
reserve(ReferenceOwner id)
Reserves the resource by incrementing its reference count by one.
|
void |
reserveTransfer(ReferenceOwner from,
ReferenceOwner to)
Atomically transfers a reservation from one owner to another by incrementing the reference
count for the new owner and decrementing it for the old owner.
|
void |
throwExceptionIfNotReleased()
Throws an exception if the object has not been released.
|
void |
throwExceptionIfReleased()
Throws an exception if the object has been released.
|
@NotNull String |
toString() |
boolean |
tryReserve(ReferenceOwner id)
Attempts to reserve the resource and returns
true if successful. |
boolean |
unmonitored() |
void |
unmonitored(boolean unmonitored)
Sets the monitored state of the object.
|
void |
warnAndReleaseIfNotReleased()
Releases any remaining references and logs a warning if there were any references to release.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitonReleasedreleaseLastreferenceId, referenceName, temporarypublic StackTrace createdHere()
ReferenceCountedTracercreatedHere in interface ReferenceCountedTracerpublic void addReferenceChangeListener(ReferenceChangeListener referenceChangeListener)
ReferenceCountedReferenceChangeListener that will be notified whenever the reference count changes.
This can be used to monitor the usage of the resource and execute code when certain conditions are met.addReferenceChangeListener in interface ReferenceCountedreferenceChangeListener - The listener that will receive notifications of reference count changes.public void removeReferenceChangeListener(ReferenceChangeListener referenceChangeListener)
ReferenceCountedReferenceChangeListener previously added via ReferenceCounted.addReferenceChangeListener(ReferenceChangeListener).
Note: Object equality is used to determine which listener to remove, so be cautious if the listener implements the equals method in a non-standard way.
removeReferenceChangeListener in interface ReferenceCountedreferenceChangeListener - The listener to remove.public void reserve(ReferenceOwner id) throws ClosedIllegalStateException
ReferenceCountedIt is required to reserve a resource before using it to prevent it from being freed.
reserve in interface ReferenceCountedid - The unique identifier representing the owner reserving the resource.ClosedIllegalStateException - If the resource has been released or closed.
I.e. its reference counter has as some point reached zero.public boolean tryReserve(ReferenceOwner id) throws ClosedIllegalStateException, IllegalArgumentException
ReferenceCountedtrue if successful.
Unlike ReferenceCounted.reserve(ReferenceOwner), this method will not throw an exception if the resource
is already freed.tryReserve in interface ReferenceCountedid - The unique identifier representing the owner attempting to reserve the resource.true if the resource was successfully reserved, false otherwise.ClosedIllegalStateException - If the resource has been released or closed.IllegalArgumentException - If the reference owner is invalid.public void release(ReferenceOwner id) throws ClosedIllegalStateException
ReferenceCountedrelease in interface ReferenceCountedid - The unique identifier representing the owner releasing the resource.ClosedIllegalStateException - If the resource has been released or closed.
I.e. its reference counter has as some point reached zero.public void reserveTransfer(ReferenceOwner from, ReferenceOwner to) throws ClosedIllegalStateException
ReferenceCountedreserveTransfer in interface ReferenceCountedfrom - The unique identifier representing the owner releasing the reservation.to - The unique identifier representing the owner acquiring the reservation.ClosedIllegalStateException - If the resource has been released or closed.public void releaseLast(ReferenceOwner id) throws IllegalStateException
ReferenceCountedreleaseLast in interface ReferenceCountedid - The unique identifier representing the owner releasing the resource.ClosedIllegalStateException - If the resource has been released or closed.ThreadingIllegalStateException - If this resource was accessed by multiple threads in an unsafe wayIllegalStateExceptionpublic int refCount()
ReferenceCountedrefCount in interface ReferenceCountedpublic void throwExceptionIfNotReleased()
throws IllegalStateException
ReferenceCountedTracerthrowExceptionIfNotReleased in interface ReferenceCountedTracerIllegalStateException - If the object has not been released (i.e., its reference count is greater than 0).public void throwExceptionIfReleased()
throws ClosedIllegalStateException
ReferenceCountedTracerthrowExceptionIfReleased in interface ReferenceCountedTracerClosedIllegalStateException - If the resource has been released or closed.public void warnAndReleaseIfNotReleased()
ReferenceCountedTracerThis method is intended to be called by a finalizer or in a test to confirm that references are being released correctly.
Note: This method will not trigger any ReferenceChangeListeners as it is mainly used for sanity checks.
warnAndReleaseIfNotReleased in interface ReferenceCountedTracerpublic void unmonitored(boolean unmonitored)
MonitorReferenceCountedunmonitored in interface MonitorReferenceCountedunmonitored - true to set the object as unmonitored, false to set it as monitored.public boolean unmonitored()
unmonitored in interface MonitorReferenceCountedtrue if the object is unmonitored, false if it is monitored.Copyright © 2024. All rights reserved.