@Deprecated public class DualReferenceCounted extends Object implements MonitorReferenceCounted
INIT, TMP| Constructor and Description |
|---|
DualReferenceCounted(MonitorReferenceCounted a,
MonitorReferenceCounted b)
Deprecated.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addReferenceChangeListener(ReferenceChangeListener referenceChangeListener)
Deprecated.
Adds a
ReferenceChangeListener that will be notified whenever the reference count changes. |
StackTrace |
createdHere()
Deprecated.
Retrieves the stack trace of the point where the object was created.
|
int |
refCount()
Deprecated.
Returns the current reference count of the resource.
|
int |
referenceId()
Deprecated.
Returns a unique identifier (ID) for this reference owner.
|
String |
referenceName()
Deprecated.
Returns a human-readable name for this reference owner.
|
void |
release(ReferenceOwner id)
Deprecated.
Releases the resource by decrementing its reference count by one.
|
void |
releaseLast(ReferenceOwner id)
Deprecated.
Releases the resource and ensures that this release is the last usage of the resource.
|
void |
removeReferenceChangeListener(ReferenceChangeListener referenceChangeListener)
Deprecated.
Removes a
ReferenceChangeListener previously added via ReferenceCounted.addReferenceChangeListener(ReferenceChangeListener). |
void |
reserve(ReferenceOwner id)
Deprecated.
Reserves the resource by incrementing its reference count by one.
|
boolean |
reservedBy(ReferenceOwner owner)
Deprecated.
|
void |
reserveTransfer(ReferenceOwner from,
ReferenceOwner to)
Deprecated.
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()
Deprecated.
Throws an exception if the object has not been released.
|
void |
throwExceptionIfReleased()
Deprecated.
Throws an exception if the object has been released.
|
boolean |
tryReserve(ReferenceOwner id)
Deprecated.
Attempts to reserve the resource and returns
true if successful. |
boolean |
unmonitored()
Deprecated.
|
void |
unmonitored(boolean unmonitored)
Deprecated.
Sets the monitored state of the object.
|
void |
warnAndReleaseIfNotReleased()
Deprecated.
Releases any remaining references and logs a warning if there were any references to release.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitonReleasedreleaseLasttemporarypublic DualReferenceCounted(MonitorReferenceCounted a, MonitorReferenceCounted b)
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 ReferenceCountedTracerIllegalStateException - If the object hadn't been released.public 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 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.@Deprecated public boolean reservedBy(ReferenceOwner owner) throws ClosedIllegalStateException
ReferenceCountedtrue if unsure.
This method provides a best-effort check and may not be accurate.
reservedBy in interface ReferenceCountedowner - The unique identifier representing the owner to check.false if it is certain that the owner does not have the resource reserved; true otherwise.ClosedIllegalStateException - If the resource has been released or closed.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 IllegalStateException, 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.ThreadingIllegalStateException - If this resource was accessed by multiple threads in an unsafe wayIllegalArgumentException - If the reference owner is invalid.IllegalStateExceptionpublic void release(ReferenceOwner id) throws IllegalStateException
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.ThreadingIllegalStateException - If this resource was accessed by multiple threads in an unsafe wayIllegalStateExceptionpublic 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 throwExceptionIfReleased()
throws ClosedIllegalStateException
ReferenceCountedTracerthrowExceptionIfReleased in interface ReferenceCountedTracerClosedIllegalStateException - If the resource has been released or closed.public void reserveTransfer(ReferenceOwner from, ReferenceOwner to) throws IllegalStateException
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.ThreadingIllegalStateException - If this resource was accessed by multiple threads in an unsafe wayIllegalStateExceptionpublic int referenceId()
ReferenceOwnerThe default implementation uses the identity hash code of this reference owner instance as the ID.
referenceId in interface ReferenceOwnerpublic String referenceName()
ReferenceOwnerThe default implementation generates a name using the simple class name of the reference owner, followed by '@', and then the reference ID encoded in base 36.
referenceName in interface ReferenceOwnerpublic 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 © 2023. All rights reserved.