jfun.yan.factory
Class SimplePool<T>

java.lang.Object
  extended by jfun.yan.factory.SimplePool<T>
All Implemented Interfaces:
java.io.Serializable, Pool<T>

public abstract class SimplePool<T>
extends java.lang.Object
implements Pool<T>

A simple implementation of Pool that uses null to indicate non-existent pool entry.

This implementation synchronizes on getMutex() for thread safety.

Author:
Ben Yu Feb 2, 2006 3:14:45 PM
See Also:
Serialized Form

Constructor Summary
SimplePool()
           
 
Method Summary
abstract  T get()
          Get the pooled instance.
 T getInstance(Factory<T> factory)
          Apply the pooling strategy and return an instance from either the pool or the factory.
protected abstract  java.lang.Object getMutex()
          Get the object that can be used to synchronize.
 T getPooledInstance(T def)
          Get the instance that's already pooled.
protected static
<X> X
ifnull(X obj, X def)
           
 boolean isPooled()
          Is this pool currently having something in cache?
abstract  void set(T val)
          set an value to the pool.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimplePool

public SimplePool()
Method Detail

getInstance

public T getInstance(Factory<T> factory)
Description copied from interface: Pool
Apply the pooling strategy and return an instance from either the pool or the factory.

Specified by:
getInstance in interface Pool<T>
Parameters:
factory - the factory to create the object instance.
Returns:
the object instance.

getPooledInstance

public T getPooledInstance(T def)
Description copied from interface: Pool
Get the instance that's already pooled.

Specified by:
getPooledInstance in interface Pool<T>
Parameters:
def - the default value to return if there's no pooled instance.
Returns:
the pooled instance or the default object.

isPooled

public boolean isPooled()
Description copied from interface: Pool
Is this pool currently having something in cache?

Specified by:
isPooled in interface Pool<T>

ifnull

protected static <X> X ifnull(X obj,
                              X def)

get

public abstract T get()
Get the pooled instance. null if not found.

Returns:
the pooled instance.

set

public abstract void set(T val)
set an value to the pool.

Parameters:
val - the value to be pooled.

getMutex

protected abstract java.lang.Object getMutex()
Get the object that can be used to synchronize.