public final class VanillaReferenceCounted extends Object implements MonitorReferenceCounted
MonitorReferenceCounted interface.
It is responsible for keeping track of reference counts and releasing resources
once they are no longer needed.INIT, TMP| Modifier and Type | Method and Description |
|---|---|
void |
addReferenceChangeListener(ReferenceChangeListener referenceChangeListener)
Adds a
ReferenceChangeListener that will be notified when references are added or removed. |
StackTrace |
createdHere()
Retrieves the stack trace of the point where the object was created.
|
int |
refCount()
Returns the current reference count of the resource.
|
void |
release(ReferenceOwner id)
Releases the resource reserved by the provided reference owner.
|
void |
releaseLast(ReferenceOwner id)
Releases the last reference of the resource.
|
void |
removeReferenceChangeListener(ReferenceChangeListener referenceChangeListener)
Removes a
ReferenceChangeListener from being notified when references are added or removed. |
void |
reserve(ReferenceOwner id)
Reserves the resource for the provided reference owner.
|
void |
reserveTransfer(ReferenceOwner from,
ReferenceOwner to)
Transfers the reservation of the resource from one reference owner to another.
|
void |
throwExceptionIfNotReleased()
Throws an exception if the object has not been released.
|
String |
toString() |
boolean |
tryReserve(ReferenceOwner id)
Attempts to reserve the resource for the provided reference owner.
|
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, waitonReleased, throwExceptionIfReleasedreleaseLastreferenceId, referenceName, temporarypublic StackTrace createdHere()
ReferenceCountedTracercreatedHere in interface ReferenceCountedTracerpublic void reserve(ReferenceOwner id) throws ClosedIllegalStateException
reserve in interface ReferenceCountedid - The reference owner.ClosedIllegalStateException - If the resource has been released or closed.public void reserveTransfer(ReferenceOwner from, ReferenceOwner to) throws ClosedIllegalStateException
reserveTransfer in interface ReferenceCountedfrom - The current reference owner.to - The new reference owner.ClosedIllegalStateException - If the resource has been released or closed.public boolean tryReserve(ReferenceOwner id)
tryReserve in interface ReferenceCountedid - The reference owner.true if the reservation was successful, false if the object has already been released.public void release(ReferenceOwner id) throws ClosedIllegalStateException
release in interface ReferenceCountedid - The reference owner.ClosedIllegalStateException - If the resource has been released or closed.public void releaseLast(ReferenceOwner id) throws IllegalStateException
releaseLast in interface ReferenceCountedid - The reference owner.IllegalStateException - If the object has more references.public 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 warnAndReleaseIfNotReleased()
throws IllegalStateException
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 ReferenceCountedTracerClosedIllegalStateException - If the object has not been released.IllegalStateExceptionpublic 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.public void addReferenceChangeListener(ReferenceChangeListener referenceChangeListener)
ReferenceChangeListener that will be notified when references are added or removed.addReferenceChangeListener in interface ReferenceCountedreferenceChangeListener - The ReferenceChangeListener to be added.public void removeReferenceChangeListener(ReferenceChangeListener referenceChangeListener)
ReferenceChangeListener from being notified when references are added or removed.removeReferenceChangeListener in interface ReferenceCountedreferenceChangeListener - The ReferenceChangeListener to be removed.Copyright © 2024. All rights reserved.