@Test public void reserveFailsWhenPendingRequest() { ReservableRequestConcurrencyController controller = newController(from(10), never(), 10); assertThat(controller.tryRequest(), is(Accepted)); assertFalse(controller.tryReserve()); }
@Override public Result tryRequest() { final int maxConcurrency = lastSeenMaxValue(maxRequests); for (;;) { final int currentPending = pendingRequests(); if (currentPending < 0) { return RejectedPermanently; } if (currentPending >= maxConcurrency) { return RejectedTemporary; } if (casPendingRequests(currentPending, currentPending + 1)) { return Accepted; } } }
ReservableRequestConcurrencyControllerMulti extends AbstractReservableRequestConcurrencyController { @Override public Result tryRequest() { final int maxConcurrency = lastSeenMaxValue(maxRequests); for (;;) { final int currentPending = pendingRequests(); if (currentPending < 0) { return RejectedPermanently; } if (currentPending >= maxConcurrency) { return RejectedTemporary; } if (casPendingRequests(currentPending, currentPending + 1)) { return Accepted; } } } }
ReservableRequestConcurrencyControllerMulti extends AbstractReservableRequestConcurrencyController { @Override public Result tryRequest() { final int maxConcurrency = lastSeenMaxValue(maxRequests); for (;;) { final int currentPending = pendingRequests(); if (currentPending < 0) { return RejectedPermanently; } if (currentPending >= maxConcurrency) { return RejectedTemporary; } if (casPendingRequests(currentPending, currentPending + 1)) { return Accepted; } } } ReservableRequestConcurrencyControllerMulti(final Publisher<? extends ConsumableEvent<Integer>> maxConcurrency,
                                                final Completable onClosing,
                                                int maxRequests); }
ReservableRequestConcurrencyControllerMulti extends AbstractReservableRequestConcurrencyController { @Override public Result tryRequest() { final int maxConcurrency = lastSeenMaxValue(maxRequests); for (;;) { final int currentPending = pendingRequests(); if (currentPending < 0) { return RejectedPermanently; } if (currentPending >= maxConcurrency) { return RejectedTemporary; } if (casPendingRequests(currentPending, currentPending + 1)) { return Accepted; } } } ReservableRequestConcurrencyControllerMulti(final Publisher<? extends ConsumableEvent<Integer>> maxConcurrency,
                                                final Completable onClosing,
                                                int maxRequests); @Override Result tryRequest(); }
ReservableRequestConcurrencyControllerMulti extends AbstractReservableRequestConcurrencyController { @Override public Result tryRequest() { final int maxConcurrency = lastSeenMaxValue(maxRequests); for (;;) { final int currentPending = pendingRequests(); if (currentPending < 0) { return RejectedPermanently; } if (currentPending >= maxConcurrency) { return RejectedTemporary; } if (casPendingRequests(currentPending, currentPending + 1)) { return Accepted; } } } ReservableRequestConcurrencyControllerMulti(final Publisher<? extends ConsumableEvent<Integer>> maxConcurrency,
                                                final Completable onClosing,
                                                int maxRequests); @Override Result tryRequest();  }