public V put(final K key, final V value) { return getValueSafe(filterExpired(this.data.put(key, wrapValue(value)))); }
private TimestampedValue<V> getNonExpiredEntryCoherent(K key, boolean markUsed) { return getNonExpiredEntry(key, markUsed, GetType.COHERENT); }
public V get(final Object key) { return getValueSafe(getNonExpiredEntryCoherent((K) key, true)); }
public V unlockedGet(final K key, final boolean quiet) { return getValueSafe(getNonExpiredEntryUnlocked(key, !quiet)); }
public V unsafeGet(final K key, final boolean quiet) { return getValueSafe(getNonExpiredEntryUnsafe(key, !quiet)); }
if (isEvictionEnabled() || isCapacityEvictionEnabled()) { final int now = getTime(); ClusteredLock lock = createFinegrainedLock(key); if (entry.isExpired(now, config)) { if (!lock.isHeldByCurrentThread(LockType.READ)) { expire(getType, key, entry, now);
public void evictOrphanElements(final ClusterInfo clusterInfo) { if (isEvictionEnabled() && getConfig().isOrphanEvictionEnabled()) { for (Map m : data.getConstituentMaps()) { Set<K> keys = clusterInfo.getKeysForOrphanedValues(m); invalidateCacheEntries(keys.iterator()); } } }
if (isEvictionEnabled() || isCapacityEvictionEnabled()) { final int now = getTime(); ClusteredLock lock = createFinegrainedLock(key); if (entry.isExpired(now, config)) { if (!lock.isHeldByCurrentThread(LockType.READ)) { evict(key, entry, now);
protected void invalidateCacheEntries(final Iterator<K> keys) { int examined = 0; int expired = 0; while (keys.hasNext()) { K key = keys.next(); try { TimestampedValue<V> wrappedValue = data.get(key); if (wrappedValue == null) continue; examined++; int now = getTime(); if (wrappedValue.isExpired(now, config)) { expired++; expire(GetType.COHERENT, key, wrappedValue, now); } } catch (Throwable t) { LOGGER.error("Unhandled exception inspecting item for [" + key + "] for expiration", t); } } if (isStatisticsEnabled()) { statistics.increment(examined, expired); } }
private TimestampedValue<V> wrapValue(final V value) { if (value instanceof TimestampedValue) { // If application already supplies a TimestampedEntry, don't wrap it again initCapacityEvictionPolicyFromConfig((TimestampedValue) value); return (TimestampedValue<V>) value; } DefaultTimestampedValue<V> defaultTimestampedValue = new DefaultTimestampedValue<V>(value, getTime()); initCapacityEvictionPolicyFromConfig(defaultTimestampedValue); return defaultTimestampedValue; }
private void initCapacityEvictionPolicyFromConfig(final TimestampedValue timestampedValue) { if (isCapacityEvictionEnabled()) { // use CapacityEvictionPolicyData.Factory in config to create a new one if its not an instance of the config's // factory CapacityEvictionPolicyData current = timestampedValue.getCapacityEvictionPolicyData(); if (!getConfig().getCapacityEvictionPolicyDataFactory().isProductOfFactory(current)) { CapacityEvictionPolicyData cep = getConfig().getCapacityEvictionPolicyDataFactory() .newCapacityEvictionPolicyData(); timestampedValue.setCapacityEvictionPolicyData(cep); } } }
public V remove(final Object key) { return getValueSafe(filterExpired(this.data.remove(key))); }
protected void initializeOnLoad(final boolean startEviction) { if (config.isLoggingEnabled()) { LOGGER.info("Initializing CHMDistributedMap, starting eviction thread"); } this.timeSource = new SystemTimeSource(); this.orphanEvictor = new OrphanEvictionListener<K>(config, this, orphanEvictorLock); this.evictionScheduler = new EvictionScheduler(config, new Evictor<K>(this, orphanEvictor)); this.statistics = new EvictionStatistics(); if (!this.config.isServerMap()) { // target capacity eviction listener not needed for servermap this.data.registerMapSizeListener(new TargetCapacityMapSizeListener(data, getConfig())); } if (startEviction) { startEviction(); } }
public boolean containsKey(final Object key) { TimestampedValue<V> entry = getNonExpiredEntryCoherent((K) key, false); return entry != null; }
protected void invalidateCacheEntries(final Iterator<K> keys) { int examined = 0; int evicted = 0; while (keys.hasNext()) { K key = keys.next(); try { TimestampedValue<V> wrappedValue = data.get(key); if (wrappedValue == null) continue; examined++; int now = getTime(); if (wrappedValue.isExpired(now, config)) { evicted++; evict(key, wrappedValue, now); } } catch (Throwable t) { LOGGER.error("Unhandled exception inspecting item for [" + key + "] for expiration", t); } } if (isStatisticsEnabled()) { statistics.increment(examined, evicted); } }
public <K, V> DistributedCache<K, V> newCache() { final MutableConfig copyConfig = new MutableConfig(this.name, this.loggingEnabled, this.maxTTISeconds, this.maxTTLSeconds, this.orphanEvictionEnabled, this.orphanEvictionPeriod, this.targetMaxInMemoryCount, this.targetMaxTotalCount, this.capacityEvictionPolicyDataFactory); if (Terracotta.isActive()) { return new TerracottaDistributedCache<K, V>(copyConfig); } else { return new LocalCache<K, V>(copyConfig); } }
public boolean unlockedContainsKey(final Object key) { TimestampedValue<V> entry = getNonExpiredEntryUnlocked((K) key, false); return entry != null; }
public TimestampedValue<V> removeTimestampedValueWithCallback(final K key, final MutationCallback<K, TimestampedValue<V>> callback) { return filterExpired(this.mutateCallbacks.removeWithCallback(key, callback)); }
public V unsafeGet(final K key, final boolean quiet) { return getValueSafe(unsafeGetTimestampedValue(key, quiet)); }
public TimestampedValue<V> unsafeGetTimestampedValue(final K key, final boolean quiet) { return getNonExpiredEntryUnsafe(key, !quiet); }