Class LivenessScope
java.lang.Object
com.illumon.util.referencecounting.ReferenceCounted
com.illumon.iris.db.util.liveness.LivenessScope
- All Implemented Interfaces:
com.fishlib.base.log.LogOutputAppendable
,LivenessManager
,LivenessNode
,LivenessReferent
,ReleasableLivenessManager
,Serializable
public class LivenessScope extends ReferenceCounted implements ReleasableLivenessManager
LivenessNode
implementation for providing external scope to one or more LivenessReferent
s.- See Also:
- Serialized Form
-
Constructor Summary
Constructors Constructor Description LivenessScope()
Construct a new scope, which must berelease()
d in order to release any subsequently addedLivenessReferent
s. -
Method Summary
Modifier and Type Method Description protected void
destroy()
Attempt to release (destructively when necessary) resources held by this object.void
dropReference()
Drop a previously-retained reference to this referent.WeakReference<? extends LivenessReferent>
getWeakReference()
Get aWeakReference
to this referent.void
initializeTransientFieldsForLiveness()
Package-private forSerializable
sub-classes to use inreadObject
only.protected void
onReferenceCountAtZero()
Callback method that will be invoked when the reference count returns to zero.void
release()
Release all referents previously added to this scope in its capacity as aLivenessManager
, unless other references to this scope are retained in its capacity as aLivenessReferent
.void
transferTo(LivenessManager other)
boolean
tryManage(LivenessReferent referent)
Attempt to add the specified referent to this manager.boolean
tryRetainReference()
If this referent is "live", behave asLivenessReferent.retainReference()
and return true.Methods inherited from class com.illumon.util.referencecounting.ReferenceCounted
append, decrementReferenceCount, incrementReferenceCount, resetReferenceCount, toString, tryDecrementReferenceCount, tryIncrementReferenceCount
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface com.illumon.iris.db.util.liveness.LivenessManager
manage, tryManage
Methods inherited from interface com.illumon.iris.db.util.liveness.LivenessReferent
getReferentDescription, retainReference
-
Constructor Details
-
LivenessScope
public LivenessScope()Construct a new scope, which must berelease()
d in order to release any subsequently addedLivenessReferent
s.
-
-
Method Details
-
transferTo
Transfer all retainedLivenessReferent
s from thisLivenessScope
to a compatibleLivenessManager
. Transfer support compatibility is implementation defined.- Parameters:
other
- The otherLivenessManager
-
release
public final void release()Release all referents previously added to this scope in its capacity as aLivenessManager
, unless other references to this scope are retained in its capacity as aLivenessReferent
.- Specified by:
release
in interfaceReleasableLivenessManager
-
initializeTransientFieldsForLiveness
Package-private forSerializable
sub-classes to use inreadObject
only. Public to allow unit tests in another package to work around mock issues where the constructor is never invoked. -
tryRetainReference
public final boolean tryRetainReference()Description copied from interface:LivenessReferent
If this referent is "live", behave asLivenessReferent.retainReference()
and return true. Otherwise, returns false rather than throwing an exception.- Specified by:
tryRetainReference
in interfaceLivenessReferent
- Returns:
- True if this referent was retained, false otherwise
-
dropReference
public final void dropReference()Description copied from interface:LivenessReferent
Drop a previously-retained reference to this referent.- Specified by:
dropReference
in interfaceLivenessReferent
-
getWeakReference
Description copied from interface:LivenessReferent
Get aWeakReference
to this referent. This may be cached, or newly created.- Specified by:
getWeakReference
in interfaceLivenessReferent
- Returns:
- A new or cached reference to this referent
-
tryManage
Description copied from interface:LivenessManager
Attempt to add the specified referent to this manager.- Specified by:
tryManage
in interfaceLivenessManager
- Parameters:
referent
- The referent to add- Returns:
- Whether the referent was in fact added
-
destroy
protected void destroy()Attempt to release (destructively when necessary) resources held by this object. This may render the object unusable for subsequent operations. Implementations should be sure to call super.destroy().
This is intended to only ever be used as a side effect of decreasing the reference count to 0.
-
onReferenceCountAtZero
protected final void onReferenceCountAtZero()Description copied from class:ReferenceCounted
Callback method that will be invoked when the reference count returns to zero.- Specified by:
onReferenceCountAtZero
in classReferenceCounted
-