rcx.josx.util
Class Recycler

java.lang.Object
  extended by rcx.josx.util.Recycler
Direct Known Subclasses:
ArrayRecycler

public abstract class Recycler
extends java.lang.Object

An abstract object recycler. This class should be extended to define the createInstance method for a particular kind of Recyclable.

Note that the caller is expected to provide thread safety for instances of this class.

See Also:
Recyclable

Constructor Summary
Recycler()
          Constructs a recycler.
 
Method Summary
 Recyclable allocate()
          Attempts to obtain a free object.
 void recycle(Recyclable r)
          Reclaims a Recyclable previously allocated with the allocate method.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Recycler

public Recycler()
Constructs a recycler.

Parameters:
capacity - Maximum number of allocated (non garbage) objects at any given time.
Method Detail

allocate

public final Recyclable allocate()
Attempts to obtain a free object.

Returns:
A Recyclable object reference.

recycle

public final void recycle(Recyclable r)
Reclaims a Recyclable previously allocated with the allocate method. The release method of the Recyclable object is invoked here.