net.sf.sasl.common.pool
Class AbstractPool<K,V>

java.lang.Object
  extended by net.sf.sasl.common.pool.AbstractPool<K,V>
Direct Known Subclasses:
SingletonPool

public abstract class AbstractPool<K,V>
extends Object

Small abstract (shared resource) pool from which specialised pools could be derived. Supports in principle to garbage collect unused pool entries, because a reference counter is sponsored to stored values. The reference counter is only working correctly if resources are allocated and freed by the user.

Since:
0.0.2 (sasl-common-library)
Author:
Philipp Förmer

Nested Class Summary
protected static class AbstractPool.PoolEntry<V>
           
 
Constructor Summary
AbstractPool()
           
 
Method Summary
protected  boolean add(K key, V value)
          Adds the value under the given key to the pool, if the key is unknown to the pool.
 boolean containsKey(K key)
          Returns true, if the key is known to the pool, false else.
protected  void free(K key)
          Notifies the pool that a reference under the given key is no longer needed.
protected  AbstractPool.PoolEntry<V> getPoolEntry(K key)
          Returns the pool entry to the corresponding key, or null if the key is unknown to the pool.
protected  V retrieve(K key)
          Returns the value to the corresponding key from the pool.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractPool

public AbstractPool()
Method Detail

add

protected boolean add(K key,
                      V value)
Adds the value under the given key to the pool, if the key is unknown to the pool. In this case true will be returned. If the key is already known, than false will be returned.

Parameters:
key - null or non null.
value - null or non null.
Returns:
true or false.
Since:
0.0.2 (sasl-common-library)

retrieve

protected V retrieve(K key)
Returns the value to the corresponding key from the pool. If a value was found, than the reference counter of the value will be updated.

Parameters:
key - null or non null.
Returns:
null or non null.
Since:
0.0.2 (sasl-common-library)

containsKey

public boolean containsKey(K key)
Returns true, if the key is known to the pool, false else.

Parameters:
key - null or non null.
Returns:
true or false.
Since:
0.0.2 (sasl-common-library)

free

protected void free(K key)
Notifies the pool that a reference under the given key is no longer needed. This allows the pool to free pooled instances from the pool so that they could get garbage collected.

Parameters:
key - null or non null.
Since:
0.0.2 (sasl-common-library)

getPoolEntry

protected AbstractPool.PoolEntry<V> getPoolEntry(K key)
Returns the pool entry to the corresponding key, or null if the key is unknown to the pool.

Parameters:
key - null or non null.
Returns:
null or non null.


Copyright © 2010. All Rights Reserved.