TimeProvider tp = () -> time.getAndAccumulate(1000, (x, y) -> x + y); ChronicleQueue queue = ChronicleQueue.singleBuilder(dir) .testBlockSize()
/** * Adds a reply time to the history. * * @param replyTime the reply time to add to the history */ void addReplyTime(long replyTime) { maxReplyTime.getAndAccumulate(replyTime, Math::max); }
boolean put(Record record) { if (immutable) { throw new IllegalStateException("page " + pageId + " is immutable!"); } final Record prev = data.put(record.key, record); final long newSize = estimateEntrySize(record); if (newSize > maxSize) { throw new IllegalStateException( "record too big to fit in any page " + newSize + " / " + maxSize + " bytes"); } final long diff = prev == null ? newSize : newSize - estimateEntrySize(prev); final long target = maxSize - diff; final long old = usedMemory.getAndAccumulate(diff, (curr, change) -> curr > target ? curr : curr + diff); if (old > target) { /* Remove the added key */ data.remove(record.key); return false; } return true; }
protected void delayedAcquirePoolMemory(long oldSize, long newSize, boolean withEntryOverHead, boolean shouldEvict) throws LowMemoryException { if (!this.reservedTable() && needAccounting()) { long size; if (withEntryOverHead) { size = (newSize - oldSize) + Math.max(0L, entryOverHead); } else { size = (newSize - oldSize); } if (MAX_VALUE_BEFORE_ACQUIRE == 1 || size > MAX_VALUE_BEFORE_ACQUIRE) { if (!callback.acquireStorageMemory(getFullPath(), (size), null, shouldEvict, false)) { throwLowMemoryException(size); } } else { long prevValue = memoryBeforeAcquire.getAndAccumulate(size, op); long currValue = prevValue + size; if (currValue >= MAX_VALUE_BEFORE_ACQUIRE) { if (!callback.acquireStorageMemory(getFullPath(), MAX_VALUE_BEFORE_ACQUIRE, null, shouldEvict, false)) { throwLowMemoryException(size); } } } } }