public void updateMemoryUsage(long deltaUserMemoryInBytes, long deltaTotalMemoryInBytes) { currentTotalMemory.addAndGet(deltaTotalMemoryInBytes); currentUserMemory.addAndGet(deltaUserMemoryInBytes); peakUserMemory.updateAndGet(currentPeakValue -> max(currentUserMemory.get(), currentPeakValue)); }
@Override public void request(long n) { extraMessages.updateAndGet((p) -> { long newVal = p - n; if (newVal < 0) { subscription.request(n - p); return 0; } else { return newVal; } }); }
public void updateMemoryUsage(long deltaUserMemoryInBytes, long deltaTotalMemoryInBytes, long taskTotalMemoryInBytes) { currentUserMemory.addAndGet(deltaUserMemoryInBytes); currentTotalMemory.addAndGet(deltaTotalMemoryInBytes); peakUserMemory.updateAndGet(currentPeakValue -> Math.max(currentUserMemory.get(), currentPeakValue)); peakTotalMemory.updateAndGet(currentPeakValue -> Math.max(currentTotalMemory.get(), currentPeakValue)); peakTaskTotalMemory.accumulateAndGet(taskTotalMemoryInBytes, Math::max); }
/** * Releases {@code n} permits. If the cumulative value of the current total permits * reaches {@link Long#MAX_VALUE} this semaphore becomes unbounded and any consecutive * acquire call succeeds. Furthermore, any consecutive release call doesn't change the * new unbounded nature of this semaphore. * * @param n the number of permits to release * @return the new count of currently available permits */ long release(long n) { return atomicLong.updateAndGet(original -> { long r = original + n; // HD 2-12 Overflow iff both arguments have the opposite sign of the result; inspired by Math.addExact(long, long) if (r == Long.MAX_VALUE || ((original ^ r) & (n ^ r)) < 0) { // unbounded reached return Long.MAX_VALUE; } else { return original + n; } }); }
/** * Updates the ID Generator so that it is at least equal to the given minimum value * * @param minimumValue the minimum value that the ID Generator should be set to */ static void updateIdGenerator(long minimumValue) { idGenerator.updateAndGet(curValue -> Math.max(minimumValue, curValue)); }
public void appendValue(long value) { count.incrementAndGet(); sum.addAndGet(value); min.updateAndGet(x -> value < x ? value : x); max.updateAndGet(x -> value > x ? value : x); }
/** * notifies the stream observer that [@code consumed} messages are processed by the client. * Triggers a new permits request when remaining permits is 0 * @param consumed nr of messages consumed */ public void markConsumed(Integer consumed) { if( remainingPermits.updateAndGet(old -> old - consumed) == 0) { remainingPermits.addAndGet(newPermits); synchronized (wrappedStreamObserver) { wrappedStreamObserver.onNext(newPermitsRequest); } logger.info("Granting new permits: {}", newPermitsRequest); } }
/** * Increments safely a requested event counter to prevent {@code Long.MAX_VALUE} overflow. * * @param increment amount of additional events to request. */ public void increment(long increment, Consumer<? super IllegalArgumentException> errorHandler) { if (increment <= 0) { errorHandler.accept(new IllegalArgumentException("Unsupported requested event increment: " + increment)); return; } requested.updateAndGet(original -> { if (original == Long.MAX_VALUE) { return Long.MAX_VALUE; } long r = original + increment; // HD 2-12 Overflow iff both arguments have the opposite sign of the result; inspired by Math.addExact(long, long) if (r == Long.MAX_VALUE || ((original ^ r) & (increment ^ r)) < 0) { // unbounded reached return Long.MAX_VALUE; } else { return r; } }); }
/** * Increments safely a requested event counter to prevent {@code Long.MAX_VALUE} overflow. * * @param increment amount of additional events to request. * @param errorHandler a consumer of {@code IllegalArgumentException} to * process errors */ public void increment(long increment, Consumer<? super IllegalArgumentException> errorHandler) { if (increment <= 0) { errorHandler.accept(new IllegalArgumentException("Unsupported requested event increment: " + increment)); return; } requested.updateAndGet(original -> { if (original == Long.MAX_VALUE) { return Long.MAX_VALUE; } long r = original + increment; // HD 2-12 Overflow iff both arguments have the opposite sign of the result; inspired by Math.addExact(long, long) if (r == Long.MAX_VALUE || ((original ^ r) & (increment ^ r)) < 0) { // unbounded reached return Long.MAX_VALUE; } else { return r; } }); }
/** * Attempts to invoke the specified {@code runnable} if no other action with * the same specifier has been called recently. Otherwise, the method will * return with no effect. * * @param action the action specifier * @param runnable the callable action to invoke */ public void call(String action, Runnable runnable) { final long now = now(); final AtomicLong timer = timers.computeIfAbsent(action, a -> new AtomicLong(0)); if (now == timer.updateAndGet( lastCall -> lastCall + millis < now ? now : lastCall )) runnable.run(); }
ConversionService conversionService = ConversionService.SHARED; Subscription s; LongConsumer onRequest = (num) -> pressureRequested.updateAndGet((p) -> { long newVal = p - num; if (newVal < 0) {
final long updatedId = idGenerator.updateAndGet(curVal -> Math.max(curVal, nextPartitionId)); logger.info("After recovering {}, next Event ID to be generated will be {}", partitionDirectory, updatedId);
long nextCursor = cursor.updateAndGet(old -> old == tail.get() ? old : old + 1);
void updateNodeStatus(final NodeConnectionStatus status, final boolean waitForCoordinator) { final NodeIdentifier nodeId = status.getNodeIdentifier(); // In this case, we are using nodeStatuses.put() instead of getting the current value and // comparing that to the new value and using the one with the largest update id. This is because // this method is called when something occurs that causes this node to change the status of the // node in question. We only use comparisons against the current value when we receive an update // about a node status from a different node, since those may be received out-of-order. final NodeConnectionStatus currentStatus = updateNodeStatus(nodeId, status); final NodeConnectionState currentState = currentStatus == null ? null : currentStatus.getState(); logger.info("Status of {} changed from {} to {}", nodeId, currentStatus, status); logger.debug("State of cluster nodes is now {}", nodeStatuses); latestUpdateId.updateAndGet(curVal -> Math.max(curVal, status.getUpdateIdentifier())); if (currentState == null || currentState != status.getState()) { final boolean notifyAllNodes = isActiveClusterCoordinator(); if (notifyAllNodes) { logger.debug("Notifying all nodes that status changed from {} to {}", currentStatus, status); } else { logger.debug("Notifying cluster coordinator that node status changed from {} to {}", currentStatus, status); } notifyOthersOfNodeStatusChange(status, notifyAllNodes, waitForCoordinator); } else { logger.debug("Not notifying other nodes that status changed because previous state of {} is same as new state of {}", currentState, status.getState()); } }
subscription.request(1); } else { extraMessages.updateAndGet((p) -> p + messages.size() - 1); messages.stream().map(HttpData.class::cast).forEach(subscriber::onNext);
public void updateMinDeletedTimestamp(DeleteVersionValue delete) { long time = delete.time; minDeleteTimestamp.updateAndGet(prev -> Math.min(time, prev)); }
private void updateAutoIdTimestamp(long newTimestamp, boolean unsafe) { assert newTimestamp >= -1 : "invalid timestamp [" + newTimestamp + "]"; maxSeenAutoIdTimestamp.updateAndGet(curr -> Math.max(curr, newTimestamp)); if (unsafe) { maxUnsafeAutoIdTimestamp.updateAndGet(curr -> Math.max(curr, newTimestamp)); } assert maxUnsafeAutoIdTimestamp.get() <= maxSeenAutoIdTimestamp.get(); }
void updateRefreshedCheckpoint(long checkpoint) { refreshedCheckpoint.updateAndGet(curr -> Math.max(curr, checkpoint)); assert refreshedCheckpoint.get() >= checkpoint : refreshedCheckpoint.get() + " < " + checkpoint; } }
/** * A replica shard receives a new max_seq_no_of_updates from its primary shard, then calls this method * to advance this marker to at least the given sequence number. */ public final void advanceMaxSeqNoOfUpdatesOrDeletes(long seqNo) { maxSeqNoOfUpdatesOrDeletes.updateAndGet(curr -> Math.max(curr, seqNo)); assert maxSeqNoOfUpdatesOrDeletes.get() >= seqNo : maxSeqNoOfUpdatesOrDeletes.get() + " < " + seqNo; } }
public TimestampRange incrementBy(long delta) { long upperBound = value.updateAndGet(current -> Math.addExact(current, delta)); long lowerBound = upperBound - delta + 1L; return TimestampRange.createInclusiveRange(lowerBound, upperBound); }