net.nutch.util
Class SoftHashMap

java.lang.Object
  extended byjava.util.AbstractMap
      extended bynet.nutch.util.SoftHashMap
All Implemented Interfaces:
Map

public class SoftHashMap
extends AbstractMap
implements Map

A Map which uses SoftReferences to keep track of values.

This class is suitable for use as a best-effort caching mechanism. Under the hood, it is simply a HashMap, which wraps it's values with SoftReferences. Unlike HashMap, however, null values should not be used- they will be indistinguisable from values which have been garbage collected.

Values should implement SoftHashMap.FinalizationNotifier, so keys can be cleaned up as values are garbage collected. If values are added which do not support this interface, the associated keys will continue to be referenced by this data structure until explicitly removed.

Expiration policy is determined by the JVM's implementation of SoftReference.


Nested Class Summary
static interface SoftHashMap.FinalizationListener
          An interface for Object which accept notification when an another Object is finalized.
static interface SoftHashMap.FinalizationNotifier
          An interface for a Objects which can notify an object when they are finalized.
 
Nested classes inherited from class java.util.Map
Map.Entry
 
Constructor Summary
SoftHashMap()
           
 
Method Summary
 void clear()
           
 boolean containsKey(Object key)
          Returns true if this map contains a mapping for the specified key.
 boolean containsValue(Object value)
          Not Implemented Note that the finalizer may invalidate the result an implementation would return.
 Set entrySet()
          Not Implemented
 Object get(Object key)
           
 boolean isEmpty()
           
 Set keySet()
           
protected  void purgeQueuedKeys()
           
 Object put(Object key, Object value)
          Associates the specified value with the specified key in this map.
protected  void queueKeyForDeletion(Object key)
           
 Object remove(Object key)
           
 int size()
           
 Collection values()
          Not Implemented
 
Methods inherited from class java.util.AbstractMap
clone, equals, hashCode, putAll, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
equals, hashCode, putAll
 

Constructor Detail

SoftHashMap

public SoftHashMap()
Method Detail

clear

public void clear()
Specified by:
clear in interface Map

queueKeyForDeletion

protected void queueKeyForDeletion(Object key)

purgeQueuedKeys

protected void purgeQueuedKeys()

containsKey

public boolean containsKey(Object key)
Returns true if this map contains a mapping for the specified key. Note that this method can return true if the value has been garbage collected, but the key has not been cleared. Additionally, the finalizer may invalidate the result of this operation before a subsequent get() can be issued.

Specified by:
containsKey in interface Map

containsValue

public boolean containsValue(Object value)
                      throws UnsupportedOperationException
Not Implemented Note that the finalizer may invalidate the result an implementation would return.

Specified by:
containsValue in interface Map
Throws:
UnsupportedOperationException

entrySet

public Set entrySet()
             throws UnsupportedOperationException
Not Implemented

Specified by:
entrySet in interface Map
Throws:
UnsupportedOperationException

get

public Object get(Object key)
Specified by:
get in interface Map

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface Map

keySet

public Set keySet()
Specified by:
keySet in interface Map

put

public Object put(Object key,
                  Object value)
Associates the specified value with the specified key in this map. If the map previously contained a mapping for this key, the old value is replaced.

Note: value must implemnt FinalizationNotifier for keys to be freed properly when values are garbage collected.

Specified by:
put in interface Map

remove

public Object remove(Object key)
Specified by:
remove in interface Map

size

public int size()
Specified by:
size in interface Map

values

public Collection values()
                  throws UnsupportedOperationException
Not Implemented

Specified by:
values in interface Map
Throws:
UnsupportedOperationException


Copyright © 2004 The Nutch Organization.