List of usage examples for io.netty.channel ChannelPipeline addLast
ChannelPipeline addLast(EventExecutorGroup group, ChannelHandler... handlers);
From source file:com.caricah.iotracah.server.netty.ServerInitializer.java
License:Apache License
/** * This method will be called once the {@link SocketChannel} was registered. After the method returns this instance * will be removed from the {@link ChannelPipeline} of the {@link SocketChannel}. * * @param ch the {@link SocketChannel} which was registered. * @throws Exception is thrown if an error occurs. In that case the {@link SocketChannel} will be closed. *///www . jav a2 s . c o m @Override protected void initChannel(SocketChannel ch) throws Exception { ChannelPipeline pipeline = ch.pipeline(); if (null != getSslContext()) { // Add SSL handler first to encrypt and decrypt everything. // In this application ssl is only used for transport encryption // Identification is not yet part of the deal. pipeline.addLast("ssl", getSslContext().newHandler(ch.alloc())); } customizePipeline(getIotEventExecutorGroup(), pipeline); }
From source file:com.chen.opensourceframework.netty.copy.DiscardClient.java
License:Apache License
public static void main(String[] args) throws Exception { EventLoopGroup group = new NioEventLoopGroup(); try {/*from ww w .j a v a2 s . co m*/ Bootstrap b = new Bootstrap(); b.group(group).channel(NioSocketChannel.class).handler(new ChannelInitializer<SocketChannel>() { @Override protected void initChannel(SocketChannel ch) throws Exception { ChannelPipeline p = ch.pipeline(); p.addLast(new TimeDecoder(), new DiscardClientHandler()); } }); // Make the connection attempt. ChannelFuture f = b.connect(HOST, PORT).sync(); // Wait until the connection is closed. f.channel().closeFuture().sync(); } finally { group.shutdownGracefully(); } }
From source file:com.chenyang.proxy.http.HttpRemoteForwardChannelInitializer.java
License:Apache License
@Override public void initChannel(SocketChannel channel) throws Exception { channel.attr(HttpConnectionAttribute.ATTRIBUTE_KEY) .set(uaChannel.attr(HttpConnectionAttribute.ATTRIBUTE_KEY).get()); ChannelPipeline pipeline = channel.pipeline(); // pipeline.addLast("idlestate", new IdleStateHandler(0, 0, 3, // TimeUnit.MINUTES)); // pipeline.addLast("idlehandler", new ProxyIdleHandler()); pipeline.addLast("codec", new HttpClientCodec()); pipeline.addLast(HttpRemoteForwardHandler.HANDLER_NAME, new HttpRemoteForwardHandler(uaChannel, remoteChannelInactiveCallback)); }
From source file:com.chiorichan.http.HttpInitializer.java
License:Mozilla Public License
@Override protected void initChannel(SocketChannel ch) throws Exception { ChannelPipeline p = ch.pipeline(); p.addLast("decoder", new HttpRequestDecoder()); p.addLast("aggregator", new HttpObjectAggregator(104857600)); // One Hundred Megabytes p.addLast("encoder", new HttpResponseEncoder()); p.addLast("deflater", new HttpContentCompressor()); p.addLast("handler", new HttpHandler(false)); activeChannels.add(new WeakReference<SocketChannel>(ch)); }
From source file:com.chiorichan.https.HttpsInitializer.java
License:Mozilla Public License
@Override protected void initChannel(SocketChannel ch) throws Exception { ChannelPipeline p = ch.pipeline(); try {//from w w w . ja va 2 s . co m SSLContext context = SslContextFactory.getServerContext(); if (context == null) { NetworkManager.shutdownHttpsServer(); Loader.getLogger() .severe("The SSL engine failed to initalize, possibly due to a missing certificate file"); return; } SSLEngine engine = context.createSSLEngine(); engine.setUseClientMode(false); p.addLast("ssl", new SslHandler(engine)); } catch (Exception e) { NetworkManager.shutdownHttpsServer(); throw new IllegalStateException("The SSL engine failed to initalize", e); } p.addLast("decoder", new HttpRequestDecoder()); p.addLast("aggregator", new HttpObjectAggregator(104857600)); p.addLast("encoder", new HttpResponseEncoder()); p.addLast("deflater", new HttpContentCompressor()); p.addLast("handler", new HttpHandler(true)); }
From source file:com.chschmid.huemorse.server.handler.MorseServerInitializer.java
License:Open Source License
@Override public void initChannel(SocketChannel ch) throws Exception { ChannelPipeline pipeline = ch.pipeline(); // Add the text line codec combination first, pipeline.addLast("framer", new DelimiterBasedFrameDecoder(8192, Delimiters.lineDelimiter())); // the encoder and decoder are static as these are sharable pipeline.addLast("decoder", DECODER); pipeline.addLast("encoder", ENCODER); // and then business logic. pipeline.addLast("handler", serverHandler); }
From source file:com.cmz.stomp.StompClient.java
License:Apache License
public static void main(String[] args) throws Exception { EventLoopGroup group = new NioEventLoopGroup(); try {//from w ww . ja v a2 s.com Bootstrap b = new Bootstrap(); b.group(group).channel(NioSocketChannel.class); b.handler(new ChannelInitializer<SocketChannel>() { @Override protected void initChannel(SocketChannel ch) throws Exception { ChannelPipeline pipeline = ch.pipeline(); pipeline.addLast("decoder", new StompSubframeDecoder()); pipeline.addLast("encoder", new StompSubframeEncoder()); pipeline.addLast("aggregator", new StompSubframeAggregator(1048576)); pipeline.addLast("handler", new StompClientHandler()); } }); b.connect(HOST, PORT).sync().channel().closeFuture().sync(); } finally { group.shutdownGracefully(); } }
From source file:com.codebroker.net.netty.NettyServerInitializer.java
License:Open Source License
@Override protected void initChannel(SocketChannel ch) throws Exception { ChannelPipeline pipeline = ch.pipeline(); pipeline.addLast("MessageHead-decoder", new ByteArrayPacketCodecDecoder()); pipeline.addLast("MessageHead-encoder", new ByteArrayPacketCodecEncoder()); pipeline.addLast("handler", new NettyHandler()); }
From source file:com.codebullets.external.party.simulator.connections.websocket.inbound.WebSocketServerInitializer.java
License:Apache License
@Override public void initChannel(final SocketChannel ch) throws Exception { long timeoutVal = connectionConfig.getTimeout() > 0 ? connectionConfig.getTimeout() : DEFAULT_TIMEOUT; ChannelPipeline pipeline = ch.pipeline(); pipeline.addLast("codec-http", new HttpServerCodec()); pipeline.addLast("readTimeoutHandler", new ReadTimeoutHandler(timeoutVal, TimeUnit.MILLISECONDS)); pipeline.addLast("aggregator", new HttpObjectAggregator(Integer.MAX_VALUE)); pipeline.addLast("handler", new NettyWebSocketServerHandler(endpoint, connectionMonitor, connectionConfig.getName(), connectedChannels)); }
From source file:com.codebullets.external.party.simulator.connections.websocket.outbound.WebSocketClientInitializer.java
License:Apache License
@Override public void initChannel(final SocketChannel ch) throws Exception { HttpHeaders headers = new DefaultHttpHeaders(); // Use half of the timeout for ping if there is no other traffic. // if timeoutSec is very small (<1s) then pingTimeout will be 0 which // disables it in the IdleStateHandler long timeoutSec = TimeUnit.MILLISECONDS.toSeconds(connectionConfig.getTimeout()); long pingTimeout = timeoutSec / 2; ChannelPipeline pipeline = ch.pipeline(); pipeline.addLast("http-codec", new HttpClientCodec()); pipeline.addLast("aggregator", new HttpObjectAggregator(Integer.MAX_VALUE)); pipeline.addLast("idleStateHandler", new IdleStateHandler((int) timeoutSec, (int) pingTimeout, 0)); pipeline.addLast("keepAliveHandler", new KeepAliveHandler(outboundWebSocketConnection)); pipeline.addLast("handler", new NettyWebSocketClientHandler( WebSocketClientHandshakerFactory.newHandshaker(URI.create(connectionConfig.getEndpoint()), WebSocketVersion.V13, null, false, headers), connectionMonitor, connectionConfig.getName())); }