Package org.elasticsearch.core
Class AbstractRefCounted
java.lang.Object
org.elasticsearch.core.AbstractRefCounted
- All Implemented Interfaces:
RefCounted
A basic
RefCounted
implementation that is initialized with a ref count of 1 and calls closeInternal()
once it reaches
a 0 ref count.-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
protected abstract void
Method that is invoked once the reference count reaches zero.final boolean
decRef()
Decreases the refCount of this instance.final boolean
Returnstrue
only if there was at least one active reference when the method was called; if it returnsfalse
then the object is closed; future attempts to acquire references will fail.final void
incRef()
Increments the refCount of this instance.static AbstractRefCounted
Construct anAbstractRefCounted
which runs the givenRunnable
when all references are released.final int
refCount()
Returns the current reference count.protected void
touch()
Called whenever the ref count is incremented or decremented.final boolean
Tries to increment the refCount of this instance.
-
Field Details
-
ALREADY_CLOSED_MESSAGE
- See Also:
-
-
Constructor Details
-
AbstractRefCounted
public AbstractRefCounted()
-
-
Method Details
-
incRef
public final void incRef()Description copied from interface:RefCounted
Increments the refCount of this instance.- Specified by:
incRef
in interfaceRefCounted
- See Also:
-
tryIncRef
public final boolean tryIncRef()Description copied from interface:RefCounted
Tries to increment the refCount of this instance. This method will returntrue
iff the refCount was- Specified by:
tryIncRef
in interfaceRefCounted
- See Also:
-
decRef
public final boolean decRef()Description copied from interface:RefCounted
Decreases the refCount of this instance. If the refCount drops to 0, then this instance is considered as closed and should not be used anymore.- Specified by:
decRef
in interfaceRefCounted
- Returns:
- returns
true
if the ref count dropped to 0 as a result of calling this method - See Also:
-
hasReferences
public final boolean hasReferences()Description copied from interface:RefCounted
Returnstrue
only if there was at least one active reference when the method was called; if it returnsfalse
then the object is closed; future attempts to acquire references will fail.- Specified by:
hasReferences
in interfaceRefCounted
- Returns:
- whether there are currently any active references to this object.
-
touch
protected void touch()Called whenever the ref count is incremented or decremented. Can be overridden to record access to the instance for debugging purposes. -
alreadyClosed
protected void alreadyClosed() -
refCount
public final int refCount()Returns the current reference count. -
closeInternal
protected abstract void closeInternal()Method that is invoked once the reference count reaches zero. Implementations of this method must handle all exceptions and may not throw any exceptions. -
of
Construct anAbstractRefCounted
which runs the givenRunnable
when all references are released.
-