/** * Blocks until the caller can send at least one byte without violating * bandwidth constraints. Records the number of byte sent. * * @param desired the number of bytes the caller would like to send * @return the number of bytes the sender is expected to send, which * is always greater than one and less than or equal to desired */ public synchronized int request(int desired) { if(UNLIMITED == rate) { return desired; } waitForBandwidth(); int result = Math.min(desired, availableBytes); availableBytes -= result; return result; }