|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.hd.d.pg2k.svrCore.collections.SoftReferenceMap<K,V>
public final class SoftReferenceMap<K,V>
Soft cache as highly-threadable (thread-safe) Map which holds each value via a SoftReference and discards mapping when the values are GCed. Similar to a WeakHashMap in its automatic trimming of expired values, and in that presence in this map does not prevent the values being GCed.
When values are GCed they will appear to vanish from the map asynchronously.
It is possible to safely iterate over the content with an iterator over the keySet
which will return elements reflecting the state of the keys in the Map
at some point at or since the creation of the iterator.
It does not throw ConcurrentModificationException.
However, iterators are designed to be used by only one thread at a time.
Permits neither null keys nor null values.
Not all operations (ie on the value or entry sets) are be supported.
| Nested Class Summary | |
|---|---|
private static class |
SoftReferenceMap.SRCMSoftReference<K,V>
Enqueueable SoftReference for SoftReferenceConcurrentMap. |
| Nested classes/interfaces inherited from interface java.util.Map |
|---|
java.util.Map.Entry<K,V> |
| Field Summary | |
|---|---|
private java.lang.ref.ReferenceQueue<V> |
_deadRefQueue
Queue of dead SoftReference entries; never null. |
private boolean |
clearWhenStressed
True iff we clear() on memory stress during compact(). |
private java.util.concurrent.ConcurrentMap<K,SoftReferenceMap.SRCMSoftReference<K,V>> |
m
The internal map; never null. |
private java.lang.String |
name
Optional name for diagnostics; can be null. |
| Constructor Summary | |
|---|---|
private |
SoftReferenceMap(int capacity,
boolean clearWhenStressed,
java.lang.String name)
Create an empty map with the specified initial capacity. |
private |
SoftReferenceMap(java.lang.String name)
Create an empty map with default characteristics. |
| Method Summary | ||
|---|---|---|
private void |
_clearDeadEntries()
Expunges any dead entries. |
|
void |
clear()
Clear the map. |
|
void |
compact()
Compacts the representation of this collection if possible. |
|
boolean |
containsKey(java.lang.Object key)
|
|
boolean |
containsValue(java.lang.Object value)
|
|
static
|
create(int capacity,
boolean clearWhenStressed,
java.lang.String name)
Create an empty map with the specified initial capacity. |
|
static
|
create(java.lang.String name)
Create an empty map with default characteristics. |
|
java.util.Set<java.util.Map.Entry<K,V>> |
entrySet()
|
|
V |
get(java.lang.Object key)
Get an entry from the map; null if no such element. |
|
java.lang.String |
getCompactableInstanceName()
Get name of this Compactable instance for tracking purposes, or null if none. |
|
boolean |
isEmpty()
True if the map is non-empty. |
|
java.util.Set<K> |
keySet()
|
|
V |
put(K key,
V value)
Put an entry in the map, returning previous value if any. |
|
void |
putAll(java.util.Map<? extends K,? extends V> newValues)
|
|
V |
remove(java.lang.Object key)
Remove an entry from the map and return the removed value, if any, else null. |
|
int |
size()
Return the number of entries in the map; non-negative. |
|
java.lang.String |
toString()
Provide a human-readable summary of status. |
|
java.util.Collection<V> |
values()
|
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface java.util.Map |
|---|
equals, hashCode |
| Field Detail |
|---|
private final java.util.concurrent.ConcurrentMap<K,SoftReferenceMap.SRCMSoftReference<K,V>> m
private final java.lang.ref.ReferenceQueue<V> _deadRefQueue
private final boolean clearWhenStressed
private final java.lang.String name
| Constructor Detail |
|---|
private SoftReferenceMap(java.lang.String name)
name - name of this instance for tracking purposes or null if none
private SoftReferenceMap(int capacity,
boolean clearWhenStressed,
java.lang.String name)
capacity - initial capacity; strictly positiveclearWhenStressed - if true then empty the map on compact() if memory system is stressedname - name of this instance for tracking purposes or null if none| Method Detail |
|---|
public java.lang.String getCompactableInstanceName()
getCompactableInstanceName in interface MemoryTools.Compactablepublic void compact()
compact in interface MemoryTools.Compactablepublic java.lang.String toString()
toString in class java.lang.Objectprivate void _clearDeadEntries()
This should be called from enough places and/or otherwise often enough to remove expired entries in a timely manner.
public static <K,V> SoftReferenceMap<K,V> create(java.lang.String name)
name - name of this instance for tracking purposes or null if none
public static <K,V> SoftReferenceMap<K,V> create(int capacity,
boolean clearWhenStressed,
java.lang.String name)
capacity - initial capacity; strictly positiveclearWhenStressed - if true then empty the map on compact() if memory system is stressedname - name of this instance for tracking purposes or null if nonepublic void clear()
MemoryTools.CacheMiniMap
clear in interface java.util.Map<K,V>clear in interface MemoryTools.CacheMiniMap<K,V>public boolean containsKey(java.lang.Object key)
containsKey in interface java.util.Map<K,V>public int size()
MemoryTools.CacheMiniMap
size in interface java.util.Map<K,V>size in interface MemoryTools.CacheMiniMap<K,V>public boolean isEmpty()
MemoryTools.CacheMiniMap
isEmpty in interface java.util.Map<K,V>isEmpty in interface MemoryTools.CacheMiniMap<K,V>public java.util.Set<K> keySet()
keySet in interface java.util.Map<K,V>public V get(java.lang.Object key)
MemoryTools.CacheMiniMap
get in interface java.util.Map<K,V>get in interface MemoryTools.CacheMiniMap<K,V>
public V put(K key,
V value)
MemoryTools.CacheMiniMap
put in interface java.util.Map<K,V>put in interface MemoryTools.CacheMiniMap<K,V>public void putAll(java.util.Map<? extends K,? extends V> newValues)
putAll in interface java.util.Map<K,V>public V remove(java.lang.Object key)
MemoryTools.CacheMiniMap
remove in interface java.util.Map<K,V>remove in interface MemoryTools.CacheMiniMap<K,V>public boolean containsValue(java.lang.Object value)
containsValue in interface java.util.Map<K,V>public java.util.Collection<V> values()
values in interface java.util.Map<K,V>public java.util.Set<java.util.Map.Entry<K,V>> entrySet()
entrySet in interface java.util.Map<K,V>
|
DHD Multimedia Gallery V1.60.69 | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||