Package org.apache.hadoop.util
Class CloseableReferenceCount
java.lang.Object
org.apache.hadoop.util.CloseableReferenceCount
A closeable object that maintains a reference count.
Once the object is closed, attempting to take a new reference will throw
ClosedChannelException.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintGet the current reference count.booleanisOpen()Return true if the status is currently open.voidIncrement the reference count.intMark the status as closed.booleanDecrement the reference count.voidDecrement the reference count, checking to make sure that the CloseableReferenceCount is not closed.
-
Constructor Details
-
CloseableReferenceCount
public CloseableReferenceCount()
-
-
Method Details
-
reference
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
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
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.
-