|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.tomp2p.utils.ConcurrentCacheMap<K,V>
K
- the type of the keyV
- the type of the valuepublic class ConcurrentCacheMap<K,V>
A map with expiration and more or less LRU. Since the maps are separated in segments, the LRU is done for each segment. A segment is chosen based on the hash of the key. If one segments is more loaded than another, then an entry of the loaded segment may get evicted before an entry used least recently from an other segment. The expiration is done best effort. There is no thread checking for timed out entries since the cache has a fixed size. Once an entry times out, it remains in the map until it either is accessed or evicted. A test showed that for the default entry size of 1024, this map has a size of 967 if 1024 items are inserted. This is due to the segmentation and hashing.
Nested Class Summary |
---|
Nested classes/interfaces inherited from interface java.util.Map |
---|
Map.Entry<K,V> |
Field Summary | |
---|---|
static int |
DEFAULT_TIME_TO_LIVE
Time to live for a value. |
static int |
MAX_ENTRIES
Max. |
static int |
SEGMENT_NR
Number of segments that can be accessed concurrently |
Constructor Summary | |
---|---|
ConcurrentCacheMap()
Creates a new instance of ConcurrentCacheMap using the supplied values and a CacheMap for the internal
data structure. |
|
ConcurrentCacheMap(int timeToLive,
int maxEntries)
Creates a new instance of ConcurrentCacheMap using the supplied values and a CacheMap for the internal
data structure. |
|
ConcurrentCacheMap(int timeToLive,
int maxEntries,
boolean refreshTimeout)
Creates a new instance of ConcurrentCacheMap using the supplied values and a CacheMap for the internal
data structure. |
Method Summary | |
---|---|
void |
clear()
|
boolean |
containsKey(Object key)
|
boolean |
containsValue(Object value)
|
Set<Map.Entry<K,V>> |
entrySet()
|
int |
expiredCounter()
|
V |
get(Object key)
|
int |
hashCode()
|
boolean |
isEmpty()
|
Set<K> |
keySet()
|
V |
put(K key,
V value)
|
void |
putAll(Map<? extends K,? extends V> inMap)
|
V |
putIfAbsent(K key,
V value)
|
V |
remove(Object key)
|
boolean |
remove(Object key,
Object value)
|
V |
replace(K key,
V value)
|
boolean |
replace(K key,
V oldValue,
V newValue)
|
int |
size()
|
Collection<V> |
values()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface java.util.Map |
---|
equals |
Field Detail |
---|
public static final int SEGMENT_NR
public static final int MAX_ENTRIES
public static final int DEFAULT_TIME_TO_LIVE
Constructor Detail |
---|
public ConcurrentCacheMap()
CacheMap
for the internal
data structure.
public ConcurrentCacheMap(int timeToLive, int maxEntries)
CacheMap
for the internal
data structure.
timeToLive
- The time-to-live value (seconds)maxEntries
- Set the maximum number of entries until items gets replaced with LRUpublic ConcurrentCacheMap(int timeToLive, int maxEntries, boolean refreshTimeout)
CacheMap
for the internal
data structure.
timeToLive
- The time-to-live value (seconds)maxEntries
- The maximum entries to keep in cache, default is 1024refreshTimeout
- If set to true, timeout will be reset in case of putIfAbsent(Object, Object)
Method Detail |
---|
public V put(K key, V value)
put
in interface Map<K,V>
public V putIfAbsent(K key, V value)
putIfAbsent
in interface ConcurrentMap<K,V>
public V get(Object key)
get
in interface Map<K,V>
public V remove(Object key)
remove
in interface Map<K,V>
public boolean remove(Object key, Object value)
remove
in interface ConcurrentMap<K,V>
public boolean containsKey(Object key)
containsKey
in interface Map<K,V>
public boolean containsValue(Object value)
containsValue
in interface Map<K,V>
public int size()
size
in interface Map<K,V>
public boolean isEmpty()
isEmpty
in interface Map<K,V>
public void clear()
clear
in interface Map<K,V>
public int hashCode()
hashCode
in interface Map<K,V>
hashCode
in class Object
public Set<K> keySet()
keySet
in interface Map<K,V>
public void putAll(Map<? extends K,? extends V> inMap)
putAll
in interface Map<K,V>
public Collection<V> values()
values
in interface Map<K,V>
public Set<Map.Entry<K,V>> entrySet()
entrySet
in interface Map<K,V>
public boolean replace(K key, V oldValue, V newValue)
replace
in interface ConcurrentMap<K,V>
public V replace(K key, V value)
replace
in interface ConcurrentMap<K,V>
public int expiredCounter()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |