public abstract class AbstractReferenceCounted extends Object implements ReferenceCountedTracer, ReferenceOwner
Modifier and Type | Field and Description |
---|---|
protected static int |
WARN_COUNT |
protected static long |
WARN_NS |
INIT
Modifier | Constructor and Description |
---|---|
protected |
AbstractReferenceCounted() |
protected |
AbstractReferenceCounted(boolean monitored) |
Modifier and Type | Method and Description |
---|---|
static void |
assertReferencesReleased() |
StackTrace |
createdHere() |
static void |
disableReferenceTracing() |
static void |
enableReferenceTracing() |
protected abstract void |
performRelease() |
protected boolean |
performReleaseInBackground() |
int |
refCount()
Returns the reference count for this resource.
|
int |
referenceId() |
void |
release(ReferenceOwner id)
Releases a resource.
|
void |
releaseLast(ReferenceOwner id)
Releases a resource and checks this is the last usage.
|
void |
reserve(ReferenceOwner id)
Reserves a resource or throws an Exception.
|
boolean |
reservedBy(ReferenceOwner owner)
Best effort check the owner has reserved it.
|
void |
reserveTransfer(ReferenceOwner from,
ReferenceOwner to) |
protected boolean |
threadSafetyCheck(boolean isUsed) |
void |
throwExceptionIfNotReleased() |
void |
throwExceptionIfReleased() |
@NotNull String |
toString() |
boolean |
tryReserve(ReferenceOwner id)
Tries to reserve a resource and returns if the resource could
be successfully reserved.
|
static void |
unmonitor(ReferenceCounted counted) |
void |
warnAndReleaseIfNotReleased() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
onReleased, onReleased
releaseLast
referenceName, temporary
protected static final long WARN_NS
protected static final int WARN_COUNT
protected AbstractReferenceCounted()
protected AbstractReferenceCounted(boolean monitored)
public static void enableReferenceTracing()
public static void disableReferenceTracing()
public static void assertReferencesReleased()
public static void unmonitor(ReferenceCounted counted)
public int referenceId()
referenceId
in interface ReferenceOwner
public StackTrace createdHere()
createdHere
in interface ReferenceCountedTracer
public void throwExceptionIfNotReleased() throws IllegalStateException
throwExceptionIfNotReleased
in interface ReferenceCountedTracer
IllegalStateException
protected boolean performReleaseInBackground()
protected abstract void performRelease() throws IllegalStateException
IllegalStateException
public void reserve(ReferenceOwner id) throws IllegalStateException
ReferenceCounted
Each invocation of this method increases the reference count by one.
reserve
in interface ReferenceCounted
id
- unique id for this reserveIllegalStateException
- if the resource has already been freed.
I.e. its reference counter has as some point reached zero.public void release(ReferenceOwner id) throws IllegalStateException
ReferenceCounted
Each invocation of this method decreases the reference count by one.
release
in interface ReferenceCounted
id
- unique id for the reserve to be releasedIllegalStateException
- if the resource has already been freed.
I.e. its reference counter has as some point reached zero.public void releaseLast(ReferenceOwner id) throws IllegalStateException
ReferenceCounted
Each invocation of this method decreases the reference count by one.
releaseLast
in interface ReferenceCounted
id
- unique id for the reserve to be releasedIllegalStateException
- if the resource has already been freed.
I.e. its reference counter has as some point reached zero.public boolean tryReserve(ReferenceOwner id) throws IllegalStateException, IllegalArgumentException
ReferenceCounted
Each invocation of this method increases the reference count by one.
tryReserve
in interface ReferenceCounted
id
- unique id for this reserveIllegalStateException
- if the resource has already been freed.
I.e. its reference counter has as some point reached zero.IllegalArgumentException
public void reserveTransfer(ReferenceOwner from, ReferenceOwner to) throws IllegalStateException
reserveTransfer
in interface ReferenceCounted
IllegalStateException
public int refCount()
ReferenceCounted
refCount
in interface ReferenceCounted
public void throwExceptionIfReleased() throws ClosedIllegalStateException
throwExceptionIfReleased
in interface ReferenceCountedTracer
ClosedIllegalStateException
public void warnAndReleaseIfNotReleased() throws ClosedIllegalStateException
warnAndReleaseIfNotReleased
in interface ReferenceCountedTracer
ClosedIllegalStateException
public boolean reservedBy(ReferenceOwner owner) throws IllegalStateException
ReferenceCounted
reservedBy
in interface ReferenceCounted
owner
- to checkIllegalStateException
protected boolean threadSafetyCheck(boolean isUsed) throws IllegalStateException
IllegalStateException
Copyright © 2021. All rights reserved.