/** Stop extending deadlines for this message and free flow control. */ private void forget() { if (pendingMessages.remove(ackId) == null) { /* * We're forgetting the message for the second time. Probably because we ran out of total * expiration, forget the message, then the user finishes working on the message, and forget * again. Turn the second forget into a no-op so we don't free twice. */ return; } flowController.release(1, outstandingBytes); messagesWaiter.incrementPendingMessages(-1); processOutstandingBatches(); }
@Override public void release(long elements, long bytes) { super.release(elements, bytes); this.elementsReleased += elements; this.bytesReleased += bytes; this.callsToRelease += 1; }
public void release(T batch) { Preconditions.checkNotNull(batch); int elements = Ints.checkedCast(elementCounter.count(batch)); int bytes = Ints.checkedCast(byteCounter.count(batch)); flowController.release(elements, bytes); } }
public void release(T batch) { Preconditions.checkNotNull(batch); int elements = Ints.checkedCast(elementCounter.count(batch)); int bytes = Ints.checkedCast(byteCounter.count(batch)); flowController.release(elements, bytes); } }
private static void testBlockingReserveRelease( final FlowController flowController, final int maxElementCount, final int maxNumBytes) throws Exception { flowController.reserve(1, 1); final SettableFuture<?> permitsReserved = SettableFuture.create(); Future<?> finished = Executors.newCachedThreadPool() .submit( new Runnable() { @Override public void run() { try { permitsReserved.set(null); flowController.reserve(maxElementCount, maxNumBytes); } catch (FlowController.FlowControlException e) { throw new AssertionError(e); } } }); permitsReserved.get(); flowController.release(1, 1); finished.get(); }
private void testRejectedReserveRelease( FlowController flowController, int maxElementCount, int maxNumBytes, Class<? extends FlowController.FlowControlException> expectedException) throws FlowController.FlowControlException { flowController.reserve(1, 1); try { flowController.reserve(maxElementCount, maxNumBytes); fail("Should thrown a FlowController.FlowControlException"); } catch (FlowController.FlowControlException e) { assertTrue(expectedException.isInstance(e)); } flowController.release(1, 1); flowController.reserve(maxElementCount, maxNumBytes); } }
@Test public void testReserveRelease_noLimits_ok() throws Exception { FlowController flowController = new FlowController( FlowControlSettings.newBuilder() .setLimitExceededBehavior(LimitExceededBehavior.Block) .build()); flowController.reserve(1, 1); flowController.release(1, 1); }
@Test public void testReserveRelease_ok() throws Exception { FlowController flowController = new FlowController( FlowControlSettings.newBuilder() .setMaxOutstandingElementCount(10L) .setMaxOutstandingRequestBytes(10L) .setLimitExceededBehavior(LimitExceededBehavior.Block) .build()); flowController.reserve(1, 1); flowController.release(1, 1); }
@Test public void testReserveRelease_ignore_ok() throws Exception { FlowController flowController = new FlowController( FlowControlSettings.newBuilder() .setMaxOutstandingElementCount(1L) .setMaxOutstandingRequestBytes(1L) .setLimitExceededBehavior(LimitExceededBehavior.Ignore) .build()); flowController.reserve(1, 1); flowController.release(1, 1); }