/** * Iterate through {@link com.sleepycat.collections.StoredMap#entrySet()} and remove, if expired. */ @Override protected void purgeInternal() throws CacheLoaderException { try { Map<Long, Object> expired = expiryMap.headMap(timeService.wallClockTime(), true); for (Map.Entry<Long, Object> entry : expired.entrySet()) { expiryMap.remove(entry.getKey()); cacheMap.remove(entry.getValue()); } } catch (RuntimeException caught) { throw convertToCacheLoaderException("error purging expired entries", caught); } }
public SessionImpl(final CodecRegistry codecRegistry, final EmbeddedCacheManager cacheManager, final String id, TimeService timeService) { if (timeService == null) { throw new IllegalArgumentException("TimeService cannot be null"); } this.codecRegistry = codecRegistry; this.cacheManager = cacheManager; this.timeService = timeService; this.id = id; timestamp = timeService.time(); codec = this.codecRegistry.getCodec("none"); }
protected void printStatusMessage(long startTime, long doneCount) { log.indexingDocumentsCompleted(doneCount, timeService.timeDuration(startTime, TimeUnit.MILLISECONDS)); }
private void addNewExpiry(InternalCacheEntry entry) throws IOException { long expiry = entry.getExpiryTime(); if (entry.getMaxIdle() > 0) { // Coding getExpiryTime() for transient entries has the risk of being a moving target // which could lead to unexpected results, hence, InternalCacheEntry calls are required expiry = entry.getMaxIdle() + timeService.wallClockTime(); } Long at = expiry; Object key = entry.getKey(); if (trace) log.tracef("at %s expire %s", new SimpleDateFormat(DATE).format(new Date(at)), key); try { expiryEntryQueue.put(new ExpiryEntry(at, key)); } catch (InterruptedException e) { Thread.currentThread().interrupt(); // Restore interruption status } }
void expireSessions() { long timeBoundary = timeService.time() - sessionTimeout * 1000000l; for (Iterator<Session> i = sessions.values().iterator(); i.hasNext();) { Session session = i.next(); if (session.getTimestamp() < timeBoundary) { i.remove(); if (log.isDebugEnabled()) { log.debugf("Removed expired interpreter session %s", session.getId()); } } } }
/** * {@inheritDoc} This implementation delegates to {@link StoredMap#get(Object)}. If the object is expired, it will * not be returned. */ @Override public InternalCacheEntry load(Object key) throws CacheLoaderException { try { InternalCacheEntry s = cacheMap.get(key); if (s != null && s.isExpired(timeService.wallClockTime())) { s = null; } return s; } catch (RuntimeException caught) { throw convertToCacheLoaderException("error loading key " + key, caught); } }
public void documentsAdded(long increment) { long current = documentsDoneCounter.addAndGet(increment); if (current == increment) { startTime = timeService.time(); } if (current % getStatusMessagePeriod() == 0) { printStatusMessage(startTime, current); } }
private void purgeExpired() { Iterator<Map.Entry<Object, InternalCacheEntry>> i = cacheMap.entrySet().iterator(); while (i.hasNext()) { if (i.next().getValue().isExpired(TIME_SERVICE.wallClockTime())) i.remove(); } }
@Override public void reset() { resetCache(cacheManager.getCache()); for (String cacheName : cacheManager.getCacheNames()) { resetCache(cacheManager.getCache(cacheName)); } timestamp = timeService.time(); }
private void addNewExpiry(InternalCacheEntry entry) throws IOException { long expiry = entry.getExpiryTime(); if (entry.getMaxIdle() > 0) { // Coding getExpiryTime() for transient entries has the risk of being a moving target // which could lead to unexpected results, hence, InternalCacheEntry calls are required expiry = entry.getMaxIdle() + timeService.wallClockTime(); } Long at = expiry; Object key = entry.getKey(); expiryMap.put(at, key); }
while (browse.getNext(tuple)) { Long time = (Long) tuple.getKey(); if (time > timeService.wallClockTime()) break; times.add(time); log.debugf("purge (up to) %d entries", keys.size()); int count = 0; long currentTimeMillis = timeService.wallClockTime(); for (Object key : keys) { byte[] b = (byte[]) tree.get(key);
@Override public InternalCacheEntry load(Object key) throws CacheLoaderException { try { InternalCacheEntry ice = unmarshall(tree.get(key), key); if (ice != null && ice.isExpired(timeService.wallClockTime())) { remove(key); return null; } return ice; } catch (IOException e) { throw new CacheLoaderException(e); } catch (ClassNotFoundException e) { throw new CacheException(e); } }
private InternalCacheEntry load(Object key) { InternalCacheEntry s = cacheMap.get(key); if (s == null) return null; if (!s.isExpired(TIME_SERVICE.wallClockTime())) return s; else cacheMap.remove(key); return null; }
public void testLoadAndStore() throws InterruptedException, CacheLoaderException { assert !cacheMap.containsKey("k"); InternalCacheEntry se = TestInternalCacheEntryFactory.create("k", "v"); store(se); assert load("k").getValue().equals("v"); assert load("k").getLifespan() == -1; assert !load("k").isExpired(TIME_SERVICE.wallClockTime()); assert cacheMap.containsKey("k"); long lifespan = 120000; se = TestInternalCacheEntryFactory.create("k", "v", lifespan); store(se); assert load("k").getValue().equals("v"); assert load("k").getLifespan() == lifespan; assert !load("k").isExpired(TIME_SERVICE.wallClockTime()); assert cacheMap.containsKey("k"); lifespan = 1; se = TestInternalCacheEntryFactory.create("k", "v", lifespan); store(se); Thread.sleep(100); assert se.isExpired(TIME_SERVICE.wallClockTime()); assert load("k") == null; assert !cacheMap.containsKey("k"); }