|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.terracotta.cache.TerracottaDistributedCache<K,V>
K - key typeV - value typepublic class TerracottaDistributedCache<K,V>
A clusterable cache implementation.
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from interface java.util.Map |
|---|
Map.Entry<K,V> |
| Field Summary | |
|---|---|
protected ClusteredMap<K,TimestampedValue<V>> |
data
|
| Constructor Summary | |
|---|---|
|
TerracottaDistributedCache(CacheConfig config)
|
protected |
TerracottaDistributedCache(CacheConfig config,
ClusteredMap<K,TimestampedValue<V>> terracottaMap)
|
| Method Summary | |
|---|---|
void |
clear()
|
void |
clearLocalCache()
Clears the local cache |
void |
clearWithCallback(MutationCallback<K,TimestampedValue<V>> callback)
|
boolean |
containsKey(Object key)
|
boolean |
containsKeyLocalOffHeap(Object key)
|
boolean |
containsKeyLocalOnHeap(Object key)
|
boolean |
containsLocalKey(K key)
|
boolean |
containsValue(Object value)
|
ClusteredLock |
createFinegrainedLock(K key)
Obtain a fine-grained lock instance for a particular key. |
void |
destroyLocalCache()
|
Set<Map.Entry<K,V>> |
entrySet()
|
void |
evicted(Object key,
Object value)
Method called when elements are evicted. |
void |
evictExpiredLocalElements()
Trigger to walk through the local elements, look for expired elements, and evict them. |
void |
evictOrphanElements(ClusterInfo clusterInfo)
Trigger to walk through the specified set of orphaned elements, check whether they have expired, and evict them from the store. |
V |
get(Object key)
|
CacheConfig |
getConfig()
Get the current config for the cache. |
protected MutationCallback<K,TimestampedValue<V>> |
getEvictRemoveCallback()
|
Map<K,Set<ClusterNode>> |
getNodesWithKeys(Collection<? extends K> keys)
|
EvictionStatistics |
getStatistics()
Retrieve the statistics for the current JVM. |
TimeSource |
getTimeSource()
Return the time source used by this cache to generate entry timestamps. |
TimestampedValue<V> |
getTimestampedValue(K key)
Get the value wrapped in a timestamped object. |
TimestampedValue<V> |
getTimestampedValueQuiet(K key)
Get the value wrapped in a timestamped object without updating the last usage statistics. |
Map<K,TimestampedValue<V>> |
getTimestampedValues(Set<K> keys,
boolean quiet)
|
void |
initializeLocalCache()
|
void |
initializeOnLoad()
Terracotta |
protected void |
initializeOnLoad(boolean startEviction)
|
protected void |
invalidateCacheEntries(Iterator<K> keys)
|
protected boolean |
isCapacityEvictionEnabled()
|
boolean |
isEmpty()
|
protected boolean |
isEvictionEnabled()
|
boolean |
isPinned(Object key)
|
boolean |
isStatisticsEnabled()
Returns whether statistics are enabled. |
Set<K> |
keySet()
|
Set<K> |
localKeySet()
|
int |
localOffHeapSize()
|
long |
localOffHeapSizeInBytes()
|
int |
localOnHeapSize()
|
long |
localOnHeapSizeInBytes()
|
int |
localSize()
Get the number of elements local in the current node. |
void |
lockEntry(K key)
Lock the entry corresponding to this key. |
void |
markUsed(K key,
Object entry,
int now)
|
protected void |
onEvict(K key,
TimestampedValue<V> entry)
Used to notify listeners of eviction. |
protected void |
onExpiry(K key,
TimestampedValue<V> entry)
Used to notify listeners of expiry. |
V |
put(K key,
V value)
|
void |
putAll(Map<? extends K,? extends V> t)
|
V |
putIfAbsent(K key,
V value)
|
void |
putNoReturn(K key,
V value)
Put the key/value into the map, replacing the existing value if present. |
void |
putNoReturnWithCallback(K key,
V value,
MutationCallback<K,TimestampedValue<V>> callback)
|
void |
recalculateLocalCacheSize(Object key)
|
V |
remove(Object key)
|
boolean |
remove(Object key,
Object value)
|
void |
removeNoReturn(Object key)
Remove the key from the map, if it exists. |
void |
removeNoReturnWithCallback(K key,
MutationCallback<K,TimestampedValue<V>> callback)
|
TimestampedValue<V> |
removeTimestampedValue(K key)
Remove the timestamped value for the given key. |
TimestampedValue<V> |
removeTimestampedValueWithCallback(K key,
MutationCallback<K,TimestampedValue<V>> callback)
|
V |
replace(K key,
V value)
|
boolean |
replace(K key,
V oldValue,
V newValue)
|
void |
setLocalCacheEnabled(boolean enabled)
|
void |
setMaxBytesLocalHeap(long maxBytesLocalHeap)
|
void |
setMaxEntriesLocalHeap(int maxEntriesLocalHeap)
|
void |
setMaxTTI(int maxTTI)
|
void |
setMaxTTL(int maxTTL)
|
void |
setPinned(Object key,
boolean pinned)
|
void |
setStatisticsEnabled(boolean enabled)
Toggle statistics being enabled or not. |
void |
setTargetMaxTotalCount(int targetMaxTotalCount)
|
void |
setTimeSource(TimeSource timeSource)
This is provided for testing purposes - it lets you override the source of System.currentTimeMillis() so that you can control it yourself in the test. |
void |
shutdown()
Shut down the background eviction thread, if any. |
int |
size()
|
boolean |
unlockedContainsKey(Object key)
Same as Map.containsKey(Object) except this operation is performed without any locking |
V |
unlockedGet(K key,
boolean quiet)
Same as Map.get(Object) except this operation is performed without any locking |
Map<K,TimestampedValue<V>> |
unlockedGetAllTimestampedValue(Set<K> keys,
boolean quiet)
|
TimestampedValue<V> |
unlockedGetTimestampedValue(K key,
boolean quiet)
Same as IncoherentDistributedCache#unlockedGet(Object) except returns the TimestampedValue instead
of the original value |
void |
unlockedPutIfAbsentNoReturn(K key,
V value)
Same as ConcurrentMap.putIfAbsent(Object, Object) except this operation is performed without any locking
and the is performed only when a current mapping exists and is equal to currentValue |
void |
unlockedPutIfAbsentNoReturnWithCallback(K key,
V value,
MutationCallback<K,TimestampedValue<V>> callback)
|
void |
unlockedPutNoReturn(K key,
V value)
Same as DistributedCache.putNoReturn(Object, Object) except that this operation is performed without any
locking. |
void |
unlockedPutNoReturnWithCallback(K key,
V value,
MutationCallback<K,TimestampedValue<V>> callback)
|
void |
unlockedRemoveNoReturn(K key,
V currentValue)
Same as DistributedCache.removeNoReturn(Object) except this operation is performed without any locking and
the remove is performed only when a current mapping exists and is equal to currentValue |
void |
unlockedRemoveNoReturn(Object key)
Same as DistributedCache.removeNoReturn(Object) except this operation is performed without any locking |
void |
unlockedRemoveNoReturnWithCallback(K key,
MutationCallback<K,TimestampedValue<V>> callback)
|
void |
unlockedRemoveNoReturnWithCallback(K key,
V currentValue,
MutationCallback<K,TimestampedValue<V>> callback)
|
void |
unlockedReplaceNoReturn(K key,
V currentValue,
V newValue)
Same as DistributedCache.putNoReturn(Object, Object) except that this operation is performed without any
locking and puts in the cache only if there is already a mapping for key that is equal to currentValue |
void |
unlockedReplaceNoReturnWithCallback(K key,
V currentValue,
V newValue,
MutationCallback<K,TimestampedValue<V>> callback)
|
void |
unlockEntry(K key)
Unlock the entry corresponding to this key |
void |
unpinAll()
|
V |
unsafeGet(K key,
boolean quiet)
Returns the local value present for the key if present in the VM, otherwise returns null. |
TimestampedValue<V> |
unsafeGetTimestampedValue(K key,
boolean quiet)
Same as IncoherentDistributedCache.unsafeGet(Object, boolean) except returns the TimestampedValue
instead of the original value |
Collection<V> |
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 |
| Field Detail |
|---|
protected final ClusteredMap<K,TimestampedValue<V>> data
| Constructor Detail |
|---|
public TerracottaDistributedCache(CacheConfig config)
protected TerracottaDistributedCache(CacheConfig config,
ClusteredMap<K,TimestampedValue<V>> terracottaMap)
| Method Detail |
|---|
public void initializeOnLoad()
protected void initializeOnLoad(boolean startEviction)
public boolean containsKey(Object key)
containsKey in interface Map<K,V>public V get(Object key)
get in interface Map<K,V>public TimestampedValue<V> getTimestampedValue(K key)
DistributedCacheThis value is used entirely for maintaining the creation and last accessed time for TTI and TTL eviction.
getTimestampedValue in interface DistributedCache<K,V>key - The key to search for
public TimestampedValue<V> getTimestampedValueQuiet(K key)
DistributedCache
getTimestampedValueQuiet in interface DistributedCache<K,V>key - The key to search for
DistributedCache.getTimestampedValue(Object)
public Map<K,TimestampedValue<V>> getTimestampedValues(Set<K> keys,
boolean quiet)
public TimestampedValue<V> removeTimestampedValue(K key)
DistributedCachePrevious values will be returned as null if they are expired.
removeTimestampedValue in interface DistributedCache<K,V>key - The key to search for
public TimestampedValue<V> removeTimestampedValueWithCallback(K key,
MutationCallback<K,TimestampedValue<V>> callback)
public Set<K> keySet()
keySet in interface Map<K,V>public Set<K> localKeySet()
public boolean containsLocalKey(K key)
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 remove(Object key)
remove in interface Map<K,V>
public V replace(K key,
V value)
replace in interface ConcurrentMap<K,V>public void clear()
clear in interface Map<K,V>public void clearLocalCache()
LocallyCacheable
clearLocalCache in interface LocallyCacheablepublic void unpinAll()
public boolean isPinned(Object key)
public void setPinned(Object key,
boolean pinned)
public int size()
size in interface Map<K,V>public int localSize()
DistributedCacheThis number should always be less than size(), and is likely to be different as all cache entries are not required to be stored in the local heap.
localSize in interface DistributedCache<K,V>public void shutdown()
DistributedCache
shutdown in interface DistributedCache<K,V>public void evictExpiredLocalElements()
Evictable
evictExpiredLocalElements in interface Evictable<K>public void evictOrphanElements(ClusterInfo clusterInfo)
Evictable
evictOrphanElements in interface Evictable<K>clusterInfo - The Terracotta cluster info which can be used to obtain the orphaned element listprotected void invalidateCacheEntries(Iterator<K> keys)
protected MutationCallback<K,TimestampedValue<V>> getEvictRemoveCallback()
public void evicted(Object key,
Object value)
CacheEvictionListener
evicted in interface CacheEvictionListener
protected void onEvict(K key,
TimestampedValue<V> entry)
By the time this function is called, the item has already been evicted
protected void onExpiry(K key,
TimestampedValue<V> entry)
By the time this function is called, the item has already been expired
public void setTimeSource(TimeSource timeSource)
timeSource - The alternate TimeSource implementationpublic TimeSource getTimeSource()
public Set<Map.Entry<K,V>> entrySet()
entrySet in interface Map<K,V>
public void putNoReturn(K key,
V value)
DistributedCacheThis method differs from the normal put() method only in that it returns void instead of the prior value. This is important in the cluster as it avoids faulting that value to return when it is rarely used.
putNoReturn in interface DistributedCache<K,V>key - Keyvalue - Value
public void unlockedPutNoReturn(K key,
V value)
IncoherentDistributedCacheDistributedCache.putNoReturn(Object, Object) except that this operation is performed without any
locking.
unlockedPutNoReturn in interface IncoherentDistributedCache<K,V>
public void unlockedPutNoReturnWithCallback(K key,
V value,
MutationCallback<K,TimestampedValue<V>> callback)
public void unlockedReplaceNoReturn(K key,
V currentValue,
V newValue)
IncoherentDistributedCacheInternalsDistributedCache.putNoReturn(Object, Object) except that this operation is performed without any
locking and puts in the cache only if there is already a mapping for key that is equal to currentValue
unlockedReplaceNoReturn in interface IncoherentDistributedCacheInternals<K,V>
public void unlockedReplaceNoReturnWithCallback(K key,
V currentValue,
V newValue,
MutationCallback<K,TimestampedValue<V>> callback)
public void unlockedRemoveNoReturn(K key,
V currentValue)
IncoherentDistributedCacheInternalsDistributedCache.removeNoReturn(Object) except this operation is performed without any locking and
the remove is performed only when a current mapping exists and is equal to currentValue
unlockedRemoveNoReturn in interface IncoherentDistributedCacheInternals<K,V>
public void unlockedRemoveNoReturnWithCallback(K key,
V currentValue,
MutationCallback<K,TimestampedValue<V>> callback)
public void unlockedPutIfAbsentNoReturn(K key,
V value)
IncoherentDistributedCacheInternalsConcurrentMap.putIfAbsent(Object, Object) except this operation is performed without any locking
and the is performed only when a current mapping exists and is equal to currentValue
unlockedPutIfAbsentNoReturn in interface IncoherentDistributedCacheInternals<K,V>
public void unlockedPutIfAbsentNoReturnWithCallback(K key,
V value,
MutationCallback<K,TimestampedValue<V>> callback)
public V unsafeGet(K key,
boolean quiet)
IncoherentDistributedCacheIf the value is not present in the local VM, it WILL NOT fault in the value from the server even when it is present on the server and will return null instead
Note: If quiet is true, it may return expired entries
unsafeGet in interface IncoherentDistributedCache<K,V>key - key to lookupquiet - if true, does not update last access time and skips checking for expired entries otherwise updates
last access time and also checks for expired entries
public TimestampedValue<V> unsafeGetTimestampedValue(K key,
boolean quiet)
IncoherentDistributedCacheIncoherentDistributedCache.unsafeGet(Object, boolean) except returns the TimestampedValue
instead of the original value
unsafeGetTimestampedValue in interface IncoherentDistributedCache<K,V>
public V unlockedGet(K key,
boolean quiet)
IncoherentDistributedCacheMap.get(Object) except this operation is performed without any locking
This operation may fault in the value from the server if it is not present in the VM locally but present in the server
unlockedGet in interface IncoherentDistributedCache<K,V>
public TimestampedValue<V> unlockedGetTimestampedValue(K key,
boolean quiet)
IncoherentDistributedCacheIncoherentDistributedCache#unlockedGet(Object) except returns the TimestampedValue instead
of the original value
unlockedGetTimestampedValue in interface IncoherentDistributedCache<K,V>
public Map<K,TimestampedValue<V>> unlockedGetAllTimestampedValue(Set<K> keys,
boolean quiet)
public boolean unlockedContainsKey(Object key)
IncoherentDistributedCacheMap.containsKey(Object) except this operation is performed without any locking
unlockedContainsKey in interface IncoherentDistributedCache<K,V>public void removeNoReturn(Object key)
DistributedCacheThis method differs from the normal remove() method only in that it returns void instead of the prior value. This is important in the cluster as it avoids faulting that value to return it when it is rarely used.
removeNoReturn in interface DistributedCache<K,V>key - Key
public void removeNoReturnWithCallback(K key,
MutationCallback<K,TimestampedValue<V>> callback)
public void unlockedRemoveNoReturn(Object key)
IncoherentDistributedCacheDistributedCache.removeNoReturn(Object) except this operation is performed without any locking
unlockedRemoveNoReturn in interface IncoherentDistributedCache<K,V>
public void unlockedRemoveNoReturnWithCallback(K key,
MutationCallback<K,TimestampedValue<V>> callback)
public boolean isStatisticsEnabled()
Evictable
isStatisticsEnabled in interface Evictable<K>true when statistics are enabled; and false otherwisepublic void setStatisticsEnabled(boolean enabled)
Evictable
setStatisticsEnabled in interface Evictable<K>enabled - true to enable statistics; and false to disable thempublic EvictionStatistics getStatistics()
Evictable
getStatistics in interface Evictable<K>public CacheConfig getConfig()
DistributedCacheThis may or may not be the same config object as was orignally supplied to the cache.
getConfig in interface DistributedCache<K,V>protected boolean isEvictionEnabled()
protected boolean isCapacityEvictionEnabled()
public boolean remove(Object key,
Object value)
remove in interface ConcurrentMap<K,V>
public boolean replace(K key,
V oldValue,
V newValue)
replace in interface ConcurrentMap<K,V>public Map<K,Set<ClusterNode>> getNodesWithKeys(Collection<? extends K> keys)
public boolean containsValue(Object value)
containsValue in interface Map<K,V>public boolean isEmpty()
isEmpty in interface Map<K,V>public void putAll(Map<? extends K,? extends V> t)
putAll in interface Map<K,V>public Collection<V> values()
values in interface Map<K,V>public ClusteredLock createFinegrainedLock(K key)
LockableMap
createFinegrainedLock in interface LockableMap<K>key - the key for which a fine-grained lock has to be constructed
public void lockEntry(K key)
LockableMap
lockEntry in interface LockableMap<K>key - the key for which all entry accesses have to be lockedpublic void unlockEntry(K key)
LockableMap
unlockEntry in interface LockableMap<K>key - the key for which all entry accesses have to be unlocked
public void putNoReturnWithCallback(K key,
V value,
MutationCallback<K,TimestampedValue<V>> callback)
public void clearWithCallback(MutationCallback<K,TimestampedValue<V>> callback)
public long localOnHeapSizeInBytes()
localOnHeapSizeInBytes in interface com.terracotta.toolkit.collections.InternalLocallyCacheablepublic long localOffHeapSizeInBytes()
localOffHeapSizeInBytes in interface com.terracotta.toolkit.collections.InternalLocallyCacheablepublic int localOnHeapSize()
localOnHeapSize in interface com.terracotta.toolkit.collections.InternalLocallyCacheablepublic int localOffHeapSize()
localOffHeapSize in interface com.terracotta.toolkit.collections.InternalLocallyCacheablepublic void initializeLocalCache()
initializeLocalCache in interface com.terracotta.toolkit.collections.InternalLocallyCacheablepublic void destroyLocalCache()
destroyLocalCache in interface com.terracotta.toolkit.collections.InternalLocallyCacheablepublic boolean containsKeyLocalOnHeap(Object key)
containsKeyLocalOnHeap in interface com.terracotta.toolkit.collections.InternalLocallyCacheablepublic boolean containsKeyLocalOffHeap(Object key)
containsKeyLocalOffHeap in interface com.terracotta.toolkit.collections.InternalLocallyCacheablepublic void setTargetMaxTotalCount(int targetMaxTotalCount)
public void setMaxTTI(int maxTTI)
public void setMaxTTL(int maxTTL)
public void setMaxEntriesLocalHeap(int maxEntriesLocalHeap)
setMaxEntriesLocalHeap in interface com.terracotta.toolkit.collections.InternalLocallyCacheablepublic void setMaxBytesLocalHeap(long maxBytesLocalHeap)
setMaxBytesLocalHeap in interface com.terracotta.toolkit.collections.InternalLocallyCacheablepublic void setLocalCacheEnabled(boolean enabled)
setLocalCacheEnabled in interface com.terracotta.toolkit.collections.InternalLocallyCacheablepublic void recalculateLocalCacheSize(Object key)
recalculateLocalCacheSize in interface com.terracotta.toolkit.collections.InternalLocallyCacheable
public void markUsed(K key,
Object entry,
int now)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||