|
J avolution v3.7 (J2SE 1.5+) | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjavolution.realtime.ObjectFactory<T>
public abstract class ObjectFactory<T>
This class represents an object factory; it allows for object recycling and pre-allocation.
Object factories are recommended over class constructors (ref. "new"
keyword) in order to benefit from context-based allocation policies.
For example:
static ObjectFactory<int[][]> BOARD_FACTORY = new ObjectFactory<int[][]>() {
protected int[][] create() {
return new int[8][8];
}
};
...
int[][] board = BOARD_FACTORY.object(); // On the stack if current thread executes
... // in a PoolContext; heap otherwise.
ObjectFactory instances are uniquely identified by their class
(one instance per sub-class). The number of instances is voluntarely
limited (see
Javolution Configuration for details).
| Constructor Summary | |
|---|---|
protected |
ObjectFactory()
Default constructor. |
| Method Summary | |
|---|---|
protected void |
cleanup(T obj)
Cleans-up this factory's objects for future reuse. |
protected abstract T |
create()
Constructs a new object for this factory (using the new
keyword). |
ObjectPool<T> |
currentPool()
Returns the local pool for the current thread or the heapPool()
when the current thread executes in a HeapContext. |
ObjectPool<T> |
heapPool()
Returns the pool representing the heap; this pool always returns objects allocated on the heap. |
protected ObjectPool<T> |
newPool()
Returns a new local pool for this object factory. |
T |
object()
Returns a factory object possibly recycled or preallocated. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
protected ObjectFactory()
java.lang.UnsupportedOperationException - if more than one instance per
factory sub-class or if the MAX number of factories
has been reached.| Method Detail |
|---|
protected abstract T create()
new
keyword).
public T object()
object(PoolContext.current()).
public final ObjectPool<T> currentPool()
heapPool()
when the current thread executes in a HeapContext.
public final ObjectPool<T> heapPool()
protected void cleanup(T obj)
obj - the object product of this factory being recycled.
java.lang.UnsupportedOperationException - if this factory does not
support object clean-up (default).protected ObjectPool<T> newPool()
|
J avolution v3.7 (J2SE 1.5+) | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||