org.castor.cache.hashbelt.container
Class WeakReferenceContainer

java.lang.Object
  extended by org.castor.cache.hashbelt.container.WeakReferenceContainer
All Implemented Interfaces:
Map<Object,Object>, Container

public final class WeakReferenceContainer
extends Object
implements Container

An implementation of a container that uses weak references for storing values in the map, so that values can be removed from the map by the system when the system is under memory pressure. Keys, however, are kept strong - so contains() may well find an element, but the value may have been lost. Make sure you test for null returns from put.

Note that keys are hard references; in a situation where OutOfMemory will occur, the JVM will first wipe out all unreferenced objects whose only link is a weak reference. An out of memory will wipe all values from the maps which are currently unreferenced. The keys remain until the hashbelt containers are garbage collected, an put is called with that key or when the value should be accessed through any operation of the Container interface.

Since:
1.0
Version:
$Revision: 8102 $ $Date: 2006-04-25 16:09:10 -0600 (Tue, 25 Apr 2006) $
Author:
Gregory Block, Ralf Joachim

Nested Class Summary
 
Nested classes/interfaces inherited from interface java.util.Map
Map.Entry<K,V>
 
Constructor Summary
WeakReferenceContainer()
           
 
Method Summary
 void clear()
          
 boolean containsKey(Object key)
          
 boolean containsValue(Object value)
          
 Set<Map.Entry<Object,Object>> entrySet()
          
 Object get(Object key)
          
 long getTimestamp()
          Returns the timestamp of this container.
 boolean isEmpty()
          
 Iterator<Object> keyIterator()
          Returns an iterator over the keys contained in this container.
 Set<Object> keySet()
          
 Object put(Object key, Object value)
          
 void putAll(Map<? extends Object,? extends Object> map)
          
 Object remove(Object key)
          
 int size()
          
 void updateTimestamp()
          Set the timestamp of this container to System.currentTimeMillis().
 Iterator<Object> valueIterator()
          Returns an iterator over the values contained in this container.
 Collection<Object> 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
 

Constructor Detail

WeakReferenceContainer

public WeakReferenceContainer()
Method Detail

updateTimestamp

public void updateTimestamp()
Set the timestamp of this container to System.currentTimeMillis().

Specified by:
updateTimestamp in interface Container

getTimestamp

public long getTimestamp()
Returns the timestamp of this container.

Specified by:
getTimestamp in interface Container
Returns:
The timestamp.

keyIterator

public Iterator<Object> keyIterator()
Returns an iterator over the keys contained in this container. If the container is modified while an iteration is in progress, the results of the iteration is not affected and vice-versa.

Specified by:
keyIterator in interface Container
Returns:
An iterator over the keys currently contained in the container.

valueIterator

public Iterator<Object> valueIterator()
Returns an iterator over the values contained in this container. If the container is modified while an iteration is in progress, the results of the iteration is not affected and vice-versa.

Specified by:
valueIterator in interface Container
Returns:
An iterator over the values currently contained in the container.

size

public int size()

Specified by:
size in interface Map<Object,Object>

isEmpty

public boolean isEmpty()

Specified by:
isEmpty in interface Map<Object,Object>

containsKey

public boolean containsKey(Object key)

Specified by:
containsKey in interface Map<Object,Object>

containsValue

public boolean containsValue(Object value)

Specified by:
containsValue in interface Map<Object,Object>

get

public Object get(Object key)

Specified by:
get in interface Map<Object,Object>

put

public Object put(Object key,
                  Object value)

Specified by:
put in interface Map<Object,Object>

remove

public Object remove(Object key)

Specified by:
remove in interface Map<Object,Object>

putAll

public void putAll(Map<? extends Object,? extends Object> map)

Specified by:
putAll in interface Map<Object,Object>

clear

public void clear()

Specified by:
clear in interface Map<Object,Object>

keySet

public Set<Object> keySet()

Specified by:
keySet in interface Map<Object,Object>

values

public Collection<Object> values()

Specified by:
values in interface Map<Object,Object>

entrySet

public Set<Map.Entry<Object,Object>> entrySet()

Specified by:
entrySet in interface Map<Object,Object>


Copyright © 2010. All Rights Reserved.