@Override public ReadStream<T> fetch(long amount) { delegate.fetch(amount); return this; }
@Override void init(ReadStream<Buffer> stream) { fetching.set(true); stream.pause(); stream.fetch(1); } @Override
@Override Future<Void> handle(ReadStream<Buffer> stream) { Future<Void> fut = Future.future(); assert fetching.getAndSet(false); Vertx.currentContext().owner().setTimer(1, id -> { assert !fetching.getAndSet(true); stream.fetch(1); fut.complete(); }); return fut; } };
private void testPauseFetch(BiFunction<MessageConsumer<String>, Handler<String>, ReadStream<?>> streamSupplier) throws Exception { List<String> data = new ArrayList<>(); for (int i = 0; i < 11; i++) { data.add(TestUtils.randomAlphaString(10)); } List<String> received = Collections.synchronizedList(new ArrayList<>()); CountDownLatch receiveLatch = new CountDownLatch(4); HandlerRegistration<String> consumer = (HandlerRegistration<String>) eb.<String>consumer(ADDRESS1).setMaxBufferedMessages(5); streamSupplier.apply(consumer, e -> { received.add(e); receiveLatch.countDown(); }).pause().fetch(4); List<String> discarded = Collections.synchronizedList(new ArrayList<>()); CountDownLatch discardLatch = new CountDownLatch(2); consumer.discardHandler(msg -> { discarded.add(msg.body()); discardLatch.countDown(); }); ListIterator<String> iterator = data.listIterator(); while (iterator.nextIndex() < 4) { eb.publish(ADDRESS1, iterator.next()); } awaitLatch(receiveLatch); while (iterator.hasNext()) { eb.publish(ADDRESS1, iterator.next()); } awaitLatch(discardLatch); assertEquals(data.subList(0, 4), received); assertEquals(data.subList(data.size() - 2, data.size()), discarded); }
@Override public ReadStream<T> fetch(long amount) { delegate.fetch(amount); return this; }
@Override void init(ReadStream<Buffer> stream) { fetching.set(true); stream.pause(); stream.fetch(1); } @Override
@Override Future<Void> handle(ReadStream<Buffer> stream) { Future<Void> fut = Future.future(); assert fetching.getAndSet(false); Vertx.currentContext().owner().setTimer(1, id -> { assert !fetching.getAndSet(true); stream.fetch(1); fut.complete(); }); return fut; } };
private void testPauseFetch(BiFunction<MessageConsumer<String>, Handler<String>, ReadStream<?>> streamSupplier) throws Exception { List<String> data = new ArrayList<>(); for (int i = 0; i < 11; i++) { data.add(TestUtils.randomAlphaString(10)); } List<String> received = Collections.synchronizedList(new ArrayList<>()); CountDownLatch receiveLatch = new CountDownLatch(4); HandlerRegistration<String> consumer = (HandlerRegistration<String>) eb.<String>consumer(ADDRESS1).setMaxBufferedMessages(5); streamSupplier.apply(consumer, e -> { received.add(e); receiveLatch.countDown(); }).pause().fetch(4); List<String> discarded = Collections.synchronizedList(new ArrayList<>()); CountDownLatch discardLatch = new CountDownLatch(2); consumer.discardHandler(msg -> { discarded.add(msg.body()); discardLatch.countDown(); }); ListIterator<String> iterator = data.listIterator(); while (iterator.nextIndex() < 4) { eb.publish(ADDRESS1, iterator.next()); } awaitLatch(receiveLatch); while (iterator.hasNext()) { eb.publish(ADDRESS1, iterator.next()); } awaitLatch(discardLatch); assertEquals(data.subList(0, 4), received); assertEquals(data.subList(data.size() - 2, data.size()), discarded); }
/** * Fetch the specified <code>amount</code> of elements. If the <code>ReadStream</code> has been paused, reading will * recommence with the specified <code>amount</code> of items, otherwise the specified <code>amount</code> will * be added to the current stream demand. * @param amount * @return a reference to this, so the API can be used fluently */ public io.vertx.rxjava.core.streams.ReadStream<T> fetch(long amount) { delegate.fetch(amount); return this; }
/** * Fetch the specified <code>amount</code> of elements. If the <code>ReadStream</code> has been paused, reading will * recommence with the specified <code>amount</code> of items, otherwise the specified <code>amount</code> will * be added to the current stream demand. * @param amount * @return a reference to this, so the API can be used fluently */ public io.vertx.rxjava.core.streams.ReadStream<T> fetch(long amount) { delegate.fetch(amount); return this; }
@Override public void request(long l) { if (current.get() == this) { stream.fetch(l); } }
/** * Fetch the specified <code>amount</code> of elements. If the <code>ReadStream</code> has been paused, reading will * recommence with the specified <code>amount</code> of items, otherwise the specified <code>amount</code> will * be added to the current stream demand. * @param amount * @return a reference to this, so the API can be used fluently */ public io.vertx.rxjava.core.streams.ReadStream<T> fetch(long amount) { delegate.fetch(amount); return this; }
@Override public BufferReadStream fetch(long amount) { stream.fetch(amount); return this; } @Override
/** * Fetch the specified <code>amount</code> of elements. If the <code>ReadStream</code> has been paused, reading will * recommence with the specified <code>amount</code> of items, otherwise the specified <code>amount</code> will * be added to the current stream demand. * @param amount * @return a reference to this, so the API can be used fluently */ public io.vertx.reactivex.core.streams.ReadStream<T> fetch(long amount) { delegate.fetch(amount); return this; }
/** * Fetch the specified <code>amount</code> of elements. If the <code>ReadStream</code> has been paused, reading will * recommence with the specified <code>amount</code> of items, otherwise the specified <code>amount</code> will * be added to the current stream demand. * @param amount * @return a reference to this, so the API can be used fluently */ public io.vertx.reactivex.core.streams.ReadStream<T> fetch(long amount) { delegate.fetch(amount); return this; }