public static <X, Y> Pair<X, Y> create(X x, Y y) { return new Pair<X, Y>(x, y); }
@Override public Pair<Integer, Long> evictEntries(long sizeToFree) { return Pair.create(0, (long) 0); }
/** * Get the last position written in the managed ledger, alongside with the associated counter */ Pair<PositionImpl, Long> getLastPositionAndCounter() { PositionImpl pos; long count; do { pos = lastConfirmedEntry; count = ENTRIES_ADDED_COUNTER_UPDATER.get(this); // Ensure no entry was written while reading the two values } while (pos.compareTo(lastConfirmedEntry) != 0); return Pair.create(pos, count); }
/** * * @param minSize * @return a pair containing the number of entries evicted and their total size */ public Pair<Integer, Long> evictLeastAccessedEntries(long minSize) { checkArgument(minSize > 0); long removedSize = 0; int removedEntries = 0; while (removedSize < minSize) { Map.Entry<Key, Value> entry = entries.pollFirstEntry(); if (entry == null) { break; } Value value = entry.getValue(); ++removedEntries; removedSize += weighter.getSize(value); value.release(); } size.addAndGet(-removedSize); return Pair.create(removedEntries, removedSize); }
/** * * @param first * @param last * @param lastInclusive * @return an pair of ints, containing the number of removed entries and the total size */ public Pair<Integer, Long> removeRange(Key first, Key last, boolean lastInclusive) { Map<Key, Value> subMap = entries.subMap(first, true, last, lastInclusive); int removedEntries = 0; long removedSize = 0; for (Key key : subMap.keySet()) { Value value = entries.remove(key); if (value == null) { continue; } removedSize += weighter.getSize(value); value.release(); ++removedEntries; } size.addAndGet(-removedSize); return Pair.create(removedEntries, removedSize); }
/** * Signal that a cursor position has been updated and that the container must re-order the cursor list. * * @param cursor * @return a pair of positions, representing the previous slowest consumer and the new slowest consumer (after the * update). */ public Pair<PositionImpl, PositionImpl> cursorUpdated(ManagedCursor cursor, Position newPosition) { checkNotNull(cursor); long stamp = rwLock.writeLock(); try { Item item = cursors.get(cursor.getName()); if (item == null) { return null; } PositionImpl previousSlowestConsumer = heap.get(0).position; // When the cursor moves forward, we need to push it toward the // bottom of the tree and push it up if a reset was done item.position = (PositionImpl) newPosition; if (item.idx == 0 || getParent(item).position.compareTo(item.position) <= 0) { siftDown(item); } else { siftUp(item); } PositionImpl newSlowestConsumer = heap.get(0).position; return Pair.create(previousSlowestConsumer, newSlowestConsumer); } finally { rwLock.unlockWrite(stamp); } }