@Override public T poll() throws Exception { return qs.poll(); } }
@Override public int requestFusion(int mode) { QueueSubscription<T> qs = this.qs; if (qs != null && (mode & BOUNDARY) == 0) { int m = qs.requestFusion(mode); if (m != NONE) { syncFused = m == SYNC; } return m; } return NONE; }
@Override public void clear() { qs.clear(); }
@Override public void onNext(T t) { if (!checkSubscriptionOnce) { checkSubscriptionOnce = true; if (upstream.get() == null) { errors.add(new IllegalStateException("onSubscribe not called in proper order")); } } lastThread = Thread.currentThread(); if (establishedFusionMode == QueueSubscription.ASYNC) { try { while ((t = qs.poll()) != null) { values.add(t); } } catch (Throwable ex) { // Exceptions.throwIfFatal(e); TODO add fatal exceptions? errors.add(ex); qs.cancel(); } return; } values.add(t); if (t == null) { errors.add(new NullPointerException("onNext received a null value")); } downstream.onNext(t); }
@Override public void onSubscribe(Subscription s) { @SuppressWarnings("unchecked") QueueSubscription<Integer> qs = (QueueSubscription<Integer>)s; qs.requestFusion(QueueFuseable.ANY); assertFalse(qs.isEmpty()); try { assertEquals(1, qs.poll().intValue()); } catch (Throwable ex) { throw new RuntimeException(ex); } assertFalse(qs.isEmpty()); qs.clear(); assertTrue(qs.isEmpty()); qs.cancel(); }
@Override public boolean isEmpty() { return qs.isEmpty(); }
@Override public void onSubscribe(Subscription s) { try { if (s instanceof QueueSubscription) { @SuppressWarnings("unchecked") QueueSubscription<Object> qs = (QueueSubscription<Object>) s; state[0] = true; int m = qs.requestFusion(QueueFuseable.ANY); if (m != QueueFuseable.NONE) { state[1] = true; state[2] = qs.isEmpty(); qs.clear(); state[3] = qs.isEmpty(); } } cdl.countDown(); } finally { s.cancel(); } }
@Override public void onSubscribe(Subscription s) { @SuppressWarnings("unchecked") QueueSubscription<Integer> qs = (QueueSubscription<Integer>)s; assertFalse(qs.isEmpty()); try { assertEquals(1, qs.poll().intValue()); } catch (Exception ex) { throw new AssertionError(ex); } assertFalse(qs.isEmpty()); qs.clear(); List<Throwable> errors = TestHelper.trackPluginErrors(); try { qs.request(-99); TestHelper.assertError(errors, 0, IllegalArgumentException.class, "n > 0 required but it was -99"); } finally { RxJavaPlugins.reset(); } }
@Override public void onSubscribe(Subscription s) { @SuppressWarnings("unchecked") QueueSubscription<Integer> qs = (QueueSubscription<Integer>)s; qs.requestFusion(QueueFuseable.ANY); try { assertEquals(1, qs.poll().intValue()); } catch (Throwable ex) { fail(ex.toString()); } qs.clear(); try { assertNull(qs.poll()); } catch (Throwable ex) { fail(ex.toString()); } }
@Override public void onSubscribe(Subscription s) { @SuppressWarnings("unchecked") QueueSubscription<Integer> qs = (QueueSubscription<Integer>)s; try { assertNull(qs.poll()); } catch (Exception ex) { throw new AssertionError(ex); } assertTrue(qs.isEmpty()); qs.clear(); assertTrue(qs.isEmpty()); try { assertNull(qs.poll()); } catch (Exception ex) { throw new AssertionError(ex); } try { qs.offer(1); fail("Should have thrown!"); } catch (UnsupportedOperationException ex) { // expected } try { qs.offer(1, 2); fail("Should have thrown!"); } catch (UnsupportedOperationException ex) { // expected } }
@Override public void onSubscribe(Subscription s) { @SuppressWarnings("unchecked") QueueSubscription<Integer> qs = (QueueSubscription<Integer>)s; qs.requestFusion(QueueFuseable.ANY); assertFalse(qs.isEmpty()); try { assertEquals(1, qs.poll().intValue()); } catch (Throwable ex) { throw new RuntimeException(ex); } assertFalse(qs.isEmpty()); qs.clear(); assertTrue(qs.isEmpty()); qs.cancel(); }
@Override public boolean isEmpty() { return qs.isEmpty(); }
@Override public void onNext(T t) { if (!checkSubscriptionOnce) { checkSubscriptionOnce = true; if (subscription.get() == null) { errors.add(new IllegalStateException("onSubscribe not called in proper order")); } } lastThread = Thread.currentThread(); if (establishedFusionMode == QueueSubscription.ASYNC) { try { while ((t = qs.poll()) != null) { values.add(t); } } catch (Throwable ex) { // Exceptions.throwIfFatal(e); TODO add fatal exceptions? errors.add(ex); qs.cancel(); } return; } values.add(t); if (t == null) { errors.add(new NullPointerException("onNext received a null value")); } actual.onNext(t); }
@Override public void onSubscribe(Subscription s) { @SuppressWarnings("unchecked") QueueSubscription<Integer> qs = (QueueSubscription<Integer>)s; assertEquals(QueueFuseable.SYNC, qs.requestFusion(QueueFuseable.ANY)); try { assertFalse("Source reports being empty!", qs.isEmpty()); assertEquals(1, qs.poll().intValue()); assertFalse("Source reports being empty!", qs.isEmpty()); assertEquals(2, qs.poll().intValue()); assertFalse("Source reports being empty!", qs.isEmpty()); qs.clear(); assertTrue("Source reports not empty!", qs.isEmpty()); assertNull(qs.poll()); } catch (Throwable ex) { throw ExceptionHelper.wrapOrThrow(ex); } }
@Override public int requestFusion(int mode) { QueueSubscription<T> qs = this.qs; if (qs != null && (mode & BOUNDARY) == 0) { int m = qs.requestFusion(mode); if (m != NONE) { syncFused = m == SYNC; } return m; } return NONE; }
@Override public T poll() throws Exception { return qs.poll(); }