/** * Register an operation with the given size before sending. * This call WILL BLOCK until resources are available. This method must * be paired with a call to {@code markCanBeCompleted} in order to make sure * resources are properly released. * * @param heapSize The serialized size of the RPC to be sent * @return A unique operation id * @throws java.lang.InterruptedException if any. */ public long registerOperationWithHeapSize(long heapSize) throws InterruptedException { long start = clock.nanoTime(); synchronized (this) { while (unsynchronizedIsFull()) { waitForCompletions(REGISTER_WAIT_MILLIS); } long waitComplete = clock.nanoTime(); stats.markThrottling(waitComplete - start); long operationId = operationSequenceGenerator.incrementAndGet(); pendingOperationsWithSize.put(operationId, heapSize); currentWriteBufferSize += heapSize; starTimes.put(operationId, waitComplete); return operationId; } }