net.jini.jeri.kerberos
Class KerberosUtil.SoftCache

java.lang.Object
  extended by net.jini.jeri.kerberos.KerberosUtil.SoftCache
Enclosing class:
KerberosUtil

static class KerberosUtil.SoftCache
extends Object

A synchronized hash map that only maintains soft reference to its value objects. It can be configured to have a limited capacity. LRU replacement policy is used when capacity limit is reached.


Nested Class Summary
private  class KerberosUtil.SoftCache.LRUHashMap
          A linked hash map that implements LRU replacement policy
private static class KerberosUtil.SoftCache.ValueCell
          An instance of this class maintains a reference to a key, and a soft reference to the value the key maps to.
 
Field Summary
private  KerberosUtil.SoftCache.LRUHashMap hash
          Internal hash map used to store the actual key value pairs
private  ReferenceQueue queue
          Reference queue for cleared ValueCells
 
Constructor Summary
KerberosUtil.SoftCache()
          Construct an instance of the SoftCache, using a default capacity of 8.
KerberosUtil.SoftCache(int maxCacheSize)
          Construct an instance of the SoftCache with the given size limit.
KerberosUtil.SoftCache(int maxCacheSize, int initialCapacity)
          Construct an instance of the SoftCache with the given size limit and initial capacity.
 
Method Summary
 void clear()
          Removes all entries in this cache.
 Object get(Object key)
          If there is a mapping in this cache for the specified key, and the softly referenced value of the mapping has not been garbage collected, return the value, other wise, return null.
private  void processQueue()
          Process the internal ReferenceQueue
 Object put(Object key, Object value)
          Associates the specified value with the specified key in this cache.
 Object remove(Object key)
          Removes the mapping for this key from this cache if it still exists.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

hash

private final KerberosUtil.SoftCache.LRUHashMap hash
Internal hash map used to store the actual key value pairs


queue

private ReferenceQueue queue
Reference queue for cleared ValueCells

Constructor Detail

KerberosUtil.SoftCache

KerberosUtil.SoftCache()
Construct an instance of the SoftCache, using a default capacity of 8.


KerberosUtil.SoftCache

KerberosUtil.SoftCache(int maxCacheSize)
Construct an instance of the SoftCache with the given size limit.

Parameters:
maxCacheSize - maximum number of entries allowed in this cache

KerberosUtil.SoftCache

KerberosUtil.SoftCache(int maxCacheSize,
                       int initialCapacity)
Construct an instance of the SoftCache with the given size limit and initial capacity.

Parameters:
maxCacheSize - maximum number of entries allowed in this cache
initialCapacity - initial capacity of the cache
Method Detail

put

public Object put(Object key,
                  Object value)
Associates the specified value with the specified key in this cache. Only a soft reference is maintained to each value object stored in the cache. If the map previously contained a mapping for this key, and the old value object has not been garbage collected, the old value will be returned to the caller. This method is synchronized.

Parameters:
key - key with which the specified value is to be associated.
value - - value to be associated with the specified key, only a soft reference is maintained to value in this cache.
Returns:
previous value associated with specified key, if an old mapping exists and the old value has not been garbage collected, or null if there was no mapping for key. A null return can also indicate that the HashMap previously associated null with the specified key.

get

public Object get(Object key)
If there is a mapping in this cache for the specified key, and the softly referenced value of the mapping has not been garbage collected, return the value, other wise, return null. This method is synchronized.

Parameters:
key - - key whose associated value is to be returned.
Returns:
the value to which this map maps the specified key.

remove

public Object remove(Object key)
Removes the mapping for this key from this cache if it still exists. This method is synchronized.

Parameters:
key - key whose mapping is to be removed from the cache.
Returns:
previous value associated with the specified key that has not been garbage collected, or null. A null return can also indicate that the HashMap previously associated null with the specified key.

clear

public void clear()
Removes all entries in this cache. This method is synchronized.


processQueue

private void processQueue()
Process the internal ReferenceQueue



Copyright 2007-2010, multiple authors.
Licensed under the Apache License, Version 2.0, see the NOTICE file for attributions.