static class BucketCache.RAMCache extends Object
Modifier and Type | Field and Description |
---|---|
(package private) ConcurrentHashMap<BlockCacheKey,BucketCache.RAMQueueEntry> |
delegate
Defined the map as
ConcurrentHashMap explicitly here, because in
get(BlockCacheKey) and
putIfAbsent(BlockCacheKey, BucketCache.RAMQueueEntry) , we need to guarantee
the atomicity of map#computeIfPresent(key, func) and map#putIfAbsent(key, func). |
Constructor and Description |
---|
RAMCache() |
Modifier and Type | Method and Description |
---|---|
void |
clear() |
boolean |
containsKey(BlockCacheKey key) |
BucketCache.RAMQueueEntry |
get(BlockCacheKey key) |
boolean |
isEmpty() |
BucketCache.RAMQueueEntry |
putIfAbsent(BlockCacheKey key,
BucketCache.RAMQueueEntry entry)
Return the previous associated value, or null if absent.
|
boolean |
remove(BlockCacheKey key) |
boolean |
remove(BlockCacheKey key,
Consumer<BucketCache.RAMQueueEntry> action)
Defined an
Consumer here, because once the removed entry release its reference count,
then it's ByteBuffers may be recycled and accessing it outside this method will be thrown an
exception. |
final ConcurrentHashMap<BlockCacheKey,BucketCache.RAMQueueEntry> delegate
ConcurrentHashMap
explicitly here, because in
get(BlockCacheKey)
and
putIfAbsent(BlockCacheKey, BucketCache.RAMQueueEntry)
, we need to guarantee
the atomicity of map#computeIfPresent(key, func) and map#putIfAbsent(key, func). Besides, the
func method can execute exactly once only when the key is present(or absent) and under the
lock context. Otherwise, the reference count of block will be messed up. Notice that the
ConcurrentSkipListMap
can not guarantee that.RAMCache()
public boolean containsKey(BlockCacheKey key)
public BucketCache.RAMQueueEntry get(BlockCacheKey key)
public BucketCache.RAMQueueEntry putIfAbsent(BlockCacheKey key, BucketCache.RAMQueueEntry entry)
ConcurrentMap.putIfAbsent(Object, Object)
public boolean remove(BlockCacheKey key)
public boolean remove(BlockCacheKey key, Consumer<BucketCache.RAMQueueEntry> action)
Consumer
here, because once the removed entry release its reference count,
then it's ByteBuffers may be recycled and accessing it outside this method will be thrown an
exception. the consumer will access entry to remove before release its reference count.
Notice, don't change its reference count in the Consumer
public boolean isEmpty()
public void clear()
Copyright © 2007–2020 The Apache Software Foundation. All rights reserved.