Package org.elasticsearch.core
Interface RefCounted
- All Known Implementing Classes:
AbstractRefCounted
public interface RefCounted
An interface for objects that need to be notified when all reference
to itself are not in user anymore. This implements basic reference counting
for instance if async operations holding on to services that are close concurrently
but should be functional until all async operations have joined
Classes implementing this interface should ref counted at any time ie. if an object is used it's reference count should
be increased before using it by calling #incRef and a corresponding #decRef must be called in a try/finally
block to release the object again ie.:
inst.incRef(); try { // use the inst... } finally { inst.decRef(); }
-
Method Summary
Modifier and TypeMethodDescriptionboolean
decRef()
Decreases the refCount of this instance.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.void
incRef()
Increments the refCount of this instance.boolean
Tries to increment the refCount of this instance.
-
Method Details
-
incRef
void incRef()Increments the refCount of this instance.- Throws:
IllegalStateException
- iff the reference counter can not be incremented.- See Also:
-
tryIncRef
boolean tryIncRef()Tries to increment the refCount of this instance. This method will returntrue
iff the refCount was -
decRef
boolean decRef()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.- Returns:
- returns
true
if the ref count dropped to 0 as a result of calling this method - See Also:
-
hasReferences
boolean hasReferences()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.- Returns:
- whether there are currently any active references to this object.
-