org.fusesource.hawtdispatch
Class BaseRetained

java.lang.Object
  extended by org.fusesource.hawtdispatch.BaseRetained
All Implemented Interfaces:
Retained

public class BaseRetained
extends Object
implements Retained

Base class that implements the Retained interface.

Author:
Hiram Chirino

Constructor Summary
BaseRetained()
           
 
Method Summary
protected  void assertRetained()
          Subclasses can use this method to validate that the object has not yet been released.
protected  void dispose()
           This method will be called once the release retained reaches zero.
 Runnable getDisposer()
           
 void release()
           Decrement the reference count of this object.
protected  void release(int n)
           Decrements the reference count by n.
 void retain()
           Increment the reference count of this object.
 int retained()
           
 void setDisposer(Runnable disposer)
           Adds a disposer runnable that is executed once the object is disposed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BaseRetained

public BaseRetained()
Method Detail

setDisposer

public final void setDisposer(Runnable disposer)

Adds a disposer runnable that is executed once the object is disposed.

A dispatch object's disposer runnable will be invoked on the object's target queue once the object's retain counter reaches zero. This disposer may be used by the application to release any resources associated with the object.

Parameters:
disposer -

getDisposer

public final Runnable getDisposer()

retain

public final void retain()

Increment the reference count of this object.

Calls to retain() must be balanced with calls to release().

Specified by:
retain in interface Retained

release

public final void release()

Decrement the reference count of this object.

An object is asynchronously disposed once all references are released. Using a disposed object will cause undefined errors. The system does not guarantee that a given client is the last or only reference to a given object.

Specified by:
release in interface Retained

release

protected final void release(int n)

Decrements the reference count by n.

An object is asynchronously disposed once all references are released. Using a disposed object will cause undefined errors. The system does not guarantee that a given client is the last or only reference to a given object.

Parameters:
n -

assertRetained

protected final void assertRetained()
Subclasses can use this method to validate that the object has not yet been released. it will throw an IllegalStateException if it has been released.

Throws:
IllegalStateException - if the object has been released.

retained

public final int retained()
Specified by:
retained in interface Retained
Returns:
the retained counter

dispose

protected void dispose()

This method will be called once the release retained reaches zero. It causes the set disposer runnabled to be executed if not null.

Subclasses should override if they want to implement a custom disposing action in addition to the actions performed by the disposer object.



Copyright © 2010-2012 FuseSource, Corp.. All Rights Reserved.