org.jasig.portal.utils.threading
Class MapCachingDoubleCheckedCreator<K,T>

java.lang.Object
  extended by org.jasig.portal.utils.threading.DoubleCheckedCreator<T>
      extended by org.jasig.portal.utils.threading.MapCachingDoubleCheckedCreator<K,T>

public abstract class MapCachingDoubleCheckedCreator<K,T>
extends DoubleCheckedCreator<T>

Implementation of DoubleCheckedCreator that stores what it creates in a backing Map. Subclasses need to implement getKey(Object...) to provide a Map key to use for the arguments and create(Object...) to create new instances of the objects.
The default constructor uses a ReferenceMap with hard references to the keys

Version:
$Revision$
Author:
Eric Dalquist

Field Summary
 
Fields inherited from class org.jasig.portal.utils.threading.DoubleCheckedCreator
logger, readLock, writeLock
 
Constructor Summary
MapCachingDoubleCheckedCreator()
           
MapCachingDoubleCheckedCreator(Map<K,T> cache)
           
MapCachingDoubleCheckedCreator(Map<K,T> cache, ReadWriteLock readWriteLock)
           
 
Method Summary
 void clear()
          Allows the object cache map to be cleared of entries
protected  T create(Object... args)
           
protected abstract  T createInternal(K key, Object... args)
           
 Map<K,T> getCacheMap()
           
protected abstract  K getKey(Object... args)
           
protected  T retrieve(Object... args)
           
 String toString()
           
 
Methods inherited from class org.jasig.portal.utils.threading.DoubleCheckedCreator
get, invalid
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MapCachingDoubleCheckedCreator

public MapCachingDoubleCheckedCreator()

MapCachingDoubleCheckedCreator

public MapCachingDoubleCheckedCreator(Map<K,T> cache)
Parameters:
cache - The Map to store created instances in

MapCachingDoubleCheckedCreator

public MapCachingDoubleCheckedCreator(Map<K,T> cache,
                                      ReadWriteLock readWriteLock)
Parameters:
cache - The Map to store created instances in
readWriteLock - the ReadWriteLock to use for the double checked locking
Method Detail

getCacheMap

public final Map<K,T> getCacheMap()
Returns:
A read-only view of the underlying Map used to cache created objects

clear

public final void clear()
Allows the object cache map to be cleared of entries


getKey

protected abstract K getKey(Object... args)
Parameters:
args - Optional arguments passed to DoubleCheckedCreator.get(Object...) used to create a key
Returns:
The key for the specified arguments

createInternal

protected abstract T createInternal(K key,
                                    Object... args)
Parameters:
key - The key to create the object for
args - The object retrieval arguments
Returns:
A new object instance for the key and args

create

protected final T create(Object... args)
Specified by:
create in class DoubleCheckedCreator<T>
Parameters:
args - Arguments to use when creating the object
Returns:
A newly created object

retrieve

protected final T retrieve(Object... args)
Specified by:
retrieve in class DoubleCheckedCreator<T>
Parameters:
args - Arguments to use when retrieving the object
Returns:
An existing object if available

toString

public String toString()
Overrides:
toString in class Object
See Also:
Object.toString()


Copyright © 2010 Jasig. All Rights Reserved.