org.castor.cache.hashbelt.container
Class WeakReferenceContainer

java.lang.Object
  extended byorg.castor.cache.hashbelt.container.WeakReferenceContainer
All Implemented Interfaces:
Container, java.util.Map

public final class WeakReferenceContainer
extends java.lang.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: 6907 $ $Date: 2006-04-25 16:09:10 -0600 (Tue, 25 Apr 2006) $
Author:
Gregory Block, Ralf Joachim

Nested Class Summary
 
Nested classes inherited from class java.util.Map
java.util.Map.Entry
 
Constructor Summary
WeakReferenceContainer()
           
 
Method Summary
 void clear()
          
 boolean containsKey(java.lang.Object key)
          
 boolean containsValue(java.lang.Object value)
          
 java.util.Set entrySet()
          
 java.lang.Object get(java.lang.Object key)
          
 long getTimestamp()
          Returns the timestamp of this container.
 boolean isEmpty()
          
 java.util.Iterator 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.
 java.util.Set keySet()
          
 java.lang.Object put(java.lang.Object key, java.lang.Object value)
          
 void putAll(java.util.Map map)
          
 java.lang.Object remove(java.lang.Object key)
          
 int size()
          
 void updateTimestamp()
          Set the timestamp of this container to System.currentTimeMillis().
 java.util.Iterator 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.
 java.util.Collection 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
See Also:
Container.updateTimestamp()

getTimestamp

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

Specified by:
getTimestamp in interface Container
Returns:
The timestamp.
See Also:
Container.getTimestamp()

keyIterator

public java.util.Iterator 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.
See Also:
Container.keyIterator()

valueIterator

public java.util.Iterator 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.
See Also:
Container.valueIterator()

size

public int size()

Specified by:
size in interface java.util.Map
See Also:
Map.size()

isEmpty

public boolean isEmpty()

Specified by:
isEmpty in interface java.util.Map
See Also:
Map.isEmpty()

containsKey

public boolean containsKey(java.lang.Object key)

Specified by:
containsKey in interface java.util.Map
See Also:
Map.containsKey(java.lang.Object)

containsValue

public boolean containsValue(java.lang.Object value)

Specified by:
containsValue in interface java.util.Map
See Also:
Map.containsValue(java.lang.Object)

get

public java.lang.Object get(java.lang.Object key)

Specified by:
get in interface java.util.Map
See Also:
Map.get(java.lang.Object)

put

public java.lang.Object put(java.lang.Object key,
                            java.lang.Object value)

Specified by:
put in interface java.util.Map
See Also:
Map.put(java.lang.Object, java.lang.Object)

remove

public java.lang.Object remove(java.lang.Object key)

Specified by:
remove in interface java.util.Map
See Also:
Map.remove(java.lang.Object)

putAll

public void putAll(java.util.Map map)

Specified by:
putAll in interface java.util.Map
See Also:
Map.putAll(java.util.Map)

clear

public void clear()

Specified by:
clear in interface java.util.Map
See Also:
Map.clear()

keySet

public java.util.Set keySet()

Specified by:
keySet in interface java.util.Map
See Also:
Map.keySet()

values

public java.util.Collection values()

Specified by:
values in interface java.util.Map
See Also:
Map.values()

entrySet

public java.util.Set entrySet()

Specified by:
entrySet in interface java.util.Map
See Also:
Map.entrySet()


Copyright 2008 null. All Rights Reserved.