NetSocketInternal so = (NetSocketInternal) handshake(req); if (so != null) { so.channelHandlerContext().pipeline().addBefore("handler", "encoder", new WebSocket13FrameEncoder(false)); so.channelHandlerContext().pipeline().addBefore("handler", "decoder", new WebSocket13FrameDecoder(true, false, 1000)); Deque<Object> received = new ArrayDeque<>(); so.messageHandler(received::add);
handshake(res -> { NetSocketInternal so = (NetSocketInternal) res; so.channelHandlerContext().pipeline().addBefore("handler", "encoder", new WebSocket13FrameEncoder(true)); so.channelHandlerContext().pipeline().addBefore("handler", "decoder", new WebSocket13FrameDecoder(false, false, 1000)); int status = 4000 + TestUtils.randomPositiveInt() % 100; String reason = TestUtils.randomAlphaString(10);
NetSocketInternal soInt = (NetSocketInternal) so; assertEquals(expectSSL, soInt.isSsl()); ChannelHandlerContext chctx = soInt.channelHandlerContext(); ChannelPipeline pipeline = chctx.pipeline(); pipeline.addBefore("handler", "http", new HttpClientCodec());
NetSocketInternal internal = (NetSocketInternal) so; assertEquals(expectSSL, internal.isSsl()); ChannelHandlerContext chctx = internal.channelHandlerContext(); ChannelPipeline pipeline = chctx.pipeline(); pipeline.addBefore("handler", "http", new HttpServerCodec());
public MqttServerConnection(NetSocketInternal so, MqttServerOptions options) { this.so = so; this.chctx = so.channelHandlerContext(); this.options = options; }
public MqttServerConnection(NetSocketInternal so, MqttServerOptions options) { this.so = so; this.chctx = so.channelHandlerContext(); this.options = options; }
NetSocketInternal so = (NetSocketInternal) handshake(req); if (so != null) { so.channelHandlerContext().pipeline().addBefore("handler", "encoder", new WebSocket13FrameEncoder(false)); so.channelHandlerContext().pipeline().addBefore("handler", "decoder", new WebSocket13FrameDecoder(true, false, 1000)); Deque<Object> received = new ArrayDeque<>(); so.messageHandler(received::add);
handshake(request, res -> { NetSocketInternal so = (NetSocketInternal) res; so.channelHandlerContext().pipeline().addBefore("handler", "encoder", new WebSocket13FrameEncoder(true)); so.channelHandlerContext().pipeline().addBefore("handler", "decoder", new WebSocket13FrameDecoder(false, false, 1000)); int status = 4000 + TestUtils.randomPositiveInt() % 100; String reason = TestUtils.randomAlphaString(10);
NetSocketInternal soInt = (NetSocketInternal) so; assertEquals(expectSSL, soInt.isSsl()); ChannelHandlerContext chctx = soInt.channelHandlerContext(); ChannelPipeline pipeline = chctx.pipeline(); pipeline.addBefore("handler", "http", new HttpClientCodec());
NetSocketInternal internal = (NetSocketInternal) so; assertEquals(expectSSL, internal.isSsl()); ChannelHandlerContext chctx = internal.channelHandlerContext(); ChannelPipeline pipeline = chctx.pipeline(); pipeline.addBefore("handler", "http", new HttpServerCodec());
void flush() { boolean done = false; while (!done) { ByteBuffer outputBuffer = transport.getOutputBuffer(); if (outputBuffer != null && outputBuffer.hasRemaining()) { final NetSocketInternal internal = (NetSocketInternal) socket; final ByteBuf bb = internal.channelHandlerContext().alloc().directBuffer(outputBuffer.remaining()); bb.writeBytes(outputBuffer); internal.writeMessage(bb); transport.outputConsumed(); } else { done = true; } } }
void upgradeToSSLConnection(Handler<AsyncResult<Void>> completionHandler) { ChannelPipeline pipeline = socket.channelHandlerContext().pipeline(); Future<Void> upgradeFuture = Future.future(); upgradeFuture.setHandler(ar->{ if (ar.succeeded()) { completionHandler.handle(Future.succeededFuture()); } else { Throwable cause = ar.cause(); if (cause instanceof DecoderException) { DecoderException err = (DecoderException) cause; cause = err.getCause(); } completionHandler.handle(Future.failedFuture(cause)); } }); pipeline.addBefore("handler", "initiate-ssl-handler", new InitiateSslHandler(this, upgradeFuture)); }
void initializeCodec() { decoder = new MessageDecoder(inflight, socket.channelHandlerContext().alloc()); encoder = new MessageEncoder(socket.channelHandlerContext()); ChannelPipeline pipeline = socket.channelHandlerContext().pipeline(); pipeline.addBefore("handler", "decoder", decoder); socket.closeHandler(this::handleClosed); socket.exceptionHandler(this::handleException); socket.messageHandler(msg -> { try { handleMessage(msg); } catch (Exception e) { handleException(e); } }); }
void upgradeToSSLConnection(Handler<AsyncResult<Void>> completionHandler) { ChannelPipeline pipeline = socket.channelHandlerContext().pipeline(); Future<Void> upgradeFuture = Future.future(); upgradeFuture.setHandler(ar->{ if (ar.succeeded()) { completionHandler.handle(Future.succeededFuture()); } else { Throwable cause = ar.cause(); if (cause instanceof DecoderException) { DecoderException err = (DecoderException) cause; cause = err.getCause(); } completionHandler.handle(Future.failedFuture(cause)); } }); pipeline.addBefore("handler", "initiate-ssl-handler", new InitiateSslHandler(this, upgradeFuture)); }
void initializeCodec() { decoder = new MessageDecoder(inflight, socket.channelHandlerContext().alloc()); encoder = new MessageEncoder(socket.channelHandlerContext()); ChannelPipeline pipeline = socket.channelHandlerContext().pipeline(); pipeline.addBefore("handler", "decoder", decoder); socket.closeHandler(this::handleClosed); socket.exceptionHandler(this::handleException); socket.messageHandler(msg -> { try { handleMessage(msg); } catch (Exception e) { handleException(e); } }); }
/** * Initialize the client, this will configure Netty's pipeline an set an handler to process the * decoded messages. */ private void init() { // Get the pipeline ChannelPipeline pipeline = so.channelHandlerContext().pipeline(); // Add the memcached message aggregator pipeline.addFirst("aggregator", new BinaryMemcacheObjectAggregator(Integer.MAX_VALUE)); // Add the memcached decoder pipeline.addFirst("memcached", new BinaryMemcacheClientCodec()); // Set the message handler to process memcached message so.messageHandler(this::processResponse); }
@Override public MqttServer listen(int port, String host, Handler<AsyncResult<MqttServer>> listenHandler) { Handler<MqttEndpoint> h1 = endpointHandler; Handler<Throwable> h2 = exceptionHandler; server.connectHandler(so -> { NetSocketInternal soi = (NetSocketInternal) so; ChannelPipeline pipeline = soi.channelHandlerContext().pipeline(); initChannel(pipeline); MqttServerConnection conn = new MqttServerConnection(soi, options); soi.messageHandler(msg -> { synchronized (conn) { conn.handleMessage(msg); } }); conn.init(h1, h2); }); server.listen(port, host, ar -> listenHandler.handle(ar.map(this))); return this; }
@Override public MqttServer listen(int port, String host, Handler<AsyncResult<MqttServer>> listenHandler) { Handler<MqttEndpoint> h1 = endpointHandler; Handler<Throwable> h2 = exceptionHandler; server.connectHandler(so -> { NetSocketInternal soi = (NetSocketInternal) so; ChannelPipeline pipeline = soi.channelHandlerContext().pipeline(); initChannel(pipeline); MqttServerConnection conn = new MqttServerConnection(soi, options); soi.messageHandler(msg -> { synchronized (conn) { conn.handleMessage(msg); } }); conn.init(h1, h2); }); server.listen(port, host, ar -> listenHandler.handle(ar.map(this))); return this; }
ChannelPipeline pipeline = soi.channelHandlerContext().pipeline(); this.connectHandler = connectHandler; this.ctx = Vertx.currentContext(); soi.messageHandler(msg -> this.handleMessage(soi.channelHandlerContext(), msg)); soi.closeHandler(v -> handleClosed());
ChannelPipeline pipeline = soi.channelHandlerContext().pipeline(); this.connectHandler = connectHandler; this.ctx = Vertx.currentContext(); soi.messageHandler(msg -> this.handleMessage(soi.channelHandlerContext(), msg)); soi.closeHandler(v -> handleClosed());