Class AbstractRefCounted

java.lang.Object
org.elasticsearch.common.util.concurrent.AbstractRefCounted
All Implemented Interfaces:
RefCounted

public abstract class AbstractRefCounted
extends java.lang.Object
implements RefCounted
A basic RefCounted implementation that is initialized with a ref count of 1 and calls closeInternal() once it reaches a 0 ref count
  • Constructor Summary

    Constructors
    Constructor Description
    AbstractRefCounted​(java.lang.String name)  
  • Method Summary

    Modifier and Type Method Description
    protected void alreadyClosed()  
    protected abstract void closeInternal()
    Method that is invoked once the reference count reaches zero.
    boolean decRef()
    Decreases the refCount of this instance.
    java.lang.String getName()
    gets the name of this instance
    void incRef()
    Increments the refCount of this instance.
    int refCount()
    Returns the current reference count.
    protected void touch()
    Called whenever the ref count is incremented or decremented.
    boolean tryIncRef()
    Tries to increment the refCount of this instance.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • AbstractRefCounted

      public AbstractRefCounted​(java.lang.String name)
  • Method Details

    • incRef

      public final void incRef()
      Description copied from interface: RefCounted
      Increments the refCount of this instance.
      Specified by:
      incRef in interface RefCounted
      See Also:
      RefCounted.decRef(), RefCounted.tryIncRef()
    • tryIncRef

      public final boolean tryIncRef()
      Description copied from interface: RefCounted
      Tries to increment the refCount of this instance. This method will return true iff the refCount was
      Specified by:
      tryIncRef in interface RefCounted
      See Also:
      RefCounted.decRef(), RefCounted.incRef()
    • 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 interface RefCounted
      Returns:
      returns true if the ref count dropped to 0 as a result of calling this method
      See Also:
      RefCounted.incRef()
    • touch

      protected void touch()
      Called whenever the ref count is incremented or decremented. Can be implemented by implementations to a record of access to the instance for debugging purposes.
    • alreadyClosed

      protected void alreadyClosed()
    • refCount

      public int refCount()
      Returns the current reference count.
    • getName

      public java.lang.String getName()
      gets the name of this instance
    • 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.