com.opensymphony.xwork2.inject.util
Class ReferenceCache<K,V>

java.lang.Object
  extended by com.opensymphony.xwork2.inject.util.ReferenceMap<K,V>
      extended by com.opensymphony.xwork2.inject.util.ReferenceCache<K,V>
All Implemented Interfaces:
Serializable, Map<K,V>

public abstract class ReferenceCache<K,V>
extends ReferenceMap<K,V>

Extends ReferenceMap to support lazy loading values by overriding create(Object).

Author:
crazybob@google.com (Bob Lee)
See Also:
Serialized Form

Nested Class Summary
(package private)  class ReferenceCache.CallableCreate
           
 
Nested classes/interfaces inherited from class com.opensymphony.xwork2.inject.util.ReferenceMap
ReferenceMap.Entry, ReferenceMap.InternalReference, ReferenceMap.KeyReferenceAwareWrapper, ReferenceMap.ReferenceAwareWrapper, ReferenceMap.SoftKeyReference, ReferenceMap.SoftValueReference, ReferenceMap.Strategy, ReferenceMap.WeakKeyReference, ReferenceMap.WeakValueReference
 
Field Summary
(package private)  ConcurrentMap<Object,Future<V>> futures
           
(package private)  ThreadLocal<Future<V>> localFuture
           
private static long serialVersionUID
           
 
Fields inherited from class com.opensymphony.xwork2.inject.util.ReferenceMap
delegate, keyReferenceType, valueReferenceType
 
Constructor Summary
ReferenceCache()
          Equivalent to new ReferenceCache(STRONG, STRONG).
ReferenceCache(ReferenceType keyReferenceType, ReferenceType valueReferenceType)
           
 
Method Summary
protected  void cancel()
          Cancels the current create(Object).
protected abstract  V create(K key)
          Override to lazy load values.
 V get(Object key)
           If this map does not contain an entry for the given key and create(Object) has been overridden, this method will create a new value, put it in the map, and return it.
(package private)  V internalCreate(K key)
           
static
<K,V> ReferenceCache<K,V>
of(ReferenceType keyReferenceType, ReferenceType valueReferenceType, Function<? super K,? extends V> function)
          Returns a ReferenceCache delegating to the specified function.
private  void readObject(ObjectInputStream in)
           
 
Methods inherited from class com.opensymphony.xwork2.inject.util.ReferenceMap
clear, containsKey, containsValue, dereference, dereferenceCollection, dereferenceEntry, dereferenceKey, dereferenceKeySet, dereferenceValue, dereferenceValues, ensureNotNull, ensureNotNull, entrySet, execute, getPutStrategy, internalGet, isEmpty, keyHashCode, keySet, makeKeyReferenceAware, makeValueReferenceAware, put, putAll, putIfAbsent, putIfAbsentStrategy, putStrategy, referenceEquals, referenceKey, referenceValue, remove, remove, replace, replace, replaceStrategy, size, values
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.Map
equals, hashCode
 

Field Detail

serialVersionUID

private static final long serialVersionUID
See Also:
Constant Field Values

futures

transient ConcurrentMap<Object,Future<V>> futures

localFuture

transient ThreadLocal<Future<V>> localFuture
Constructor Detail

ReferenceCache

public ReferenceCache(ReferenceType keyReferenceType,
                      ReferenceType valueReferenceType)

ReferenceCache

public ReferenceCache()
Equivalent to new ReferenceCache(STRONG, STRONG).

Method Detail

create

protected abstract V create(K key)
Override to lazy load values. Use as an alternative to ReferenceMap.put(Object,Object). Invoked by getter if value isn't already cached. Must not return null. This method will not be called again until the garbage collector reclaims the returned value.


internalCreate

V internalCreate(K key)

get

public V get(Object key)
If this map does not contain an entry for the given key and create(Object) has been overridden, this method will create a new value, put it in the map, and return it.

Specified by:
get in interface Map<K,V>
Overrides:
get in class ReferenceMap<K,V>
Throws:
NullPointerException - if create(Object) returns null.
CancellationException - if the creation is cancelled. See cancel().

cancel

protected void cancel()
Cancels the current create(Object). Throws CancellationException to all clients currently blocked on get(Object).


of

public static <K,V> ReferenceCache<K,V> of(ReferenceType keyReferenceType,
                                           ReferenceType valueReferenceType,
                                           Function<? super K,? extends V> function)
Returns a ReferenceCache delegating to the specified function. The specified function must not return null.


readObject

private void readObject(ObjectInputStream in)
                 throws IOException,
                        ClassNotFoundException
Throws:
IOException
ClassNotFoundException


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