javolution.context
Class Allocator<T>

Object
  extended by Allocator<T>

public abstract class Allocator<T>
extends Object

This class represents an object allocator; instances of this class are generated by AllocatorContext.

If an allocator has recycled objects available, those are returned first, before allocating new ones.

Allocator instances are thread-safe without synchronization, they are the "production lines" of the factories, their implementation is derived from the AllocatorContext to which they belong (e.g. heap allocators for HeapContext).

Version:
5.2, August 14, 2007
Author:
Jean-Marie Dautelle
See Also:
AllocatorContext.getAllocator(ObjectFactory)

Field Summary
protected  T[] queue
          Holds the queue of objects belonging to this allocator (always used first when available).
protected  int queueSize
          Holds the number of objects in this allocator queue.
protected  Thread user
          Holds the current user or null if deactivated.
 
Constructor Summary
protected Allocator()
          Default constructor.
 
Method Summary
protected abstract  T allocate()
          Allocates a new object, this method is called when the allocator queue is empty.
 T next()
          Returns the next available object from this allocator queue or allocate() one if none available.
protected abstract  void recycle(T object)
          Recycles the specified object to this queue.
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

user

protected Thread user
Holds the current user or null if deactivated.


queue

protected T[] queue
Holds the queue of objects belonging to this allocator (always used first when available).


queueSize

protected int queueSize
Holds the number of objects in this allocator queue.

Constructor Detail

Allocator

protected Allocator()
Default constructor.

Method Detail

next

public final T next()
Returns the next available object from this allocator queue or allocate() one if none available.

Returns:
the next available object ready to use.

allocate

protected abstract T allocate()
Allocates a new object, this method is called when the allocator queue is empty.

Returns:
the allocated object.

recycle

protected abstract void recycle(T object)
Recycles the specified object to this queue.

Parameters:
object - the object to recycle.


Copyright © 2005-2012 Javolution. All Rights Reserved.