@Test public void testInvalidRequests() { switchable = new SwitchableSubscriptionSubscriber<Integer>(downstream) { @Override public void onItem(Integer item) { downstream.onItem(item); } }; switchable.request(-1); subscriber.assertHasFailedWith(IllegalArgumentException.class, ""); }
@Override public final void request(long n) { if (n <= 0) { downstream.onError(Subscriptions.getInvalidRequestException()); return; } if (unbounded) { return; } if (wip.compareAndSet(0, 1)) { long r = requested; if (r != Long.MAX_VALUE) { r = Subscriptions.add(r, n); requested = r; if (r == Long.MAX_VALUE) { unbounded = true; } } Subscription actual = currentUpstream.get(); if (wip.decrementAndGet() != 0) { drainLoop(); } if (actual != null) { actual.request(n); } return; } Subscriptions.add(missedRequested, n); drain(); }
SwitchableSubscriptionSubscriber implements MultiSubscriber<O>, Subscription { @Override public final void request(long n) { if (n <= 0) { downstream.onError(Subscriptions.getInvalidRequestException()); return; } if (unbounded) { return; } if (wip.compareAndSet(0, 1)) { long r = requested; if (r != Long.MAX_VALUE) { r = Subscriptions.add(r, n); requested = r; if (r == Long.MAX_VALUE) { unbounded = true; } } Subscription actual = currentUpstream.get(); if (wip.decrementAndGet() != 0) { drainLoop(); } if (actual != null) { actual.request(n); } return; } Subscriptions.add(missedRequested, n); drain(); } }
SwitchableSubscriptionSubscriber implements MultiSubscriber<O>, Subscription { @Override public final void request(long n) { if (n <= 0) { downstream.onError(Subscriptions.getInvalidRequestException()); return; } if (unbounded) { return; } if (wip.compareAndSet(0, 1)) { long r = requested; if (r != Long.MAX_VALUE) { r = Subscriptions.add(r, n); requested = r; if (r == Long.MAX_VALUE) { unbounded = true; } } Subscription actual = currentUpstream.get(); if (wip.decrementAndGet() != 0) { drainLoop(); } if (actual != null) { actual.request(n); } return; } Subscriptions.add(missedRequested, n); drain(); } SwitchableSubscriptionSubscriber(MultiSubscriber<? super O> downstream); }
SwitchableSubscriptionSubscriber implements MultiSubscriber<O>, Subscription { @Override public final void request(long n) { if (n <= 0) { downstream.onError(Subscriptions.getInvalidRequestException()); return; } if (unbounded) { return; } if (wip.compareAndSet(0, 1)) { long r = requested; if (r != Long.MAX_VALUE) { r = Subscriptions.add(r, n); requested = r; if (r == Long.MAX_VALUE) { unbounded = true; } } Subscription actual = currentUpstream.get(); if (wip.decrementAndGet() != 0) { drainLoop(); } if (actual != null) { actual.request(n); } return; } Subscriptions.add(missedRequested, n); drain(); } SwitchableSubscriptionSubscriber(MultiSubscriber<? super O> downstream); @Override void cancel(); boolean isCancelled(); @Override void onCompletion(); @Override void onFailure(Throwable t); @Override void onSubscribe(Subscription s); void emitted(long n); @Override final void request(long n); }
SwitchableSubscriptionSubscriber implements MultiSubscriber<O>, Subscription { @Override public final void request(long n) { if (n <= 0) { downstream.onError(Subscriptions.getInvalidRequestException()); return; } if (unbounded) { return; } if (wip.compareAndSet(0, 1)) { long r = requested; if (r != Long.MAX_VALUE) { r = Subscriptions.add(r, n); requested = r; if (r == Long.MAX_VALUE) { unbounded = true; } } Subscription actual = currentUpstream.get(); if (wip.decrementAndGet() != 0) { drainLoop(); } if (actual != null) { actual.request(n); } return; } Subscriptions.add(missedRequested, n); drain(); } SwitchableSubscriptionSubscriber(MultiSubscriber<? super O> downstream); @Override void cancel(); boolean isCancelled(); @Override void onCompletion(); @Override void onFailure(Throwable t); @Override void onSubscribe(Subscription s); void emitted(long n); @Override final void request(long n);  }