Example usage for io.vertx.core.http HttpServerOptions getMaxWebsocketFrameSize

List of usage examples for io.vertx.core.http HttpServerOptions getMaxWebsocketFrameSize

Introduction

In this page you can find the example usage for io.vertx.core.http HttpServerOptions getMaxWebsocketFrameSize.

Prototype

public int getMaxWebsocketFrameSize() 

Source Link

Usage

From source file:io.sqp.proxy.ServerVerticle.java

License:Open Source License

@Override
public void start() {
    // TODO: set subprotocols

    JsonObject config = config();// w  w w . j a  v a 2 s. c o  m

    String path = config.getString("path", DEFAULT_PATH);
    int port = config.getInteger("port", DEFAULT_PORT);
    int poolSize = config.getInteger("connectionPoolSize", DEFAULT_POOL_SIZE);
    JsonArray backendConfs = config.getJsonArray("backends");
    _executorService = Executors.newFixedThreadPool(10); // TODO: set this reasonably

    // Initialize the backend connection pool
    BackendConnectionPool connectionPool = new VertxBackendConnectionPool(vertx, poolSize, backendConfs);

    try {
        connectionPool.init();
    } catch (ServerErrorException e) {
        _logger.log(Level.SEVERE, "Failed to create the connection pool", e);
        throw new RuntimeException(e.getMessage(), e.getCause());
    }

    HttpServerOptions options = new HttpServerOptions();
    int maxFrameSize = options.getMaxWebsocketFrameSize();

    // Create the actual server
    HttpServer server = vertx.createHttpServer(options);

    // For each incoming websocket connection: create a client connection object
    server.websocketHandler(socket -> {
        if (!socket.path().equals(path)) {
            socket.reject();
            return;
        }
        // TODO: check sub protocols
        new VertxClientConnection(_executorService, socket, connectionPool, maxFrameSize);
    });
    // start to listen
    server.listen(port, result -> {
        if (result.succeeded()) {
            _logger.log(Level.INFO, "Listening on port " + port + " and path '" + path + "'...");
            setStarted(true);
        } else {
            _logger.log(Level.SEVERE, "Failed to listen", result.cause());
            setStartingError(result.cause());
        }
    });
}