Class CloseableReferenceCount

java.lang.Object
org.apache.hadoop.util.CloseableReferenceCount

public class CloseableReferenceCount extends Object
A closeable object that maintains a reference count. Once the object is closed, attempting to take a new reference will throw ClosedChannelException.
  • Constructor Details

    • CloseableReferenceCount

      public CloseableReferenceCount()
  • Method Details

    • reference

      public void reference() throws ClosedChannelException
      Increment the reference count.
      Throws:
      ClosedChannelException - If the status is closed.
    • unreference

      public boolean unreference()
      Decrement the reference count.
      Returns:
      True if the object is closed and has no outstanding references.
    • unreferenceCheckClosed

      public void unreferenceCheckClosed() throws ClosedChannelException
      Decrement the reference count, checking to make sure that the CloseableReferenceCount is not closed.
      Throws:
      AsynchronousCloseException - If the status is closed.
      ClosedChannelException
    • isOpen

      public boolean isOpen()
      Return true if the status is currently open.
      Returns:
      True if the status is currently open.
    • setClosed

      public int setClosed() throws ClosedChannelException
      Mark the status as closed. Once the status is closed, it cannot be reopened.
      Returns:
      The current reference count.
      Throws:
      ClosedChannelException - If someone else closes the object before we do.
    • getReferenceCount

      public int getReferenceCount()
      Get the current reference count.
      Returns:
      The current reference count.