/** * {@inheritDoc} */ public int getCreationTime() { return value.getCreateTime(); }
/** * {@inheritDoc} */ public int getLastAccessTime() { return value.getLastAccessedTime(); }
private void checkExpired(final Object key, final boolean markUsed) { TimestampedValue<V> entry = this.data.get(key); if (null == entry) return; if (isEvictionEnabled()) { int now = getTime(); if (entry.isExpired(now, config)) { removeNoReturn(key); } else if (markUsed) { entry.markUsed(now, null, config); } } }
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); } } }
/** * Take an entry (which may be null) and return that entry only if not expired. If expired, return a null. If the * entry is expired, it is NOT evicted from the map. This method is suitable for calling by methods that return an old * version of an entry being modified (put, replace, remove) - these methods should not return an old expired entry. * * @param entry A possibly null, possibly expired entry * @return A possibly null, never expired entry */ private TimestampedValue<V> filterExpired(final TimestampedValue<V> entry) { if (entry != null && entry.isExpired(getTime(), config)) { return null; } else { return entry; } }
/** * Return the value from a possibly null entry. * * @param entry An entry, which may be null * @return The value for entry or null if the entry is null */ private V getValueSafe(final TimestampedValue<V> entry) { return entry == null ? null : entry.getValue(); }
private void setLastAccessTime(int time, final Element element, final Store store) { if (null == store) { throw new IllegalArgumentException("store can't be null"); } if (!(store instanceof ClusteredStore)) { throw new IllegalArgumentException( "store is expected to be a ClusteredStore"); } if (time < value.getCreateTime()) { if (LOG.isWarnEnabled()) { LOG.warn("Last access time " + time + " of element with key '" + element.getObjectKey() + "' is earlier than its creation time " + value.getCreateTime() + ". Setting it to the creation time."); } time = value.getCreateTime(); } ClusteredStore clusteredStore = (ClusteredStore) store; ClusteredStoreBackend backend = clusteredStore.getBackend(); value.markUsed(time, backend.createFinegrainedLock(clusteredStore.generateStringKeyFor(element.getKey())), backend .getConfig()); }
private void logEviction(final K key, final TimestampedValue<V> entry, final int now) { if (config.isLoggingEnabled()) { LOGGER.info(ManagerUtil.getClientID() + " expiring key: " + key + " (expiresAt = " + entry.expiresAt(config) + ", now = " + now + ")"); } }
public int compare(DetachedEntry o1, DetachedEntry o2) { Object v1 = o1.getValue(); Object v2 = o2.getValue(); if ((v1 instanceof TimestampedValue) && (v2 instanceof TimestampedValue)) { CapacityEvictionPolicyData d1 = ((TimestampedValue) v1).getCapacityEvictionPolicyData(); CapacityEvictionPolicyData d2 = ((TimestampedValue) v2).getCapacityEvictionPolicyData(); if (d1 == null) { if (d2 == null) { return 0; } else { return -1; } } else { return d1.compareTo(d2); } } else { return 0; } }
private void checkExpired(final Object key, final boolean markUsed) { TimestampedValue<V> entry = this.data.get(key); if (null == entry) return; if (isEvictionEnabled()) { int now = getTime(); if (entry.isExpired(now, config)) { removeNoReturn(key); } else if (markUsed) { entry.markUsed(now, null, config); } } }
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); } } }
/** * Take an entry (which may be null) and return that entry only if not expired. If expired, return a null. If the * entry is expired, it is NOT evicted from the map. This method is suitable for calling by methods that return an old * version of an entry being modified (put, replace, remove) - these methods should not return an old expired entry. * * @param entry A possibly null, possibly expired entry * @return A possibly null, never expired entry */ private TimestampedValue<V> filterExpired(final TimestampedValue<V> entry) { if (entry != null && entry.isExpired(getTime(), config)) { return null; } else { return entry; } }
/** * Return the value from a possibly null entry. * * @param entry An entry, which may be null * @return The value for entry or null if the entry is null */ private V getValueSafe(final TimestampedValue<V> entry) { return entry == null ? null : entry.getValue(); }
private void setLastAccessTime(int time, final Element element, final Store store) { if (null == store) { throw new IllegalArgumentException("store can't be null"); } if (!(store instanceof ClusteredStore)) { throw new IllegalArgumentException( "store is expected to be a ClusteredStore"); } if (time < value.getCreateTime()) { if (LOG.isLoggable(Level.WARNING)) { LOG.warning("Last access time " + time + " of element with key '" + element.getObjectKey() + "' is earlier than its creation time " + value.getCreateTime() + ". Setting it to the creation time."); } time = value.getCreateTime(); } ClusteredStore clusteredStore = (ClusteredStore) store; ClusteredStoreBackend backend = clusteredStore.getBackend(); value.markUsed(time, backend.getLockIdForKey(clusteredStore.generatePortableKeyFor(element.getObjectKey())), backend.getConfig()); }
private void logExpiry(final K key, final TimestampedValue<V> entry, final int now) { if (config.isLoggingEnabled()) { LOGGER.info(ManagerUtil.getClientID() + " expiring key: " + key + " (expiresAt = " + (entry == null ? "[null entry]" : entry.expiresAt(config)) + ", now = " + now + ")"); } }
public int compare(DetachedEntry o1, DetachedEntry o2) { Object v1 = o1.getValue(); Object v2 = o2.getValue(); if ((v1 instanceof TimestampedValue) && (v2 instanceof TimestampedValue)) { CapacityEvictionPolicyData d1 = ((TimestampedValue) v1).getCapacityEvictionPolicyData(); CapacityEvictionPolicyData d2 = ((TimestampedValue) v2).getCapacityEvictionPolicyData(); if (d1 == null) { if (d2 == null) { return 0; } else { return -1; } } else { return d1.compareTo(d2); } } else { return 0; } }
private void checkExpired(final Object key, final boolean markUsed) { TimestampedValue<V> entry = this.data.get(key); if (null == entry) return; if (isEvictionEnabled()) { int now = getTime(); if (entry.isExpired(now, config)) { removeNoReturn(key); } else if (markUsed) { entry.markUsed(now, null, config); } } }
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); } } }