Package io.vertx.rxcore.java.impl

Examples of io.vertx.rxcore.java.impl.Regulator


      public void handle(Message<Integer> msg) {
        sendBatch(msg, msg.body(), 10);
      }
    });

    Regulator regulator=new Regulator<>();

    Observable<RxStream<Integer,JsonArray>> res=rx.<Integer,JsonArray>observeStream("countdown", 4000)
      // Add the regulator gate here
      .lift(regulator)
      // Process the stream
      .map(new Func1<RxStream<Integer, JsonArray>, JsonArray>() {
        public JsonArray call(RxStream<Integer, JsonArray> s) {
          int start = s.value().get(0);
          if (start > 0) {
            s.next(start - 10);
          }
          return s.value();
        }
      })
      .map(new Func1<JsonArray, Buffer>() {
        public Buffer call(JsonArray data) {
          return new Buffer(data.encode());
        }
      });

    // Create a WriteStream that can only handle 5 writes per second
    RatedWriteStream out=new RatedWriteStream(vertx,5);

    assertCountThenComplete(regulator.stream(res,out),401);
  }
View Full Code Here

TOP

Related Classes of io.vertx.rxcore.java.impl.Regulator

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.