org.apache.hadoop.util
Class CloseableReferenceCount

java.lang.Object
  extended by 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 Summary
CloseableReferenceCount()
           
 
Method Summary
 int getReferenceCount()
          Get the current reference count.
 boolean isOpen()
          Return true if the status is currently open.
 void reference()
          Increment the reference count.
 int setClosed()
          Mark the status as closed.
 boolean unreference()
          Decrement the reference count.
 void unreferenceCheckClosed()
          Decrement the reference count, checking to make sure that the CloseableReferenceCount is not closed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CloseableReferenceCount

public CloseableReferenceCount()
Method Detail

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.


Copyright © 2014 Apache Software Foundation. All Rights Reserved.