Java Code Examples for io.vertx.core.streams.ReadStream#pause()

The following examples show how to use io.vertx.core.streams.ReadStream#pause() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ConfigurationStreamTest.java    From vertx-config with Apache License 2.0 5 votes vote down vote up
@Test
public void testFetch(TestContext tc) {
  retriever = ConfigRetriever.create(vertx,
    addStores(new ConfigRetrieverOptions().setScanPeriod(500)));
  Async async = tc.async();
  AtomicInteger steps = new AtomicInteger();
  ReadStream<JsonObject> stream = retriever.configStream();
  stream.pause();
  stream.fetch(3);
  AtomicBoolean paused = new AtomicBoolean();
  stream
    .handler(conf -> {
      String foo = conf.getString("foo");
      tc.assertFalse(paused.get());
      int step = steps.getAndIncrement();
      if (step == 0) {
        tc.assertEquals(foo, "bar");
      } else {
        tc.assertEquals(foo, "bar" + step);
      }
      if (step < 2) {
      } else if (step < 6) {
        paused.set(true);
        vertx.setTimer(1000, id -> {
          paused.set(false);
          stream.fetch(1);
        });
      } else {
        async.complete();
      }
      System.setProperty("foo", "bar" + (step + 1));
    });
}
 
Example 2
Source File: FlowableReadStream.java    From vertx-rx with Apache License 2.0 5 votes vote down vote up
public FlowableReadStream(ReadStream<T> stream, long maxBufferSize, Function<T, U> f) {

    stream.pause();

    this.stream = stream;
    this.f = f;
    this.current = new AtomicReference<>();
  }
 
Example 3
Source File: MQTTSocket.java    From vertx-mqtt-broker with Apache License 2.0 5 votes vote down vote up
protected void sendMessageToClient(Buffer bytes, WriteStream<Buffer> writer, ReadStream<Buffer> reader) {
    try {
        writer.write(bytes);
        if (writer.writeQueueFull()) {
            reader.pause();
            writer.drainHandler( done -> reader.resume() );
        }
    } catch(Throwable e) {
        logger.error(e.getMessage());
    }
}
 
Example 4
Source File: ReadStreamPart.java    From servicecomb-java-chassis with Apache License 2.0 4 votes vote down vote up
public ReadStreamPart(Context context, ReadStream<Buffer> readStream) {
  this.context = context;
  this.readStream = readStream;

  readStream.pause();
}
 
Example 5
Source File: ObservableReadStream.java    From vertx-rx with Apache License 2.0 3 votes vote down vote up
public ObservableReadStream(ReadStream<T> stream, Function<T, R> adapter, long maxBufferSize) {

    stream.pause();

    this.stream = stream;
    this.adapter = adapter;
  }