io.vertx.core.TimeoutStream Java Examples

The following examples show how to use io.vertx.core.TimeoutStream. 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: EthStatsReporter.java    From incubator-tuweni with Apache License 2.0 5 votes vote down vote up
private void reportPeriodically(WebSocket ws) {
  TimeoutStream reportingStream = vertx.periodicStream(REPORTING_PERIOD).handler(ev -> {
    report(ws);
  });
  TimeoutStream pingStream = vertx.periodicStream(PING_PERIOD).handler(ev -> {
    writePing(ws);
  });
  ws.closeHandler(h -> {
    reportingStream.cancel();
    pingStream.cancel();
    attemptConnect(null);
  });
}
 
Example #2
Source File: HttpServer.java    From vertx-in-action with MIT License 5 votes vote down vote up
private void sse(HttpServerRequest request) {
  HttpServerResponse response = request.response();
  response
    .putHeader("Content-Type", "text/event-stream")
    .putHeader("Cache-Control", "no-cache")
    .setChunked(true);

  MessageConsumer<JsonObject> consumer = vertx.eventBus().consumer("sensor.updates");
  consumer.handler(msg -> {
    response.write("event: update\n");
    response.write("data: " + msg.body().encode() + "\n\n");
  });


  TimeoutStream ticks = vertx.periodicStream(1000);
  ticks.handler(id -> {
    vertx.eventBus().<JsonObject>request("sensor.average", "", reply -> {
      if (reply.succeeded()) {
        response.write("event: average\n");
        response.write("data: " + reply.result().body().encode() + "\n\n");
      }
    });
  });

  response.endHandler(v -> {
    consumer.unregister();
    ticks.cancel();
  });
}
 
Example #3
Source File: SfsVertxImpl.java    From sfs with Apache License 2.0 4 votes vote down vote up
@Override
public TimeoutStream timerStream(long delay) {
    return vertx.timerStream(delay);
}
 
Example #4
Source File: SfsVertxImpl.java    From sfs with Apache License 2.0 4 votes vote down vote up
@Override
public TimeoutStream periodicStream(long delay) {
    return vertx.periodicStream(delay);
}