List of usage examples for io.vertx.core.http HttpServer connectionHandler
@Fluent HttpServer connectionHandler(Handler<HttpConnection> handler);
From source file:examples.HTTP2Examples.java
License:Open Source License
public void example17(Vertx vertx, HttpServerOptions http2Options) { HttpServer server = vertx.createHttpServer(http2Options); server.connectionHandler(connection -> { System.out.println("A client connected"); });// www. j av a 2 s.c om }
From source file:org.apache.servicecomb.transport.rest.vertx.RestServerVerticle.java
License:Apache License
@Override public void start(Future<Void> startFuture) throws Exception { try {/*www .jav a2 s . co m*/ super.start(); // ???????? if (endpointObject == null) { LOGGER.warn("rest listen address is not configured, will not start."); startFuture.complete(); return; } Router mainRouter = Router.router(vertx); mountGlobalRestFailureHandler(mainRouter); mountAccessLogHandler(mainRouter); mountCorsHandler(mainRouter); initDispatcher(mainRouter); HttpServer httpServer = createHttpServer(); httpServer.requestHandler(mainRouter::accept); httpServer.connectionHandler(connection -> { int connectedCount = connectedCounter.incrementAndGet(); int connectionLimit = DynamicPropertyFactory.getInstance() .getIntProperty("servicecomb.rest.server.connection-limit", Integer.MAX_VALUE).get(); if (connectedCount > connectionLimit) { connectedCounter.decrementAndGet(); connection.close(); } else { EventManager.post(new ClientEvent(connection.remoteAddress().toString(), ConnectionEvent.Connected, TransportType.Rest, connectedCount)); connection.closeHandler(event -> EventManager .post(new ClientEvent(connection.remoteAddress().toString(), ConnectionEvent.Closed, TransportType.Rest, connectedCounter.decrementAndGet()))); } }); httpServer.exceptionHandler(e -> { LOGGER.error("Unexpected error in server.{}", ExceptionUtils.getExceptionMessageWithoutTrace(e)); }); startListen(httpServer, startFuture); } catch (Throwable e) { // vert.x got some states that not print error and execute call back in VertexUtils.blockDeploy, we add a log our self. LOGGER.error("", e); throw e; } }