List of usage examples for io.netty.channel ChannelPipeline addLast
ChannelPipeline addLast(ChannelHandler... handlers);
From source file:SecureChatServerInitializer.java
License:Apache License
@Override public void initChannel(SocketChannel ch) throws Exception { ChannelPipeline pipeline = ch.pipeline(); // Add SSL handler first to encrypt and decrypt everything. // In this example, we use a bogus certificate in the server side // and accept any invalid certificates in the client side. // You will need something more complicated to identify both // and server in the real world. pipeline.addLast(sslCtx.newHandler(ch.alloc())); // On top of the SSL handler, add the text line codec. pipeline.addLast(new DelimiterBasedFrameDecoder(8192, Delimiters.lineDelimiter())); pipeline.addLast(new StringDecoder()); pipeline.addLast(new StringEncoder()); // and then business logic. pipeline.addLast(new SecureChatServerHandler()); }
From source file:UdpServer.java
License:Open Source License
void createActorAndHandler(ChannelPipeline p) { final ActorSystem system = ActorSystem.create("CapwapFSMActorSystem"); ActorRef discoveryActor = system.actorOf(Props.create(CapwapDiscoveryServiceActor.class, "discoveryActor"), "discoveryActor"); ActorRef decoder = system.actorOf(/*from w w w . java 2 s.c o m*/ Props.create(CapwapDecoderActor.class, "MessageDecoderActor", discoveryActor), "MessageDecoderActor"); final ActorRef PacketProcessorActor = system.actorOf( Props.create(CapwapMsgProcActor.class, "MessageProcessorActor", decoder), "MessageProcessorActor"); p.addLast(new IncommingPacketHandler(PacketProcessorActor, decoder, discoveryActor)); }
From source file:TelnetClientInitializer.java
License:Apache License
@Override public void initChannel(SocketChannel ch) { ChannelPipeline pipeline = ch.pipeline(); if (sslCtx != null) { pipeline.addLast(sslCtx.newHandler(ch.alloc(), TelnetClient.HOST, TelnetClient.PORT)); }//from w ww . j a v a2s .c o m // Add the text line codec combination first, pipeline.addLast(new DelimiterBasedFrameDecoder(8192, Delimiters.lineDelimiter())); pipeline.addLast(DECODER); pipeline.addLast(ENCODER); // and then business logic. pipeline.addLast(CLIENT_HANDLER); }
From source file:FSMTester.java
License:Open Source License
public void run() throws Exception { final NioEventLoopGroup group = new NioEventLoopGroup(); //Create Actor System final ActorSystem system = ActorSystem.create("CapwapFSMActorSystem"); final ActorRef PacketProcessorActor = system .actorOf(Props.create(CapwapMsgProcActor.class, "MessageProcessorActor"), "MessageProcessorActor"); try {// w w w . j a v a 2 s . c o m final Bootstrap b = new Bootstrap(); b.group(group).channel(NioDatagramChannel.class).option(ChannelOption.SO_BROADCAST, true) .handler(new ChannelInitializer<NioDatagramChannel>() { @Override public void initChannel(final NioDatagramChannel ch) throws Exception { ChannelPipeline p = ch.pipeline(); p.addLast(new IncommingPacketFSMHandler(PacketProcessorActor)); } }); // Bind and start to accept incoming connections. Integer pPort = port; InetAddress address = InetAddress.getLoopbackAddress(); System.out.printf("\n\nwaiting for message %s %s\n\n", String.format(pPort.toString()), String.format(address.toString())); b.bind(address, port).sync().channel().closeFuture().await(); } finally { System.out.print("In Server Finally"); } }
From source file:NettyHttpTransportHandlerInitializer.java
License:Apache License
/** * * @param ch//from w ww.j a v a 2 s . c o m * @throws Exception */ @Override protected void initChannel(SocketChannel ch) throws Exception { // System.out.println("Initlizing Source channel pool"); ChannelPipeline p = ch.pipeline(); if (sslCtx != null) { p.addLast(sslCtx.newHandler(ch.alloc())); } p.addLast(new HttpServerCodec(102400, 102400, 102400)); // p.addLast(new HttpObjectAggregator(Constants.MAXIMUM_CHUNK_SIZE_AGGREGATOR)); p.addLast(new NettyHttpTransportSourceHandler(connections)); }
From source file:alluxio.client.netty.NettyClient.java
License:Apache License
/** * Creates and returns a new Netty client bootstrap for clients to connect to remote servers. * * @param handler the handler that should be added to new channel pipelines * @return the new client {@link Bootstrap} *///from w ww . ja v a 2 s . com public static Bootstrap createClientBootstrap(final ClientHandler handler) { final Bootstrap boot = new Bootstrap(); boot.group(WORKER_GROUP).channel(CLIENT_CHANNEL_CLASS); boot.option(ChannelOption.SO_KEEPALIVE, true); boot.option(ChannelOption.TCP_NODELAY, true); boot.option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT); boot.handler(new ChannelInitializer<SocketChannel>() { @Override public void initChannel(SocketChannel ch) throws Exception { ChannelPipeline pipeline = ch.pipeline(); pipeline.addLast(RPCMessage.createFrameDecoder()); pipeline.addLast(ENCODER); pipeline.addLast(DECODER); pipeline.addLast(handler); } }); return boot; }
From source file:alluxio.network.netty.NettyClient.java
License:Apache License
/** * Creates and returns a new Netty client bootstrap for clients to connect to remote servers. * * @param address the socket address/*from ww w. j av a 2s . c o m*/ * @return the new client {@link Bootstrap} */ public static Bootstrap createClientBootstrap(SocketAddress address) { final Bootstrap boot = new Bootstrap(); boot.group(WORKER_GROUP).channel( NettyUtils.getClientChannelClass(NettyUtils.CHANNEL_TYPE, !(address instanceof InetSocketAddress))); boot.option(ChannelOption.SO_KEEPALIVE, true); boot.option(ChannelOption.TCP_NODELAY, true); boot.option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT); if (NettyUtils.CHANNEL_TYPE == ChannelType.EPOLL) { boot.option(EpollChannelOption.EPOLL_MODE, EpollMode.LEVEL_TRIGGERED); } // After 10 missed heartbeat attempts and no write activity, the server will close the channel. final long timeoutMs = Configuration.getMs(PropertyKey.NETWORK_NETTY_HEARTBEAT_TIMEOUT_MS); final long heartbeatPeriodMs = Math.max(timeoutMs / 10, 1); boot.handler(new ChannelInitializer<Channel>() { @Override public void initChannel(Channel ch) throws Exception { ChannelPipeline pipeline = ch.pipeline(); pipeline.addLast(RPCMessage.createFrameDecoder()); pipeline.addLast(ENCODER); pipeline.addLast(DECODER); pipeline.addLast(new IdleStateHandler(0, heartbeatPeriodMs, 0, TimeUnit.MILLISECONDS)); pipeline.addLast(new IdleWriteHandler()); } }); return boot; }
From source file:app.WebSocketServerInitializer.java
License:Apache License
@Override public void initChannel(SocketChannel ch) throws Exception { ChannelPipeline pipeline = ch.pipeline(); pipeline.addLast(new HttpServerCodec()); pipeline.addLast(new HttpObjectAggregator(65536)); pipeline.addLast(new WebSocketServerHandler()); }
From source file:baseFrame.netty.atest.HttpHelloWorldServerInitializer.java
License:Apache License
@Override public void initChannel(SocketChannel ch) { ChannelPipeline p = ch.pipeline(); p.addLast(new HttpServerCodec()); p.addLast(new HttpHelloWorldServerHandler()); }
From source file:be.yildizgames.module.network.netty.NettyChannelInitializer.java
License:MIT License
@Override protected void initChannel(final SocketChannel ch) { ChannelPipeline pipeline = ch.pipeline(); switch (factory.getCodec()) { case STRING://from w w w . j ava 2 s . c om pipeline.addLast(new StringEncoder(CharsetUtil.UTF_8)); pipeline.addLast(new StringDecoder(CharsetUtil.UTF_8)); break; case HTTP: pipeline.addLast(new HttpServerCodec()); pipeline.addLast(new HttpObjectAggregator(65536)); pipeline.addLast(new ChunkedWriteHandler()); break; case WEBSOCKET: if (this.factory.isServer()) { pipeline.addLast(new HttpServerCodec()); pipeline.addLast(new HttpObjectAggregator(65536)); pipeline.addLast(new WebSocketServerProtocolHandler("/websocket")); } else { pipeline.addLast(new HttpClientCodec()); pipeline.addLast(new HttpObjectAggregator(8192)); } break; default: throw new IllegalArgumentException("Unknown codec: " + factory.getCodec()); } pipeline.addLast("handler", this.factory.create()); }