public void reserve(long elements, long bytes) throws FlowControlException { Preconditions.checkArgument(elements >= 0); Preconditions.checkArgument(bytes >= 0); if (outstandingElementCount != null) { if (!outstandingElementCount.acquire(elements)) { throw new MaxOutstandingElementCountReachedException(maxOutstandingElementCount); } } // Will always allow to send a request even if it is larger than the flow control limit, // if it doesn't then it will deadlock the thread. if (outstandingByteCount != null) { long permitsToDraw = Math.min(bytes, maxOutstandingRequestBytes); if (!outstandingByteCount.acquire(permitsToDraw)) { if (outstandingElementCount != null) { outstandingElementCount.release(elements); } throw new MaxOutstandingRequestBytesReachedException(maxOutstandingRequestBytes); } } }
public void reserve(long elements, long bytes) throws FlowControlException { Preconditions.checkArgument(elements >= 0); Preconditions.checkArgument(bytes >= 0); if (outstandingElementCount != null) { if (!outstandingElementCount.acquire(elements)) { throw new MaxOutstandingElementCountReachedException(maxOutstandingElementCount); } } // Will always allow to send a request even if it is larger than the flow control limit, // if it doesn't then it will deadlock the thread. if (outstandingByteCount != null) { long permitsToDraw = Math.min(bytes, maxOutstandingRequestBytes); if (!outstandingByteCount.acquire(permitsToDraw)) { if (outstandingElementCount != null) { outstandingElementCount.release(elements); } throw new MaxOutstandingRequestBytesReachedException(maxOutstandingRequestBytes); } } }