List of usage examples for io.netty.channel ChannelPipeline remove
<T extends ChannelHandler> T remove(Class<T> handlerType);
From source file:dorkbox.network.connection.registration.remote.RegistrationRemoteHandler.java
License:Apache License
private void cleanupPipeline0(final int idleTimeout, final ChannelHandler connection, final Channel channel, final ChannelPromise channelPromise, final boolean isTcp) { final ChannelPipeline pipeline = channel.pipeline(); // have to explicitly remove handlers based on the input type. Cannot use this.getClass().... boolean isClient = registrationWrapper.isClient(); if (isClient) { if (isTcp) { pipeline.remove(RegistrationRemoteHandlerClientTCP.class); } else {// w w w . ja va 2s . c om pipeline.remove(RegistrationRemoteHandlerClientUDP.class); } } else { if (isTcp) { pipeline.remove(RegistrationRemoteHandlerServerTCP.class); } else { pipeline.remove(RegistrationRemoteHandlerServerUDP.class); } } pipeline.remove(ConnectionRegistrationImpl.class); if (idleTimeout > 0) { pipeline.replace(IDLE_HANDLER, IDLE_HANDLER_FULL, new IdleStateHandler(0, 0, idleTimeout, TimeUnit.MILLISECONDS)); } else { pipeline.remove(IDLE_HANDLER); } pipeline.addLast(CONNECTION_HANDLER, connection); // we also DEREGISTER from the HANDSHAKE event-loop and run on the worker event-loop! ChannelFuture future = channel.deregister(); future.addListener(new GenericFutureListener<Future<? super Void>>() { @Override public void operationComplete(final Future<? super Void> f) throws Exception { if (f.isSuccess()) { // TCP and UDP register on DIFFERENT event loops. The channel promise ONLY runs on 1 of them... if (channelPromise.channel() == channel) { workerEventLoop.register(channelPromise); } else { workerEventLoop.register(channel); } } } }); }
From source file:dpfmanager.shell.modules.server.core.HttpServerHandler.java
License:Open Source License
@Override protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception { // Will use the first five bytes to detect a protocol. if (in.readableBytes() < 5) { in.clear();// w w w . java 2 s .c o m ctx.close(); return; } final int magic1 = in.getUnsignedByte(in.readerIndex()); final int magic2 = in.getUnsignedByte(in.readerIndex() + 1); if (isPost(magic1, magic2) || isOptions(magic1, magic2)) { // POST ChannelPipeline pipeline = ctx.pipeline(); pipeline.addLast(new HttpRequestDecoder()); pipeline.addLast(new HttpResponseEncoder()); pipeline.addLast(new HttpPostHandler(context)); pipeline.remove(this); } else if (isGet(magic1, magic2)) { // GET ChannelPipeline pipeline = ctx.pipeline(); pipeline.addLast(new HttpServerCodec()); pipeline.addLast(new HttpObjectAggregator(65536)); pipeline.addLast(new ChunkedWriteHandler()); pipeline.addLast(new HttpGetHandler(context)); pipeline.remove(this); } else { in.clear(); ctx.close(); } }
From source file:io.advantageous.conekt.http.impl.ClientConnection.java
License:Open Source License
NetSocket createNetSocket() { // connection was upgraded to raw TCP socket NetSocketImpl socket = new NetSocketImpl(vertx, channel, context, client.getSslHelper(), true, metrics, metric);/* w w w . ja va 2 s.c om*/ 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 ConektNetHandler(connectionMap) { @Override public void exceptionCaught(ChannelHandlerContext chctx, Throwable t) throws Exception { // remove from the real mapping client.removeChannel(channel); super.exceptionCaught(chctx, t); } @Override public void channelInactive(ChannelHandlerContext chctx) throws Exception { // remove from the real mapping client.removeChannel(channel); super.channelInactive(chctx); } @Override public void channelRead(ChannelHandlerContext chctx, Object msg) throws Exception { if (msg instanceof HttpContent) { ReferenceCountUtil.release(msg); return; } super.channelRead(chctx, msg); } }); return socket; }
From source file:io.advantageous.conekt.http.impl.ServerConnection.java
License:Open Source License
NetSocket createNetSocket() { NetSocketImpl socket = new NetSocketImpl(vertx, channel, context, server.getSslHelper(), false, metrics, metric);/*from ww w . ja va 2 s . 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 compressor = pipeline.get(HttpChunkContentCompressor.class); if (compressor != null) { pipeline.remove(compressor); } pipeline.remove("httpDecoder"); if (pipeline.get("chunkedWriter") != null) { pipeline.remove("chunkedWriter"); } channel.pipeline().replace("handler", "handler", new ConektNetHandler(connectionMap) { @Override public void exceptionCaught(ChannelHandlerContext chctx, Throwable t) throws Exception { // remove from the real mapping server.removeChannel(channel); super.exceptionCaught(chctx, t); } @Override public void channelInactive(ChannelHandlerContext chctx) throws Exception { // remove from the real mapping server.removeChannel(channel); super.channelInactive(chctx); } @Override public void channelRead(ChannelHandlerContext chctx, Object msg) throws Exception { if (msg instanceof HttpContent) { ReferenceCountUtil.release(msg); return; } super.channelRead(chctx, msg); } }); // check if the encoder can be removed yet or not. if (lastWriteFuture == null) { channel.pipeline().remove("httpEncoder"); } else { lastWriteFuture.addListener(new ChannelFutureListener() { @Override public void operationComplete(ChannelFuture future) throws Exception { channel.pipeline().remove("httpEncoder"); } }); } return socket; }
From source file:io.airlift.drift.transport.netty.server.OptionalSslHandler.java
License:Apache License
@Override protected void decode(ChannelHandlerContext context, ByteBuf in, List<Object> out) { // minimum bytes required to detect ssl if (in.readableBytes() < SSL_RECORD_HEADER_LENGTH) { return;/* w w w . j a va 2s .c om*/ } ChannelPipeline pipeline = context.pipeline(); if (isTls(in, in.readerIndex())) { pipeline.replace(this, "ssl", sslContext.newHandler(context.alloc())); } else { pipeline.remove(this); } }
From source file:io.airlift.drift.transport.netty.server.ThriftProtocolDetection.java
License:Apache License
private void switchToTransport(ChannelHandlerContext context, Transport transport, Optional<Protocol> protocol) { ChannelPipeline pipeline = context.pipeline(); transport.addFrameHandlers(pipeline, protocol, maxFrameSize, assumeClientsSupportOutOfOrderResponses); pipeline.addLast(new ResponseOrderingHandler()); pipeline.addLast(thriftServerHandler); // remove(this) must be last because it triggers downstream processing of the current message pipeline.remove(this); }
From source file:io.aos.netty5.socksproxy.SocksPortUnificationServerHandler.java
License:Apache License
@Override protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception { ChannelPipeline p = ctx.pipeline(); SocksProtocolVersion version = SocksProtocolVersion.valueOf(in.readByte()); System.out.println(version);/*from w w w . j a va2 s .c o m*/ in.resetReaderIndex(); switch (version) { case SOCKS4a: p.addLast(new Socks4CmdRequestDecoder()); p.addLast(Socks4MessageEncoder.INSTANCE); break; case SOCKS5: p.addLast(new Socks5InitRequestDecoder()); p.addLast(Socks5MessageEncoder.INSTANCE); break; case UNKNOWN: in.clear(); ctx.close(); return; } p.addLast(SocksServerHandler.INSTANCE); p.remove(this); }
From source file:io.jsync.http.impl.ClientConnection.java
License:Open Source License
NetSocket createNetSocket() { // connection was upgraded to raw TCP socket upgradedConnection = true;//from w w w . j av a 2 s . co m DefaultNetSocket socket = new DefaultNetSocket(async, channel, context, client.tcpHelper, true); Map<Channel, DefaultNetSocket> connectionMap = new HashMap<Channel, DefaultNetSocket>(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 AsyncNetHandler(client.async, connectionMap) { @Override public void exceptionCaught(ChannelHandlerContext chctx, Throwable t) throws Exception { // remove from the real mapping client.connectionMap.remove(channel); super.exceptionCaught(chctx, t); } @Override public void channelInactive(ChannelHandlerContext chctx) throws Exception { // remove from the real mapping client.connectionMap.remove(channel); super.channelInactive(chctx); } @Override public void channelRead(ChannelHandlerContext chctx, Object msg) throws Exception { if (msg instanceof HttpContent) { ReferenceCountUtil.release(msg); return; } super.channelRead(chctx, msg); } }); return socket; }
From source file:io.jsync.http.impl.ServerConnection.java
License:Open Source License
NetSocket createNetSocket() { DefaultNetSocket socket = new DefaultNetSocket(async, channel, context, server.tcpHelper, false); Map<Channel, DefaultNetSocket> connectionMap = new HashMap<Channel, DefaultNetSocket>(1); connectionMap.put(channel, socket);//from w w w . j a va2 s .co m // 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 compressor = pipeline.get(HttpChunkContentCompressor.class); if (compressor != null) { pipeline.remove(compressor); } pipeline.remove("httpDecoder"); if (pipeline.get("chunkedWriter") != null) { pipeline.remove("chunkedWriter"); } channel.pipeline().replace("handler", "handler", new AsyncNetHandler(server.async, connectionMap) { @Override public void exceptionCaught(ChannelHandlerContext chctx, Throwable t) throws Exception { // remove from the real mapping server.connectionMap.remove(channel); super.exceptionCaught(chctx, t); } @Override public void channelInactive(ChannelHandlerContext chctx) throws Exception { // remove from the real mapping server.connectionMap.remove(channel); super.channelInactive(chctx); } @Override public void channelRead(ChannelHandlerContext chctx, Object msg) throws Exception { if (msg instanceof HttpContent) { ReferenceCountUtil.release(msg); return; } super.channelRead(chctx, msg); } }); // check if the encoder can be removed yet or not. if (lastWriteFuture == null) { channel.pipeline().remove("httpEncoder"); } else { lastWriteFuture.addListener(new ChannelFutureListener() { @Override public void operationComplete(ChannelFuture future) throws Exception { channel.pipeline().remove("httpEncoder"); } }); } return socket; }
From source file:io.liveoak.container.protocols.PipelineConfigurator.java
License:Open Source License
public void switchToPureStomp(ChannelPipeline pipeline) { if (pipeline.get("protocol-detector") != null) { pipeline.remove("protocol-detector"); }//from w ww . j ava2 s . c o m StompServerContext serverContext = new SecuredStompServerContext(this.codecManager, this.subscriptionManager, this.client); AnalyticsService analyticsService = AnalyticsService.instance(); AnalyticsBandwidthHandler analyticsHandler = null; if (analyticsService != null && analyticsService.enabled()) { analyticsHandler = new AnalyticsBandwidthHandler(analyticsService); pipeline.addLast("analytics-handler", analyticsHandler); } pipeline.addLast(new StompFrameDecoder()); pipeline.addLast(new StompFrameEncoder()); // 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)); if (analyticsHandler != null) { pipeline.addLast(new AnalyticsNotificationHandler(analyticsHandler)); } // handle messages pipeline.addLast(new SendHandler(serverContext)); // catch errors, return an ERROR message. pipeline.addLast(new StompErrorHandler()); }