Class WeakReferenceContainer
java.lang.Object
org.castor.cache.hashbelt.container.WeakReferenceContainer
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
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()booleancontainsKey(Object key) booleancontainsValue(Object value) entrySet()longReturns the timestamp of this container.booleanisEmpty()Returns an iterator over the keys contained in this container.keySet()voidintsize()voidSet the timestamp of this container to System.currentTimeMillis().Returns an iterator over the values contained in this container.values()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, equals, forEach, getOrDefault, hashCode, merge, putIfAbsent, remove, replace, replace, replaceAll
-
Constructor Details
-
WeakReferenceContainer
public WeakReferenceContainer()
-
-
Method Details
-
updateTimestamp
public void updateTimestamp()Set the timestamp of this container to System.currentTimeMillis().- Specified by:
updateTimestampin interfaceContainer
-
getTimestamp
public long getTimestamp()Returns the timestamp of this container.- Specified by:
getTimestampin interfaceContainer- Returns:
- The timestamp.
-
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:
keyIteratorin interfaceContainer- Returns:
- An iterator over the keys currently contained in the container.
-
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:
valueIteratorin interfaceContainer- Returns:
- An iterator over the values currently contained in the container.
-
size
public int size() -
isEmpty
public boolean isEmpty() -
containsKey
- Specified by:
containsKeyin interfaceMap<Object,Object>
-
containsValue
- Specified by:
containsValuein interfaceMap<Object,Object>
-
get
-
put
-
remove
-
putAll
-
clear
public void clear() -
keySet
-
values
-
entrySet
-