List of usage examples for io.netty.channel ChannelPipeline remove
<T extends ChannelHandler> T remove(Class<T> handlerType);
From source file:com.heliosapm.tsdblite.handlers.http.HttpRequestManager.java
License:Apache License
/** * {@inheritDoc}/*from w w w .j a va 2 s . c o m*/ * @see io.netty.channel.SimpleChannelInboundHandler#channelRead0(io.netty.channel.ChannelHandlerContext, java.lang.Object) */ @Override protected void channelRead0(final ChannelHandlerContext ctx, final HttpRequest msg) throws Exception { try { final String uri = msg.uri(); final Channel channel = ctx.channel(); if (uri.endsWith("/favicon.ico")) { final DefaultFullHttpResponse resp = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK, favicon); resp.headers().set(HttpHeaders.CONTENT_TYPE, "image/x-icon"); resp.headers().setInt(HttpHeaders.CONTENT_LENGTH, favSize); ctx.writeAndFlush(resp); return; } else if (uri.equals("/api/put") || uri.equals("/api/metadata")) { final ChannelPipeline p = ctx.pipeline(); // p.addLast(loggingHandler, jsonAdapter, new JsonObjectDecoder(true), traceHandler); p.addLast(jsonAdapter, new JsonObjectDecoder(true), traceHandler); // if(msg instanceof FullHttpRequest) { // ByteBuf b = ((FullHttpRequest)msg).content().copy(); // ctx.fireChannelRead(b); // } ctx.fireChannelRead(msg); p.remove("requestManager"); log.info("Switched to JSON Trace Processor"); return; } final TSDBHttpRequest r = new TSDBHttpRequest(msg, ctx.channel(), ctx); final HttpRequestHandler handler = requestHandlers.get(r.getRoute()); if (handler == null) { r.send404().addListener(new GenericFutureListener<Future<? super Void>>() { public void operationComplete(Future<? super Void> f) throws Exception { log.info("404 Not Found for {} Complete: success: {}", r.getRoute(), f.isSuccess()); if (!f.isSuccess()) { log.error("Error sending 404", f.cause()); } }; }); return; } handler.process(r); } catch (Exception ex) { log.error("HttpRequest Routing Error", ex); } }
From source file:com.heliosapm.tsdblite.handlers.http.HttpSwitch.java
License:Apache License
@Override protected void decode(final ChannelHandlerContext ctx, final HttpRequest msg, final List<Object> out) throws Exception { final String uri = msg.uri(); log.info("-----------------------> URI [{}]", uri); if (uri.endsWith("/favicon.ico")) { final DefaultFullHttpResponse resp = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK, favicon); resp.headers().set(HttpHeaders.CONTENT_TYPE, "image/x-icon"); resp.headers().setInt(HttpHeaders.CONTENT_LENGTH, favSize); ctx.writeAndFlush(resp);//from w w w .j ava 2 s .co m return; } ReferenceCountUtil.retain(msg); final ChannelPipeline p = ctx.pipeline(); final int index = uri.indexOf("/api/"); final String endpoint = index == -1 ? "" : uri.substring(5); if (index != -1 && pureJsonEndPoints.contains(endpoint)) { log.info("Switching to PureJSON handler"); p.addLast(eventExecutorGroup, "httpToJson", httpToJson); // p.addLast("jsonLogger", loggingHandler); p.addLast("jsonDecoder", new JsonObjectDecoder(true)); // p.addLast("jsonLogger", loggingHandler); p.addLast("traceHandler", traceHandler); p.remove(this); if (msg instanceof FullHttpMessage) { out.add(msg); } } else { log.info("Switching to Http Request Manager"); out.add(msg); p.addLast(eventExecutorGroup, "requestManager", HttpRequestManager.getInstance()); p.remove(this); } }
From source file:com.heliosapm.tsdblite.handlers.ProtocolSwitch.java
License:Apache License
private void enableGzip(ChannelHandlerContext ctx) { ChannelPipeline p = ctx.pipeline(); p.addLast("gzipdeflater", ZlibCodecFactory.newZlibEncoder(ZlibWrapper.GZIP)); p.addLast("gzipinflater", ZlibCodecFactory.newZlibDecoder(ZlibWrapper.GZIP)); p.addLast("2ndPhaseSwitch", new ProtocolSwitch(false)); p.remove(this); log.info("enabled gzip: [{}]", ctx.channel().id()); }
From source file:com.heliosapm.tsdblite.handlers.ProtocolSwitch.java
License:Apache License
private void switchToHttp(ChannelHandlerContext ctx) { ChannelPipeline p = ctx.pipeline(); //p.addLast("logging", loggingHandler); // p.addLast(new HttpObjectAggregator(1048576)); final HttpServerCodec sourceCodec = new HttpServerCodec(); p.addLast("httpCodec", sourceCodec); // HttpServerUpgradeHandler.UpgradeCodec upgradeCodec = new Http2ServerUpgradeCodec(new HelloWorldHttp2Handler()); // HttpServerUpgradeHandler upgradeHandler = new HttpServerUpgradeHandler(sourceCodec, Collections.singletonList(upgradeCodec), 65536); // p.addLast("http2Upgrader", upgradeHandler); // p.addLast("encoder", new HttpResponseEncoder()); // p.addLast("decoder", new HttpRequestDecoder()); // p.addLast("deflater", new HttpContentCompressor(1)); p.addLast("inflater", new HttpContentDecompressor()); //p.addLast("logging", loggingHandler); //p.addLast("encoder", new HttpResponseEncoder()); //p.addLast("logging", loggingHandler); // p.addLast("logging", loggingHandler); //WebSocketServerHandler //p.addLast(eventExecutorGroup, "requestManager", new WebSocketServerHandler()); p.addLast(new HttpObjectAggregator(1048576 * 2)); p.addLast("httpSwitch", HTTP_SWITCH); // p.addLast(eventExecutorGroup, "requestManager", HttpRequestManager.getInstance()); // p.addLast("requestManager", HttpRequestManager.getInstance()); p.remove(this); }
From source file:com.heliosapm.tsdblite.handlers.ProtocolSwitch.java
License:Apache License
private void switchToPlainText(ChannelHandlerContext ctx) { ChannelPipeline p = ctx.pipeline(); p.addLast("framer", new LineBasedFrameDecoder(1024)); p.addLast("encoder", PLAINTEXT_ENCODER); p.addLast("decoder", PLAINTEXT_DECODER); p.addLast("traceDecoder", TRACE_DECODER); p.remove(this); log.info("switched to plain text: [{}]", ctx.channel().id()); }
From source file:com.hzmsc.scada.Jmtis.server.PortUnificationServerHandler.java
License:Apache License
private void switchToHttp(ChannelHandlerContext ctx) { ChannelPipeline p = ctx.pipeline(); p.addLast("decoder", new HttpRequestDecoder()); p.addLast("encoder", new HttpResponseEncoder()); p.addLast("deflater", new HttpContentCompressor()); p.addLast("handler", new HttpHelloWorldServerHandler()); p.remove(this); }
From source file:com.hzmsc.scada.Jmtis.server.PortUnificationServerHandler.java
License:Apache License
private void switchToJMAC(ChannelHandlerContext ctx) { ChannelPipeline pipeline = ctx.pipeline(); pipeline.addLast(new LengthFieldBasedFrameDecoder(1024, 4, 4)); pipeline.addLast(new JmtisDecoder()); pipeline.addLast(new JmtisHeaderEncoder()); pipeline.addLast(new JmtisBodyEncoder()); pipeline.addLast(new JmtisServerHandler()); pipeline.remove(this); }
From source file:com.jroossien.boxx.util.protocol.TinyProtocol.java
License:Open Source License
private void unregisterChannelHandler() { if (serverChannelHandler == null) return;//w w w .j ava 2s . c om for (Channel serverChannel : serverChannels) { final ChannelPipeline pipeline = serverChannel.pipeline(); // Remove channel handler serverChannel.eventLoop().execute(new Runnable() { @Override public void run() { try { pipeline.remove(serverChannelHandler); } catch (NoSuchElementException e) { // That's fine } } }); } }
From source file:com.lambdaworks.redis.PlainChannelInitializer.java
License:Apache License
static void removeIfExists(ChannelPipeline pipeline, Class<? extends ChannelHandler> handlerClass) { ChannelHandler channelHandler = pipeline.get(handlerClass); if (channelHandler != null) { pipeline.remove(channelHandler); }/*from w w w . j ava 2 s. c o m*/ }
From source file:com.linecorp.armeria.client.http.HttpClientPipelineConfigurator.java
License:Apache License
@Override public void connect(ChannelHandlerContext ctx, SocketAddress remoteAddress, SocketAddress localAddress, ChannelPromise promise) throws Exception { // Remember the requested remote address for later use. this.remoteAddress = (InetSocketAddress) remoteAddress; // Configure the pipeline. final Channel ch = ctx.channel(); final ChannelPipeline p = ch.pipeline(); p.addLast(new FlushConsolidationHandler()); p.addLast(ReadSuppressingHandler.INSTANCE); try {/*from ww w .jav a2 s .co m*/ if (sslCtx != null) { configureAsHttps(ch); } else { configureAsHttp(ch); } } catch (Throwable t) { promise.tryFailure(t); ctx.close(); } finally { if (p.context(this) != null) { p.remove(this); } } ctx.connect(remoteAddress, localAddress, promise); }