net.sf.sasl.common.pool
Class SingletonPool
java.lang.Object
net.sf.sasl.common.pool.AbstractPool<Class<?>,Object>
net.sf.sasl.common.pool.SingletonPool
public class SingletonPool
- extends AbstractPool<Class<?>,Object>
The class could be used to create and share singleton instances without the need to define
a static singleton creation procedure at the singleton class.
- Since:
- 0.0.2 (sasl-common-library)
- Author:
- Philipp Förmer
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
SingletonPool
public SingletonPool()
getSharedInstance
public static SingletonPool getSharedInstance()
- Returns a shared instance of the SingletonPool.
- Returns:
- non null.
- Since:
- 0.0.2 (sasl-common-library)
retrieveSingleton
public <T> T retrieveSingleton(Class<T> clazz)
throws IllegalArgumentException,
ReflectionException
- Returns a pooled singleton instance of the given class.
If no singleton instance was yet created for the given class, than a new one will be
instantiated via reflection. As of this, the class should define a zero argument constructor,
otherwise the instantiation will fail.
- Type Parameters:
T
- - Parameters:
clazz
- non null
- Returns:
- non null pooled instance.
- Throws:
IllegalArgumentException
- if parameter clazz is null.
ReflectionException
- if an error occured during creating a not yet pooled singleton instance.- Since:
- 0.0.2 (sasl-common-library)
free
public <T> void free(Class<T> clazz,
T instance)
- Notifies the pool that a reference under the given key is no longer needed.
The instance must be same to the instance the key points to.
This allows the pool to free pooled instances from the pool so that they could get garbage collected.
- Type Parameters:
T
- - Parameters:
clazz
- null or non null.instance
- null or non null.- Since:
- 0.0.2 (sasl-common-library)
Copyright © 2010. All Rights Reserved.