JADE v6.1

com.dautelle.realtime
Class ObjectPool

java.lang.Object
  extended bycom.dautelle.realtime.ObjectPool

public abstract class ObjectPool
extends java.lang.Object

This abstract class represents an object pool managed by a PoolContext. Local pools are safe to use without synchronization. The real-time framework guarantees that no more than one thread can have access to any local pool at any given time. As for operations upon non-local pools, synchronization has to be performed on the pool itself to guarantee thread-safety.

Version:
6.0, May 16, 2004
Author:
Jean-Marie Dautelle

Field Summary
protected static int DEFAULT_POOL_SIZE
          Holds the default pool size (32).
 
Constructor Summary
protected ObjectPool()
          Default constructor.
 
Method Summary
protected abstract  void clearAll()
          Removes all objects from this pool.
abstract  void export(java.lang.Object obj)
          Exports the specified object out of this pool to the outer pool.
 ObjectPool getOuter()
          Returns the outer pool of this pool.
 java.lang.Thread getUser()
          Returns the current user of this pool or null if none.
 boolean inUse()
          Indicates if this pool is in use.
 boolean isLocal()
          Indicates if this pool is actively used by the current thread.
abstract  java.lang.Object next()
          Returns the next available object from this pool.
abstract  void recycle(java.lang.Object obj)
          Recycles the specified object.
protected abstract  void recycleAll()
          Recycles all the objects of this pool.
abstract  void remove(java.lang.Object obj)
          Removes the specified object from this pool.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_POOL_SIZE

protected static final int DEFAULT_POOL_SIZE
Holds the default pool size (32).

See Also:
Constant Field Values
Constructor Detail

ObjectPool

protected ObjectPool()
Default constructor.

Method Detail

getUser

public final java.lang.Thread getUser()
Returns the current user of this pool or null if none.

Returns:
the pool current user.

isLocal

public final boolean isLocal()
Indicates if this pool is actively used by the current thread. The framework ensures that local pools are visible to their users only (concurrent executions are performed in an inner pool context). Operations on local pools are therefore thread-safe without requiring synchronization.

Returns:
true if this pool is local for the current thread; false otherwise.
Throws:
java.lang.IllegalAccessError - if this operation is called upon a pool not currently in use.

inUse

public final boolean inUse()
Indicates if this pool is in use. A pool can be in use and not having a current user if the user has entered an inner pool.

Returns:
true if at least one thread has been allocating from this pool; false if this pool is not being used at all (e.g. inner pool).

getOuter

public final ObjectPool getOuter()
Returns the outer pool of this pool.

Returns:
the outer pool or null if the outer is the heap.

next

public abstract java.lang.Object next()
Returns the next available object from this pool. If there is none, a new object is allocated on the heap, added to the pool and returned.

Returns:
the next available object from this pool.

recycle

public abstract void recycle(java.lang.Object obj)
Recycles the specified object. Callers should make sure that the recycled object is not going to be referenced anymore (in a heap context it would be garbage collected).

Parameters:
obj - the object to recycle to this pool.
Throws:
java.lang.IllegalArgumentException - if the specified object do not belong to the pool.

export

public abstract void export(java.lang.Object obj)
Exports the specified object out of this pool to the outer pool. To avoid pool depletion it is usually recommended to swap the specified object with a free object from the outer pool.

Parameters:
obj - the object to export to outer pool.
Throws:
java.lang.IllegalArgumentException - if the specified object do not belong to the pool.

remove

public abstract void remove(java.lang.Object obj)
Removes the specified object from this pool. After removal the specified object belongs to the heap and will be garbage collected when not referenced any more.

Parameters:
obj - the object to remove from this pool.
Throws:
java.lang.IllegalArgumentException - if the specified object do not belong to the pool.

recycleAll

protected abstract void recycleAll()
Recycles all the objects of this pool.

Note: This method is called upon exit of a pool context for which this pool has been used.


clearAll

protected abstract void clearAll()
Removes all objects from this pool.

Note: This method is called upon clearing of the pool context this pool belongs to.


JADE v6.1

Copyright © 2004 Jean-Marie Dautelle.