List of usage examples for io.netty.channel ChannelPipeline remove
<T extends ChannelHandler> T remove(Class<T> handlerType);
From source file:io.liveoak.container.protocols.PipelineConfigurator.java
License:Open Source License
public void switchToHttpWebSockets(ChannelPipeline pipeline) { if (pipeline.get("protocol-detector") != null) { pipeline.remove("protocol-detector"); }/*w ww .j a v a 2 s . co m*/ //pipeline.addLast(new DebugHandler("server-pre-http")); AnalyticsBandwidthHandler analyticsHandler = null; AnalyticsService analyticsService = AnalyticsService.instance(); if (analyticsService != null && analyticsService.enabled()) { analyticsHandler = new AnalyticsBandwidthHandler(analyticsService); pipeline.addLast("analytics-handler", analyticsHandler); } pipeline.addLast(new HttpRequestDecoder()); pipeline.addLast(new HttpResponseEncoder()); if (analyticsHandler != null) { pipeline.addLast(new AnalyticsResponseHandler(analyticsHandler)); } //pipeline.addLast( new DebugHandler( "server-post-http" ) ); //pipeline.addLast(new HttpObjectAggregator(1024 * 1024)); //TODO: Remove this to support chunked http pipeline.addLast("ws-handshake", new WebSocketHandshakerHandler(this)); }
From source file:io.liveoak.container.protocols.PipelineConfigurator.java
License:Open Source License
public void switchToWebSockets(ChannelPipeline pipeline) { pipeline.remove(WebSocketHandshakerHandler.class); //pipeline.addLast( new DebugHandler( "networkServer-1" ) ); pipeline.addLast(new WebSocketStompFrameDecoder()); pipeline.addLast(new WebSocketStompFrameEncoder()); StompServerContext serverContext = new SecuredStompServerContext(this.codecManager, this.subscriptionManager, this.client); // handle frames pipeline.addLast(new ConnectHandler(serverContext)); pipeline.addLast(new DisconnectHandler(serverContext)); pipeline.addLast(new SubscribeHandler(serverContext)); pipeline.addLast(new UnsubscribeHandler(serverContext)); // convert some frames to messages pipeline.addLast(new ReceiptHandler()); pipeline.addLast(new StompMessageDecoder()); pipeline.addLast(new StompMessageEncoder(true)); // place analytics handler in stomp pipeline to another position - it's now twice in the pipeline AnalyticsBandwidthHandler handler = (AnalyticsBandwidthHandler) pipeline.get("analytics-handler"); if (handler != null) { pipeline.addLast(new AnalyticsNotificationHandler(handler)); }/*from w w w .j a v a 2 s . c o m*/ // handle messages pipeline.addLast(new SendHandler(serverContext)); // catch errors, return an ERROR message. pipeline.addLast(new StompErrorHandler()); }
From source file:io.liveoak.container.protocols.PipelineConfigurator.java
License:Open Source License
public void switchToPlainHttp(ChannelPipeline pipeline) { // turn off automatic socket read for better http body read control pipeline.addLast("channel-resetter", new ChannelResetterHandler(this)); pipeline.channel().config().setAutoRead(false); pipeline.remove(WebSocketHandshakerHandler.class); //pipeline.addLast(new DebugHandler("server-pre-cors")); pipeline.addLast("cors-origin-handler", new CORSHandler()); pipeline.addLast("cors-preflight-handler", new CORSPreflightOptionsHandler()); //pipeline.addLast( new DebugHandler( "server-post-cors" ) ); pipeline.addLast("deflater", new HttpContentCompressor(1)); pipeline.addLast("http-resource-decoder", new HttpResourceRequestDecoder(this.codecManager)); pipeline.addLast("http-resource-encoder", new HttpResourceResponseEncoder(this.codecManager)); pipeline.addLast("http-request-body-handler", new HttpRequestBodyHandler()); pipeline.addLast("interceptor", new InterceptorHandler("http", this.interceptorManager)); pipeline.addLast("request-context-disposer", new RequestContextDisposerHandler()); //pipeline.addLast("auth-handler", new AuthHandler(this.client)); //pipeline.addLast("authz-handler", new AuthzHandler(this.client)); pipeline.addLast("subscription-watcher", new SubscriptionWatcher(this.subscriptionManager)); //pipeline.addLast( new DebugHandler( "server-debug" ) ); pipeline.addLast("resource-state-handler", new ResourceStateHandler(this.workerPool)); pipeline.addLast("object-handler", new ResourceHandler(this.globalContext, this.workerPool)); pipeline.addLast("error-handler", new ErrorHandler()); }
From source file:io.moquette.spi.impl.ProtocolProcessor.java
License:Open Source License
private void setIdleTime(ChannelPipeline pipeline, int idleTime) { if (pipeline.names().contains("idleStateHandler")) { pipeline.remove("idleStateHandler"); }//ww w . j av a 2 s.c o m pipeline.addFirst("idleStateHandler", new IdleStateHandler(0, 0, idleTime)); }
From source file:io.reactivex.netty.protocol.http.websocket.WebSocketClientHandler.java
License:Apache License
private void finishHandshake(ChannelHandlerContext ctx, FullHttpResponse msg, Channel ch) { try {//from ww w . ja v a 2s . c o m handshaker.finishHandshake(ch, msg); } catch (WebSocketHandshakeException e) { eventsSubject.onEvent(WebSocketClientMetricsEvent.HANDSHAKE_FAILURE, Clock.onEndMillis(handshakeStartTime)); handshakeFuture.setFailure(e); ctx.close(); return; } eventsSubject.onEvent(WebSocketClientMetricsEvent.HANDSHAKE_SUCCESS, Clock.onEndMillis(handshakeStartTime)); ChannelPipeline p = ctx.pipeline(); ChannelHandlerContext nettyDecoderCtx = p.context(WebSocketFrameDecoder.class); p.addAfter(nettyDecoderCtx.name(), "websocket-read-metrics", new ClientReadMetricsHandler(eventsSubject)); ChannelHandlerContext nettyEncoderCtx = p.context(WebSocketFrameEncoder.class); p.addAfter(nettyEncoderCtx.name(), "websocket-write-metrics", new ClientWriteMetricsHandler(eventsSubject)); if (messageAggregation) { p.addAfter("websocket-read-metrics", "websocket-frame-aggregator", new WebSocketFrameAggregator(maxFramePayloadLength)); } p.remove(HttpObjectAggregator.class); p.remove(this); handshakeFuture.setSuccess(); }
From source file:io.reactivex.netty.protocol.http.websocket.WebSocketServerHandler.java
License:Apache License
private void updatePipeline(ChannelHandlerContext ctx) { ChannelPipeline p = ctx.pipeline(); ChannelHandlerContext nettyEncoderCtx = p.context(WebSocketFrameEncoder.class); p.addAfter(nettyEncoderCtx.name(), "websocket-write-metrics", new ServerWriteMetricsHandler(eventsSubject)); ChannelHandlerContext nettyDecoderCtx = p.context(WebSocketFrameDecoder.class); p.addAfter(nettyDecoderCtx.name(), "websocket-read-metrics", new ServerReadMetricsHandler(eventsSubject)); if (messageAggregator) { p.addAfter("websocket-read-metrics", "websocket-frame-aggregator", new WebSocketFrameAggregator(maxFramePayloadLength)); }//from w w w . j ava 2s . c o m p.remove(this); }
From source file:io.vertx.core.http.impl.ClientConnection.java
License:Open Source License
public NetSocket createNetSocket() { // connection was upgraded to raw TCP socket NetSocketImpl socket = new NetSocketImpl(vertx, channel, context, client.getSslHelper(), metrics); socket.metric(metric());// w w w . j a v a2s . co m Map<Channel, NetSocketImpl> connectionMap = new HashMap<>(1); connectionMap.put(channel, socket); // Flush out all pending data endReadAndFlush(); // remove old http handlers and replace the old handler with one that handle plain sockets ChannelPipeline pipeline = channel.pipeline(); ChannelHandler inflater = pipeline.get(HttpContentDecompressor.class); if (inflater != null) { pipeline.remove(inflater); } pipeline.remove("codec"); pipeline.replace("handler", "handler", new VertxNetHandler<NetSocketImpl>(channel, socket, connectionMap) { @Override public void exceptionCaught(ChannelHandlerContext chctx, Throwable t) throws Exception { // remove from the real mapping pool.removeChannel(channel); super.exceptionCaught(chctx, t); } @Override public void channelInactive(ChannelHandlerContext chctx) throws Exception { // remove from the real mapping pool.removeChannel(channel); super.channelInactive(chctx); } @Override public void channelRead(ChannelHandlerContext chctx, Object msg) throws Exception { if (msg instanceof HttpContent) { if (msg instanceof LastHttpContent) { handleResponseEnd((LastHttpContent) msg); } ReferenceCountUtil.release(msg); return; } super.channelRead(chctx, msg); } @Override protected void handleMsgReceived(NetSocketImpl conn, Object msg) { ByteBuf buf = (ByteBuf) msg; conn.handleDataReceived(Buffer.buffer(buf)); } }); return socket; }
From source file:io.vertx.core.http.impl.Http1xClientConnection.java
License:Open Source License
private synchronized NetSocket upgrade(StreamImpl stream) { if (options.isPipelining()) { throw new IllegalStateException("Cannot upgrade a pipe-lined request"); }// ww w . jav a2 s. c o m if (upgraded) { throw new IllegalStateException("Request already upgraded to NetSocket"); } upgraded = true; // connection was upgraded to raw TCP socket AtomicBoolean paused = new AtomicBoolean(false); NetSocketImpl socket = new NetSocketImpl(vertx, chctx, context, client.getSslHelper(), metrics) { { super.pause(); } @Override public synchronized NetSocket handler(Handler<Buffer> dataHandler) { return super.handler(dataHandler); } @Override public synchronized NetSocket pause() { paused.set(true); return super.pause(); } @Override public synchronized NetSocket resume() { paused.set(false); return super.resume(); } }; socket.metric(metric()); // Flush out all pending data endReadAndFlush(); // remove old http handlers and replace the old handler with one that handle plain sockets ChannelPipeline pipeline = chctx.pipeline(); ChannelHandler inflater = pipeline.get(HttpContentDecompressor.class); if (inflater != null) { pipeline.remove(inflater); } pipeline.replace("handler", "handler", new VertxNetHandler(socket) { @Override public void channelRead(ChannelHandlerContext chctx, Object msg) throws Exception { if (msg instanceof HttpContent) { if (msg instanceof LastHttpContent) { stream.endResponse((LastHttpContent) msg); } ReferenceCountUtil.release(msg); return; } super.channelRead(chctx, msg); } }.removeHandler(sock -> listener.onDiscard())); // Removing this codec might fire pending buffers in the HTTP decoder // this happens when the channel reads the HTTP response and the following data in a single buffer pipeline.remove("codec"); // Async check to deliver the pending messages // because the netSocket access in HttpClientResponse is synchronous // we need to pause the NetSocket to avoid losing or reordering buffers // and then asynchronously un-pause it unless it was actually paused by the application context.runOnContext(v -> { if (!paused.get()) { socket.resume(); } }); return socket; }
From source file:io.vertx.core.http.impl.Http1xServerConnection.java
License:Open Source License
NetSocket createNetSocket() { NetSocketImpl socket = new NetSocketImpl(vertx, chctx, context, sslHelper, metrics); socket.metric(metric());//from w w w. j a v a 2 s.c o m Map<Channel, NetSocketImpl> connectionMap = new HashMap<>(1); connectionMap.put(chctx.channel(), socket); // Flush out all pending data endReadAndFlush(); // remove old http handlers and replace the old handler with one that handle plain sockets ChannelPipeline pipeline = chctx.pipeline(); ChannelHandler compressor = pipeline.get(HttpChunkContentCompressor.class); if (compressor != null) { pipeline.remove(compressor); } pipeline.remove("httpDecoder"); if (pipeline.get("chunkedWriter") != null) { pipeline.remove("chunkedWriter"); } chctx.pipeline().replace("handler", "handler", new VertxNetHandler(socket) { @Override public void channelRead(ChannelHandlerContext chctx, Object msg) throws Exception { if (msg instanceof HttpContent) { ReferenceCountUtil.release(msg); return; } super.channelRead(chctx, msg); } }.removeHandler(sock -> { if (metrics != null) { metrics.responseEnd(responseInProgress.metric(), responseInProgress.response()); } connectionMap.remove(chctx.channel()); })); // check if the encoder can be removed yet or not. chctx.pipeline().remove("httpEncoder"); return socket; }
From source file:io.vertx.core.http.impl.HttpChannelConnector.java
License:Open Source License
@Override public void deactivate(HttpClientConnection conn) { if (options.getIdleTimeout() > 0) { ChannelPipeline pipeline = conn.channelHandlerContext().pipeline(); pipeline.remove("idle"); }//www.ja v a 2 s .co m }