public LRUStringConverter(int size) { cache = Collections.synchronizedMap(new LRUMap(size)); }
LRUMap map = new LRUMap(2); assertEquals(0, map.size()); assertEquals(false, map.isFull()); assertEquals(2, map.maxSize()); map.put(keys[0], values[0]); assertEquals(1, map.size()); assertEquals(false, map.isFull()); assertEquals(2, map.maxSize()); map.put(keys[1], values[1]); assertEquals(2, map.size()); assertEquals(true, map.isFull()); assertEquals(2, map.maxSize()); it = map.keySet().iterator(); assertSame(keys[0], it.next()); assertSame(keys[1], it.next()); it = map.values().iterator(); assertSame(values[0], it.next()); assertSame(values[1], it.next()); map.put(keys[2], values[2]); assertEquals(2, map.size()); assertEquals(true, map.isFull()); assertEquals(2, map.maxSize()); it = map.keySet().iterator(); assertSame(keys[1], it.next()); assertSame(keys[2], it.next()); it = map.values().iterator();
if (isFull()) { LinkEntry reuse = header.after; boolean removeLRUEntry = false; if (scanUntilRemovable) { while (reuse != header && reuse != null) { if (removeLRU(reuse)) { removeLRUEntry = true; break; removeLRUEntry = removeLRU(reuse); " If so, then please report this to commons-dev@jakarta.apache.org as a bug."); reuseMapping(reuse, hashIndex, hashCode, key, value); } else { super.addMapping(hashIndex, hashCode, key, value);
public void testInternalState_getEntry_int() { if (isPutAddSupported() == false || isPutChangeSupported() == false) return; SingleHashCode one = new SingleHashCode("1"); SingleHashCode two = new SingleHashCode("2"); SingleHashCode three = new SingleHashCode("3"); SingleHashCode four = new SingleHashCode("4"); SingleHashCode five = new SingleHashCode("5"); SingleHashCode six = new SingleHashCode("6"); LRUMap map = new LRUMap(3, 1.0f); int hashIndex = map.hashIndex(map.hash(one), 4); map.put(one, "A"); map.put(two, "B"); map.put(three, "C"); assertEquals(one, map.getEntry(0).key); assertEquals(two, map.getEntry(1).key); assertEquals(three, map.getEntry(2).key); try { map.getEntry(-1); fail(); } catch (IndexOutOfBoundsException ex) {} try { map.getEntry(3); fail(); } catch (IndexOutOfBoundsException ex) {} }
SingleHashCode six = new SingleHashCode("6"); LRUMap map = new LRUMap(3, 1.0f); int hashIndex = map.hashIndex(map.hash(one), 4); map.put(one, "A"); map.put(two, "B"); map.put(three, "C"); assertEquals(one, map.data[hashIndex].next.next.key); map.put(four, "D"); // reuses last in next list assertEquals(two, map.data[hashIndex].next.next.key); map.get(three); assertEquals(two, map.data[hashIndex].next.next.key); map.put(five, "E"); // reuses last in next list assertEquals(three, map.data[hashIndex].next.next.key); map.get(three); map.get(five); assertEquals(three, map.data[hashIndex].next.next.key); map.put(six, "F"); // reuses middle in next list
ByteSequence testVis = k.getColumnVisibilityData(); if (filterInvalid) { Boolean b = (Boolean) cache.get(testVis); if (b != null) return b; try { new ColumnVisibility(testVis.toArray()); cache.put(testVis, true); return true; } catch (BadArgumentException e) { cache.put(testVis, false); return false; Boolean b = (Boolean) cache.get(testVis); if (b != null) return b; cache.put(testVis, bb); return bb; } catch (VisibilityParseException | BadArgumentException e) {
@Override public SortedKeyValueIterator<Key,Value> deepCopy(IteratorEnvironment env) { TransformingIterator copy; try { copy = getClass().newInstance(); } catch (Exception e) { throw new RuntimeException(e); } copy.setSource(getSource().deepCopy(env)); copy.scanning = scanning; copy.keyPos = keyPos; copy.keys.addAll(keys); copy.seekRange = (seekRange == null) ? null : new Range(seekRange); copy.seekColumnFamilies = (seekColumnFamilies == null) ? null : new HashSet<>(seekColumnFamilies); copy.seekColumnFamiliesInclusive = seekColumnFamiliesInclusive; copy.ve = ve; if (visibleCache != null) { copy.visibleCache = new LRUMap(visibleCache.maxSize()); copy.visibleCache.putAll(visibleCache); } if (parsedVisibilitiesCache != null) { copy.parsedVisibilitiesCache = new LRUMap(parsedVisibilitiesCache.maxSize()); copy.parsedVisibilitiesCache.putAll(parsedVisibilitiesCache); } copy.maxBufferSize = maxBufferSize; return copy; }
/** * Registers a list of snapshots with internal cache, using a String key. */ public synchronized void cacheSnapshots(String key, List snapshots) { snapshotLists.put(key, snapshots); }
Entry entry; synchronized (cacheSegment) { entry = (Entry) cacheSegment.get(uuid); int inUse = 0; for (LRUMap docNumber : docNumbers) { inUse += docNumber.size(); statistics.append("/").append(docNumbers[0].maxSize() * CACHE_SEGMENTS); statistics.append(", #accesses=").append(accesses); statistics.append(", #hits=").append((accesses - misses));
/** * Returns a list of previously cached snapshots. */ public synchronized List getCachedSnapshots(String key) { if (key == null) { return null; } return (List) snapshotLists.get(key); }
/** * Clear the principal cache. */ protected synchronized void clearCache() { cache.clear(); }
public JoinEdge getCachedOrNewJoinEdge(JoinSpec joinSpec, JoinVertex left, JoinVertex right) { Pair<JoinVertex,JoinVertex> cacheKey = new Pair<JoinVertex, JoinVertex>(left, right); if (edgeCache.containsKey(cacheKey)) { return (JoinEdge) edgeCache.get(cacheKey); } else { return cacheEdge(new JoinEdge(joinSpec, left, right)); } }
public void report(final ProblemReport pr) { if (problemReports.containsKey(pr)) { return; problemReports.put(pr, System.currentTimeMillis());
/** * Returns maximum allowed cache size. */ public int maximumSize() { return snapshots.maxSize(); }
protected boolean removeLRU(LinkEntry entry) { overflowRemoved(entry.getKey(), entry.getValue()); return super.removeLRU(entry); }
private static void cacheMisconfiguredHost(String host, int port, InetAddress address) { synchronized (misconfiguredHosts) { if (!misconfiguredHosts.isEmpty()) { removeStaleCachedMisconfiguredHosts(); } logger.info("Caching address of misconfigured (\"unrecognized_name\") host [host=" + host + ", port=" + port + "] for the next " + MAX_AGE_MISCONFIGURED_HOST_IN_MIN + " minutes, following connections will not use the hostname."); misconfiguredHosts.put(host + port, new MisconfiguredHostCacheEntry(host, port, address)); } }
private static InetAddress getCachedMisconfiguredHost(String host, int port) { synchronized (misconfiguredHosts) { if (misconfiguredHosts.isEmpty()) { return null; } removeStaleCachedMisconfiguredHosts(); MisconfiguredHostCacheEntry entry = (MisconfiguredHostCacheEntry) misconfiguredHosts.get(host + port); if (entry != null) { return entry.getAddress(); } return null; } }
public boolean isFull() { return (_max == -1) ? super.isFull() : size() >= _max; }