Java Code Examples for io.vertx.core.http.WebSocket#closeHandler()

The following examples show how to use io.vertx.core.http.WebSocket#closeHandler() . 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: EventBusBridgeWebsocketClientVerticle.java    From vertx-mqtt-broker with Apache License 2.0 5 votes vote down vote up
@Override
public void handle(WebSocket webSocket) {
    connecting = false;
    connected = true;
    logger.info("Bridge Client - connected to server [" + remoteBridgeHost + ":" + remoteBridgePort + "]");

    webSocket.write(Buffer.buffer( tenant + "\n" ));
    webSocket.write(Buffer.buffer( "START SESSION" + "\n" ));
    webSocket.pause();

    final EventBusWebsocketBridge ebnb = new EventBusWebsocketBridge(webSocket, vertx.eventBus(), address);
    webSocket.closeHandler(aVoid -> {
        logger.error("Bridge Client - closed connection from server [" + remoteBridgeHost + ":" + remoteBridgePort + "]" + webSocket.textHandlerID());
        ebnb.stop();
        connected = false;
    });
    webSocket.exceptionHandler(throwable -> {
        logger.error("Bridge Client - Exception: " + throwable.getMessage(), throwable);
        ebnb.stop();
        connected = false;
    });
    ebnb.setTenant(tenant);
    ebnb.start();

    logger.info("Bridge Client - bridgeUUID: "+ ebnb.getBridgeUUID());
    webSocket.resume();
}