Class ReferenceCounted
java.lang.Object
com.illumon.util.referencecounting.ReferenceCounted
- All Implemented Interfaces:
com.fishlib.base.log.LogOutputAppendable
,Serializable
- Direct Known Subclasses:
ProceduralReferenceCounted
,ReferenceCountedLivenessNode
,TableDataRequestImpl
public abstract class ReferenceCounted
extends Object
implements com.fishlib.base.log.LogOutputAppendable, Serializable
Implements a recurring reference counting pattern - a concurrent reference count that should refuse to go below zero,
and invokes
onReferenceCountAtZero()
exactly once when the count returns to zero.- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncom.fishlib.base.log.LogOutput
append
(com.fishlib.base.log.LogOutput logOutput) final void
Decrement the reference count by one, if it has ever been increased and has not already been decreased to zero.final void
Increment the reference count by one, if it has not already been decreased to zero.protected abstract void
Callback method that will be invoked when the reference count returns to zero.final void
Reset this reference count to its initial state for reuse.toString()
final boolean
Decrement the reference count by one, if it has ever been increased and has not already been decreased to zero.final boolean
Increment the reference count by 1, if it has not already been decreased to 0.
-
Constructor Details
-
ReferenceCounted
protected ReferenceCounted() -
ReferenceCounted
protected ReferenceCounted(int initialValue)
-
-
Method Details
-
toString
-
append
public com.fishlib.base.log.LogOutput append(@NotNull com.fishlib.base.log.LogOutput logOutput) - Specified by:
append
in interfacecom.fishlib.base.log.LogOutputAppendable
-
resetReferenceCount
public final void resetReferenceCount()Reset this reference count to its initial state for reuse. -
tryIncrementReferenceCount
public final boolean tryIncrementReferenceCount()Increment the reference count by 1, if it has not already been decreased to 0.- Returns:
- Whether the reference count was successfully incremented
- Throws:
IllegalStateException
- If the reference count is already at its maximum referenceCount
-
incrementReferenceCount
public final void incrementReferenceCount()Increment the reference count by one, if it has not already been decreased to zero.- Throws:
IllegalStateException
- If the reference count was not successfully incremented
-
tryDecrementReferenceCount
public final boolean tryDecrementReferenceCount()Decrement the reference count by one, if it has ever been increased and has not already been decreased to zero. Invokes the implementation'sonReferenceCountAtZero()
method if decrementing to zero.- Returns:
- Whether the reference count was successfully decremented
-
decrementReferenceCount
public final void decrementReferenceCount()Decrement the reference count by one, if it has ever been increased and has not already been decreased to zero. Invokes the implementation'sonReferenceCountAtZero()
method if decrementing to zero.- Throws:
IllegalStateException
- If the reference count was not successfully decremented
-
onReferenceCountAtZero
protected abstract void onReferenceCountAtZero()Callback method that will be invoked when the reference count returns to zero.
-