public abstract class AbstractCloseableReferenceCounted extends AbstractReferenceCounted implements ManagedCloseable
The resource starts reserved by ReferenceOwner.INIT. Once all calls
to release(ReferenceOwner) (or releaseLast(ReferenceOwner))
have balanced earlier reserve(ReferenceOwner) calls the resource is
closed. If AbstractReferenceCounted.canReleaseInBackground() is true the cleanup is
delegated to BackgroundResourceReleaser.
referenceCounted, WARN_COUNT, WARN_NSINIT, TMPDISABLE_SINGLE_THREADED_CHECK| Modifier | Constructor and Description |
|---|---|
protected |
AbstractCloseableReferenceCounted()
Constructs a new AbstractCloseableReferenceCounted instance and adds the instance
to the CloseableUtils set for tracking.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
backgroundPerformRelease()
Closes the resource in the background.
|
void |
close()
Closes the resource, ensuring it transitions to a closed state.
|
boolean |
isClosed()
Indicates whether the resource is in a closed state.
|
void |
release(ReferenceOwner id)
Releases the resource for the given id.
|
void |
releaseLast(ReferenceOwner id)
Releases the resource for the given id and checks the resource is now released.
|
void |
reserve(ReferenceOwner id)
Attempts to reserve the resource for the given unique id.
|
void |
reserveTransfer(ReferenceOwner from,
ReferenceOwner to)
Reserves the resource for the given id.
|
protected void |
setClosed()
Sets the resource as closed.
|
protected void |
setClosing()
Sets the resource as closing in case it is being released in the background.
|
void |
throwExceptionIfClosed()
Throws an exception if the resource is closed.
|
protected void |
throwExceptionIfClosedInSetter()
Throws an exception if the resource is closed while in a setter method.
|
boolean |
tryReserve(ReferenceOwner id)
Tries to reserve the resource for the given id.
|
void |
unmonitor()
Stops monitoring the resource.
|
addReferenceChangeListener, assertReferencesReleased, canReleaseInBackground, createdHere, disableReferenceTracing, enableReferenceTracing, performRelease, refCount, referenceCountedUnmonitored, referenceId, removeReferenceChangeListener, singleThreadedCheckDisabled, singleThreadedCheckReset, threadSafetyCheck, throwExceptionIfNotReleased, throwExceptionIfReleased, toString, unmonitor, warnAndReleaseIfNotReleasedclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitcreatedHere, warnAndCloseIfNotClosedcloseQuietly, closeQuietlyisClosingonReleasedreleaseLastreferenceName, temporaryunmonitorprotected AbstractCloseableReferenceCounted()
public void reserve(ReferenceOwner id) throws ClosedIllegalStateException, ThreadingIllegalStateException
reserve in interface ReferenceCountedreserve in class AbstractReferenceCountedid - the unique identifier representing the owner of this reserve.ClosedIllegalStateException - If the resource has been released or closed.ThreadingIllegalStateException - If this resource was accessed by multiple threads in an unsafe waypublic void reserveTransfer(ReferenceOwner from, ReferenceOwner to) throws ClosedIllegalStateException, ThreadingIllegalStateException
reserveTransfer in interface ReferenceCountedreserveTransfer in class AbstractReferenceCountedfrom - resourceto - resourceClosedIllegalStateException - If the resource has been released or closed.ThreadingIllegalStateException - If used in a non thread safe waypublic void release(ReferenceOwner id) throws ClosedIllegalStateException
release in interface ReferenceCountedrelease in class AbstractReferenceCountedid - unique id for this releaseClosedIllegalStateException - If the resource has been released or closed.public void releaseLast(ReferenceOwner id) throws ClosedIllegalStateException
releaseLast in interface ReferenceCountedreleaseLast in class AbstractReferenceCountedid - unique id for this releaseClosedIllegalStateException - If the resource has been released or closed.public boolean tryReserve(ReferenceOwner id) throws ClosedIllegalStateException, IllegalArgumentException
tryReserve in interface ReferenceCountedtryReserve in class AbstractReferenceCountedid - unique id for this reserveClosedIllegalStateException - If the resource has been released or closed.IllegalArgumentException - If the reference owner is not valid.public void close()
close in interface Closeableclose in interface AutoCloseableAbstractCloseable.performClose()protected void backgroundPerformRelease()
backgroundPerformRelease in class AbstractReferenceCountedprotected void setClosing()
protected void setClosed()
public void throwExceptionIfClosed()
throws ClosedIllegalStateException,
ThreadingIllegalStateException
throwExceptionIfClosed in interface ManagedCloseableClosedIllegalStateException - If the resource has been released or closed.ThreadingIllegalStateException - If the thread safety check fails.protected void throwExceptionIfClosedInSetter()
throws ClosedIllegalStateException,
ThreadingIllegalStateException
ClosedIllegalStateException - If the resource has been released or closed.ThreadingIllegalStateExceptionpublic boolean isClosed()
isClosed in interface QueryCloseabletrue if the resource is closed; false otherwise.public void unmonitor()
MonitorableImplementations of this method should ensure that the resource and any resources it uses are no longer being tracked for any purpose such as cleanup, resource management, or debugging. This is particularly important for resources that are explicitly managed to avoid leaks.
unmonitor in interface Monitorableunmonitor in class AbstractReferenceCountedCopyright © 2026 Chronicle Software Ltd. All rights reserved.