Package io.deephaven.engine.liveness
Class ReferenceCountedLivenessNode
java.lang.Object
io.deephaven.util.referencecounting.ReferenceCounted
io.deephaven.engine.liveness.ReferenceCountedLivenessReferent
io.deephaven.engine.liveness.ReferenceCountedLivenessNode
- All Implemented Interfaces:
LogOutputAppendable,LivenessManager,LivenessNode,LivenessReferent
- Direct Known Subclasses:
BarrageSnapshotImpl,BarrageSubscriptionImpl,LivenessArtifact,LivenessScope,StreamPublisherBase,TableLocationSubscriptionBuffer
public abstract class ReferenceCountedLivenessNode
extends ReferenceCountedLivenessReferent
implements LivenessNode
LivenessNode implementation that relies on reference counting to determine its liveness.-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedReferenceCountedLivenessNode(boolean enforceStrongReachability) -
Method Summary
Modifier and TypeMethodDescriptionfinal voidEnsure that this node'sRetainedReferenceTrackeris kept alive and will fire cleanup even if this node is garbage-collected without an explicit call toonReferenceCountAtZero().protected Optional<? extends LivenessReferent> findAnyManagedReferent(Predicate<LivenessReferent> referentPredicate) Find a managed reference that matches the given predicate.protected voidforEachManagedReference(Consumer<LivenessReferent> consumer) Apply consumer to each managed reference.WeakReference<? extends LivenessReferent> Get aWeakReferenceto this referent.final voidPackage-private forSerializablesub-classes to use inreadObjectonly.final voidCallback method that will be invoked when the reference count returns to zero.final booleantryManage(@NotNull LivenessReferent referent) Attempt to addreferentto this manager.final booleantryUnmanage(@NotNull LivenessReferent referent) If this manager manages referent one or more times, drop one such reference.final booleantryUnmanage(@NotNull Stream<? extends LivenessReferent> referents) For each referent in referents, if this manager manages referent one or more times, drop one such reference.Methods inherited from class io.deephaven.engine.liveness.ReferenceCountedLivenessReferent
destroy, dropReference, tryRetainReferenceMethods inherited from class io.deephaven.util.referencecounting.ReferenceCounted
append, decrementReferenceCount, forceReferenceCountToZero, getReferenceCountDebug, incrementReferenceCount, resetReferenceCount, toString, tryDecrementReferenceCount, tryIncrementReferenceCountMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface io.deephaven.engine.liveness.LivenessManager
manage, unmanage, unmanageMethods inherited from interface io.deephaven.engine.liveness.LivenessReferent
dropReference, getReferentDescription, retainReference, tryRetainReference
-
Constructor Details
-
ReferenceCountedLivenessNode
protected ReferenceCountedLivenessNode(boolean enforceStrongReachability) - Parameters:
enforceStrongReachability- Whether thisLivenessManagershould maintain strong references to its referents
-
-
Method Details
-
initializeTransientFieldsForLiveness
Package-private forSerializablesub-classes to use inreadObjectonly. Public to allow unit tests in another package to work around mock issues where the constructor is never invoked. -
getWeakReference
Description copied from interface:LivenessReferentGet aWeakReferenceto this referent. This may be cached, or newly created.- Specified by:
getWeakReferencein interfaceLivenessReferent- Overrides:
getWeakReferencein classReferenceCountedLivenessReferent- Returns:
- A new or cached reference to this referent
-
ensureCleanupOnGC
public final void ensureCleanupOnGC()Ensure that this node'sRetainedReferenceTrackeris kept alive and will fire cleanup even if this node is garbage-collected without an explicit call toonReferenceCountAtZero().Registers a phantom reference to this node via
CleanupReferenceProcessorInstance.LIVENESSwhose action captures the tracker. This keeps the tracker strongly reachable (via the registration set) until after this node is collected, guaranteeing that the tracker'sCleanupReference.cleanup()will be invoked.Note, each call registers a new cleanup action. If you call this method multiple times, you may have multiple cleanup actions registered, and thus multiple calls to
CleanupReference.cleanup()when this node is collected. -
tryManage
Description copied from interface:LivenessManagerAttempt to addreferentto this manager. Will succeed ifreferentis live and if this manager is not aLivenessReferentor is live.- Specified by:
tryManagein interfaceLivenessManager- Parameters:
referent- The referent to add- Returns:
- Whether the referent was in fact added
-
tryUnmanage
Description copied from interface:LivenessManagerIf this manager manages referent one or more times, drop one such reference. If this manager is also aLivenessReferent, then this method is a no-op ifthisis not live.Strongly prefer using
LivenessManager.tryUnmanage(Stream)} when multiple referents should be unmanaged.- Specified by:
tryUnmanagein interfaceLivenessManager- Parameters:
referent- The referent to drop- Returns:
- If this node is also a
LivenessReferent, whether this node was live and thus in fact tried to drop a reference. Else always returnstrueif dropping a reference via this method is supported by the implementation.
-
tryUnmanage
Description copied from interface:LivenessManagerFor each referent in referents, if this manager manages referent one or more times, drop one such reference. If this manager is also aLivenessReferent, then this method is a no-op ifthisis not live.- Specified by:
tryUnmanagein interfaceLivenessManager- Parameters:
referents- The referents to drop- Returns:
- If this node is also a
LivenessReferent, whether this node was live and thus in fact tried to drop the references. Else always returnstrueif dropping a reference via this method is supported by the implementation.
-
onReferenceCountAtZero
public final void onReferenceCountAtZero()Description copied from class:ReferenceCountedCallback method that will be invoked when the reference count returns to zero.- Overrides:
onReferenceCountAtZeroin classReferenceCountedLivenessReferent
-
findAnyManagedReferent
protected Optional<? extends LivenessReferent> findAnyManagedReferent(Predicate<LivenessReferent> referentPredicate) Find a managed reference that matches the given predicate.- Parameters:
referentPredicate- a predicate to test against our managed items- Returns:
- an Optional of a LivenessReferent that matches the given predicate; or empty if no such reference exists
-
forEachManagedReference
Apply consumer to each managed reference.
-