@Override
 protected String toString(InternalCacheEntry ice) {
   if (ice == null) return null;
   StringBuilder sb = new StringBuilder(256);
   sb.append(ice.getClass().getSimpleName());
   sb.append("[key=").append(ice.getKey()).append(", value=").append(ice.getValue());
   sb.append(", created=").append(ice.getCreated()).append(", isCreated=").append(ice.isCreated());
   sb.append(", lastUsed=")
       .append(ice.getLastUsed())
       .append(", isChanged=")
       .append(ice.isChanged());
   sb.append(", expires=")
       .append(ice.getExpiryTime())
       .append(", isExpired=")
       .append(ice.isExpired(System.currentTimeMillis()));
   sb.append(", canExpire=")
       .append(ice.canExpire())
       .append(", isEvicted=")
       .append(ice.isEvicted());
   sb.append(", isRemoved=").append(ice.isRemoved()).append(", isValid=").append(ice.isValid());
   sb.append(", lifespan=")
       .append(ice.getLifespan())
       .append(", maxIdle=")
       .append(ice.getMaxIdle());
   return sb.append(']').toString();
 }
  @Override
  public final void store(InternalCacheEntry ed) throws CacheLoaderException {
    if (trace) {
      log.tracef("store(%s)", ed);
    }
    if (ed == null) {
      return;
    }
    if (ed.canExpire() && ed.isExpired(System.currentTimeMillis())) {
      if (containsKey(ed.getKey())) {
        if (trace) {
          log.tracef("Entry %s is expired!  Removing!", ed);
        }
        remove(ed.getKey());
      } else {
        if (trace) {
          log.tracef("Entry %s is expired!  Not doing anything.", ed);
        }
      }
      return;
    }

    L keyHashCode = getLockFromKey(ed.getKey());
    lockForWriting(keyHashCode);
    try {
      storeLockSafe(ed, keyHashCode);
    } finally {
      unlock(keyHashCode);
    }
    if (trace) {
      log.tracef("exit store(%s)", ed);
    }
  }
 public boolean containsKey(Object k) {
   InternalCacheEntry ice = peek(k);
   if (ice != null && ice.canExpire() && ice.isExpired(System.currentTimeMillis())) {
     entries.remove(k);
     ice = null;
   }
   return ice != null;
 }
Пример #4
0
 @Override
 public boolean containsKey(Object k) {
   InternalCacheEntry<K, V> ice = peek(k);
   if (ice != null && ice.canExpire() && ice.isExpired(timeService.wallClockTime())) {
     entries.remove(k);
     ice = null;
   }
   return ice != null;
 }
 public InternalCacheEntry get(Object k) {
   InternalCacheEntry e = peek(k);
   if (e != null && e.canExpire()) {
     long currentTimeMillis = System.currentTimeMillis();
     if (e.isExpired(currentTimeMillis)) {
       entries.remove(k);
       e = null;
     } else {
       e.touch(currentTimeMillis);
     }
   }
   return e;
 }
Пример #6
0
 @Override
 public InternalCacheEntry<K, V> get(Object k) {
   InternalCacheEntry<K, V> e = entries.get(k);
   if (e != null && e.canExpire()) {
     long currentTimeMillis = timeService.wallClockTime();
     if (e.isExpired(currentTimeMillis)) {
       expirationManager.handleInMemoryExpiration(e, currentTimeMillis);
       e = null;
     } else {
       e.touch(currentTimeMillis);
     }
   }
   return e;
 }
Пример #7
0
 @Override
 public InternalCacheEntry<K, V> remove(Object k) {
   final InternalCacheEntry<K, V>[] reference = new InternalCacheEntry[1];
   entries.compute(
       (K) k,
       (key, entry) -> {
         activator.onRemove(key, entry == null);
         reference[0] = entry;
         return null;
       });
   InternalCacheEntry<K, V> e = reference[0];
   if (trace) {
     log.tracef("Removed %s from container", e);
   }
   return e == null || (e.canExpire() && e.isExpired(timeService.wallClockTime())) ? null : e;
 }
Пример #8
0
 private InternalCacheEntry<K, V> getNext() {
   boolean initializedTime = false;
   long now = 0;
   while (it.hasNext()) {
     InternalCacheEntry<K, V> entry = it.next();
     if (includeExpired || !entry.canExpire()) {
       return entry;
     } else {
       if (!initializedTime) {
         now = timeService.wallClockTime();
         initializedTime = true;
       }
       if (!entry.isExpired(now)) {
         return entry;
       }
     }
   }
   return null;
 }
Пример #9
0
 private void store0(
     InternalCacheEntry entry, Map<ByteBuffer, Map<String, List<Mutation>>> mutationMap)
     throws IOException, UnsupportedKeyTypeException {
   Object key = entry.getKey();
   if (trace) log.tracef("store(\"%s\") ", key);
   String cassandraKey = hashKey(key);
   try {
     addMutation(
         mutationMap,
         ByteBufferUtil.bytes(cassandraKey),
         config.entryColumnFamily,
         ByteBuffer.wrap(entryColumnPath.getColumn()),
         ByteBuffer.wrap(marshall(entry)));
     if (entry.canExpire()) {
       addExpiryEntry(cassandraKey, entry.getExpiryTime(), mutationMap);
     }
   } catch (InterruptedException ie) {
     if (trace) log.trace("Interrupted while trying to marshall entry");
     Thread.currentThread().interrupt();
   }
 }
Пример #10
0
 @Override
 public InternalCacheEntry remove(Object k) {
   InternalCacheEntry e = entries.remove(k);
   return e == null || (e.canExpire() && e.isExpired(System.currentTimeMillis())) ? null : e;
 }