Overview | Package | Class | Tree | Deprecated | Index | Help
| J avolution v5.2 (J2SE 1.5+)
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## javolution.context
Class Allocator<T>

    java.lang.Object
      javolution.context.Allocator<T>

    public abstract class Allocator<T>

extends java.lang.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 boolean` | `keepInQueue` Indicates if the objects from the queue should be kept in the queue.
`protected T[]` | `queue` Holds the queue of available objects (typically recycled).
`protected int` | `queueSize` Holds the number of objects in this allocator queue.
`protected java.lang.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 java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### user

    protected java.lang.Thread user

  Holds the current user or `null` if deactivated.

### queue

    protected T[] queue

  Holds the queue of available objects (typically recycled).

### queueSize

    protected int queueSize

  Holds the number of objects in this allocator queue.

### keepInQueue

    protected boolean keepInQueue

  Indicates if the objects from the queue should be kept in the 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.

Overview | Package | Class | Tree | Deprecated | Index | Help
| J avolution v5.2 (J2SE 1.5+)
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2005 - 2007 Javolution.