synchronized void registerEventBusHandler() { Handler<Message<Buffer>> writeHandler = msg -> write(msg.body()); registration = vertx.eventBus().<Buffer>localConsumer(writeHandlerID).handler(writeHandler); }
private void handshakeComplete(ChannelHandlerContext ctx, FullHttpResponse response) { handshaking = false; ChannelHandler handler = ctx.pipeline().get(HttpContentDecompressor.class); if (handler != null) { // remove decompressor as its not needed anymore once connection was upgraded to websockets ctx.pipeline().remove(handler); } WebSocketImpl webSocket = new WebSocketImpl(vertx, Http1xClientConnection.this, supportsContinuation, options.getMaxWebsocketFrameSize(), options.getMaxWebsocketMessageSize()); ws = webSocket; handshaker.finishHandshake(chctx.channel(), response); ws.subProtocol(handshaker.actualSubprotocol()); context.executeFromIO(v -> { log.debug("WebSocket handshake complete"); if (metrics != null ) { webSocket.setMetric(metrics.connected(endpointMetric, metric(), webSocket)); } webSocket.registerHandler(vertx.eventBus()); wsConnect.handle(webSocket); }); } }
ServerWebSocketImpl createWebSocket(HttpServerRequestImpl request) { if (ws != null) { return ws; } if (!(request.getRequest() instanceof FullHttpRequest)) { throw new IllegalStateException(); } FullHttpRequest nettyReq = (FullHttpRequest) request.getRequest(); WebSocketServerHandshaker handshaker = createHandshaker(nettyReq); if (handshaker == null) { return null; } Function<ServerWebSocketImpl, String> f = ws -> { handshaker.handshake(chctx.channel(), nettyReq); // remove compressor as its not needed anymore once connection was upgraded to websockets ChannelHandler handler = chctx.pipeline().get(HttpChunkContentCompressor.class); if (handler != null) { chctx.pipeline().remove(handler); } ws.registerHandler(vertx.eventBus()); return handshaker.selectedSubprotocol(); }; ws = new ServerWebSocketImpl(vertx, request.uri(), request.path(), request.query(), request.headers(), this, handshaker.version() != WebSocketVersion.V00, f, options.getMaxWebsocketFrameSize(), options.getMaxWebsocketMessageSize()); if (METRICS_ENABLED && metrics != null) { ws.setMetric(metrics.connected(metric(), request.metric(), ws)); } return ws; }
vertx = (VertxInternal) vertices[0]; vertx.eventBus().<String>consumer("control", msg -> { switch (msg.body()) { case "start": vertx.eventBus().publish("ping", message1); assertEqualsEventually("All pongs", Long.valueOf(NODE_COUNT * NODE_COUNT * ADDRESSES_COUNT), pongsReceived::get); vertx.eventBus().publish("ping", message2); assertEqualsEventually("Survivor pongs", Long.valueOf(ADDRESSES_COUNT), pongsReceived::get); vertx.eventBus().publish("ping", message3); assertEqualsEventually("Dead errors", Long.valueOf((NODE_COUNT - 1) * ADDRESSES_COUNT), noHandlersErrors::get);
synchronized void registerEventBusHandler() { Handler<Message<Buffer>> writeHandler = msg -> write(msg.body()); registration = vertx.eventBus().<Buffer>localConsumer(writeHandlerID).handler(writeHandler); }
private void handshakeComplete(ChannelHandlerContext ctx, FullHttpResponse response) { handshaking = false; ChannelHandler handler = ctx.pipeline().get(HttpContentDecompressor.class); if (handler != null) { // remove decompressor as its not needed anymore once connection was upgraded to websockets ctx.pipeline().remove(handler); } WebSocketImpl webSocket = new WebSocketImpl(vertx, Http1xClientConnection.this, supportsContinuation, options.getMaxWebsocketFrameSize(), options.getMaxWebsocketMessageSize()); ws = webSocket; handshaker.finishHandshake(chctx.channel(), response); ws.subProtocol(handshaker.actualSubprotocol()); context.executeFromIO(v -> { log.debug("WebSocket handshake complete"); if (metrics != null ) { webSocket.setMetric(metrics.connected(endpointMetric, metric(), webSocket)); } webSocket.registerHandler(vertx.eventBus()); wsConnect.handle(webSocket); }); } }
ServerWebSocketImpl createWebSocket(HttpServerRequestImpl request) { if (ws != null) { return ws; } if (!(request.getRequest() instanceof FullHttpRequest)) { throw new IllegalStateException(); } FullHttpRequest nettyReq = (FullHttpRequest) request.getRequest(); WebSocketServerHandshaker handshaker = createHandshaker(nettyReq); if (handshaker == null) { return null; } Function<ServerWebSocketImpl, String> f = ws -> { handshaker.handshake(chctx.channel(), nettyReq); // remove compressor as its not needed anymore once connection was upgraded to websockets ChannelHandler handler = chctx.pipeline().get(HttpChunkContentCompressor.class); if (handler != null) { chctx.pipeline().remove(handler); } ws.registerHandler(vertx.eventBus()); return handshaker.selectedSubprotocol(); }; ws = new ServerWebSocketImpl(vertx, request.uri(), request.path(), request.query(), request.headers(), this, handshaker.version() != WebSocketVersion.V00, f, options.getMaxWebsocketFrameSize(), options.getMaxWebsocketMessageSize()); if (METRICS_ENABLED && metrics != null) { ws.setMetric(metrics.connected(metric(), request.metric(), ws)); } return ws; }
vertx = (VertxInternal) vertices[0]; vertx.eventBus().<String>consumer("control", msg -> { switch (msg.body()) { case "start": vertx.eventBus().publish("ping", message1); assertEqualsEventually("All pongs", Long.valueOf(NODE_COUNT * NODE_COUNT * ADDRESSES_COUNT), pongsReceived::get); vertx.eventBus().publish("ping", message2); assertEqualsEventually("Survivor pongs", Long.valueOf(ADDRESSES_COUNT), pongsReceived::get); vertx.eventBus().publish("ping", message3); assertEqualsEventually("Dead errors", Long.valueOf((NODE_COUNT - 1) * ADDRESSES_COUNT), noHandlersErrors::get);