org.apache.lucene.gdata.utils
Class SimpleObjectPool<Type>

java.lang.Object
  extended by org.apache.lucene.gdata.utils.SimpleObjectPool<Type>
Type Parameters:
Type -
All Implemented Interfaces:
Pool<Type>

public class SimpleObjectPool<Type>
extends Object
implements Pool<Type>

A Simple implementation of the Pool interface using a Stack as a buffer for the pooled objects. This implementation does not provide any timeout mechanismn. Objects will stay inside the pool until the pool is destroyed.

If any object will be released e.g. handover to the pool and the pool has already enought objects in the pool the released object will be destroyed. If the pool is empty a new Object will be created.

This implementation does not track any references to the objects aquired by any other resource. The objects must be destroyed manually if not released to the pool after aquired.

Author:
Simon Willnauer

Constructor Summary
SimpleObjectPool(int size, PoolObjectFactory<Type> factory)
          Constructs a new SimpleObjectPool and sets the ObjectFactory and the pool size
SimpleObjectPool(PoolObjectFactory<Type> factory)
           
 
Method Summary
 Type aquire()
          Return an object from the pool or create one if the pool is empty.
 void destroy()
          releases all pooled objects using PoolObjectFactory.destroyInstance(Object) method.
 boolean expires()
           
 long getExpireTime()
           
 int getSize()
           
 void release(Type type)
          Adds a previously aquired object to the pool.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimpleObjectPool

public SimpleObjectPool(int size,
                        PoolObjectFactory<Type> factory)
Constructs a new SimpleObjectPool and sets the ObjectFactory and the pool size

Parameters:
size - - the maximum size of the pool
factory - - factory to create and destroy pooled objects

SimpleObjectPool

public SimpleObjectPool(PoolObjectFactory<Type> factory)
Parameters:
factory -
Method Detail

aquire

public Type aquire()
Description copied from interface: Pool
Return an object from the pool or create one if the pool is empty.

Specified by:
aquire in interface Pool<Type>
Returns:
- a pooled object
See Also:
Pool.aquire()

release

public void release(Type type)
Description copied from interface: Pool
Adds a previously aquired object to the pool. If the pool has already been closed or if the pool has already reached his size the released object will be destroyed using PoolObjectFactory.destroyInstance(Object) method.

Specified by:
release in interface Pool<Type>
Parameters:
type - - generic type
See Also:
Pool.release(Object)

getSize

public int getSize()
Specified by:
getSize in interface Pool<Type>
Returns:
- the defined size of the pool
See Also:
Pool.getSize()

getExpireTime

public long getExpireTime()
Specified by:
getExpireTime in interface Pool<Type>
Returns:
- the expire time of the objects in the pool if defined
See Also:
Pool.getExpireTime()

expires

public boolean expires()
Specified by:
expires in interface Pool<Type>
Returns:
true if and only if the pool uses an expire mechanismn, otherwith false
See Also:
Pool.expires()

destroy

public void destroy()
Description copied from interface: Pool
releases all pooled objects using PoolObjectFactory.destroyInstance(Object) method. The pool can not be reused after this method has been called

Specified by:
destroy in interface Pool<Type>
See Also:
Pool.destroy()


Copyright © 2000-2008 Apache Software Foundation. All Rights Reserved.