List of usage examples for io.netty.channel ChannelOption TCP_NODELAY
ChannelOption TCP_NODELAY
To view the source code for io.netty.channel ChannelOption TCP_NODELAY.
Click Source Link
From source file:org.msgpack.rpc.impl.netty.NettyTcpClientTransport.java
License:Apache License
NettyTcpClientTransport(final TcpClientConfig config, final Session session, final NettyEventLoop loop) { // TODO check session.getAddress() instanceof IPAddress final RpcMessageHandler handler = new RpcMessageHandler(session); _bootstrap = new Bootstrap().group(new NioEventLoopGroup(/*2*/)).channel(NioSocketChannel.class) .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, Math.round((float) config.getConnectTimeout())) .option(ChannelOption.TCP_NODELAY, !Boolean.FALSE.equals(config.getOption(ChannelOption.TCP_NODELAY.name()))) .option(ChannelOption.SO_KEEPALIVE, !Boolean.FALSE.equals(config.getOption(ChannelOption.SO_KEEPALIVE.name()))) .handler(new ChannelInitializer<SocketChannel>() { @Override/* w w w. j a v a 2 s. c o m*/ public void initChannel(SocketChannel ch) throws Exception { ch.pipeline().addLast(new MessagePackDecoder(loop.getObjectMapper()), new MessageHandler(handler), new MessagePackEncoder(loop.getObjectMapper())); } }); _session = session; _writables = new ConcurrentLinkedQueue<>(); }
From source file:org.msgpack.rpc.impl.netty.NettyTcpServerTransport.java
License:Apache License
NettyTcpServerTransport(final TcpServerConfig config, final Server server, final NettyEventLoop loop) throws InterruptedException { if (server == null) { throw new IllegalArgumentException("Server must not be null"); }// w w w.j a va2 s. c o m final Address address = config.getListenAddress(); final RpcMessageHandler handler = new RpcMessageHandler(server); handler.useThread(true); final EventLoopGroup bossGroup = new NioEventLoopGroup(/*1*/); // (1) final EventLoopGroup workerGroup = new NioEventLoopGroup(/*4*/); final ServerBootstrap b = new ServerBootstrap().group(bossGroup, workerGroup) .channel(NioServerSocketChannel.class) // (3) .childHandler(new ChannelInitializer<SocketChannel>() { // (4) @Override public void initChannel(SocketChannel ch) throws Exception { ch.pipeline().addLast(new MessagePackDecoder(loop.getObjectMapper()), new MessageHandler(handler), new MessagePackEncoder(loop.getObjectMapper())); } }).option(ChannelOption.SO_BACKLOG, 128) // (5) .childOption(ChannelOption.TCP_NODELAY, !Boolean.FALSE.equals(config.getOption(ChannelOption.TCP_NODELAY.name()))) .childOption(ChannelOption.SO_KEEPALIVE, !Boolean.FALSE.equals(config.getOption(ChannelOption.SO_KEEPALIVE.name()))); // Bind and start to accept incoming connections. channelFuture = b.bind(address.getSocketAddress()).sync(); // (7) }
From source file:org.msgpack.rpc.loop.netty.NettyTcpClientTransport.java
License:Apache License
NettyTcpClientTransport(TcpClientConfig config, Session session, NettyEventLoop loop, Class<? extends RpcMessageHandler> rpcHandlerClass) { super(config, session); try {/* w w w .jav a 2s .co m*/ handler = rpcHandlerClass.getConstructor(Session.class).newInstance(session); } catch (Exception e) { throw new RuntimeException(e); } // handler = new RpcMessageHandlerEx(session); eventLoop = loop; bootstrap = new Bootstrap().group(group); bootstrap.channel(NioSocketChannel.class); final NettyTcpClientTransport trans = this; bootstrap.handler(new ChannelInitializer<SocketChannel>() { @Override protected void initChannel(SocketChannel ch) throws Exception { ChannelPipeline p = ch.pipeline(); if (isSocks) { p.addFirst("socks-handler", new SocksProxyHandler(session, trans)); p.addFirst("socks-encode", new SocksMessageEncoder()); p.addFirst("socks-decode", new SocksInitResponseDecoder()); } p.addLast("msgpack-decode-stream", new MessagePackStreamDecoder(eventLoop.getMessagePack())); p.addLast("msgpack-encode", new MessagePackEncoder(eventLoop.getMessagePack())); p.addLast("message", new MessageHandler(handler, trans)); } }); bootstrap.option(ChannelOption.TCP_NODELAY, true); }
From source file:org.msgpack.rpc.loop.netty.NettyTcpServerTransport.java
License:Apache License
NettyTcpServerTransport(TcpServerConfig config, Server server, NettyEventLoop loop, Class<? extends RpcMessageHandler> rpcHandlerClass) { if (server == null) { throw new IllegalArgumentException("Server must not be null"); }/*from www. j a v a 2 s . co m*/ Address address = config.getListenAddress(); try { RpcMessageHandler handler = rpcHandlerClass.getConstructor(Server.class).newInstance(server); handler.useThread(true); ServerBootstrap bootstrap = new ServerBootstrap().group(bossGroup, workerGroup) .channel(NioServerSocketChannel.class); bootstrap.childHandler(new ChannelInitializer<SocketChannel>() { @Override protected void initChannel(SocketChannel ch) throws Exception { ChannelPipeline p = ch.pipeline(); p.addLast("msgpack-decode-stream", new MessagePackStreamDecoder(loop.getMessagePack())); p.addLast("msgpack-encode", new MessagePackEncoder(loop.getMessagePack())); p.addLast("message", new MessageHandler(handler)); } }); bootstrap.childOption(ChannelOption.TCP_NODELAY, true); bootstrap.option(ChannelOption.SO_REUSEADDR, true); bootstrap.option(ChannelOption.TCP_NODELAY, true); bootstrap.localAddress(address.getSocketAddress()); future = bootstrap.bind(); } catch (Exception e) { throw new RuntimeException(e); } // RpcMessageHandler handler = new RpcMessageHandlerEx(server); }
From source file:org.msrpenabler.server.test.EchoClient.java
License:Apache License
public void run() throws Exception { // Configure the client. group = new NioEventLoopGroup(); // try { Bootstrap b = new Bootstrap(); b.group(group).channel(NioSocketChannel.class).option(ChannelOption.TCP_NODELAY, true) .handler(new ChannelInitializer<SocketChannel>() { @Override/*from ww w . j a v a 2 s. co m*/ public void initChannel(SocketChannel ch) throws Exception { ch.pipeline().addLast(new LoggingHandler(LogLevel.INFO), new EchoClientHandler()); } }); // Start the client. ChannelFuture f = b.connect(host, port).sync(); ch = f.channel(); // // Wait until the connection is closed. // f.channel().closeFuture().sync(); // } finally { // // Shut down the event loop to terminate all threads. // group.shutdown(); // } }
From source file:org.onlab.netty.NettyMessaging.java
License:Apache License
private void startAcceptingConnections() throws InterruptedException { ServerBootstrap b = new ServerBootstrap(); b.option(ChannelOption.WRITE_BUFFER_HIGH_WATER_MARK, 32 * 1024); b.option(ChannelOption.WRITE_BUFFER_LOW_WATER_MARK, 8 * 1024); b.option(ChannelOption.SO_RCVBUF, 1048576); b.option(ChannelOption.TCP_NODELAY, true); b.option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT); b.group(serverGroup, clientGroup);//from w ww. java2 s . c o m b.channel(serverChannelClass); if (enableNettyTLS) { b.childHandler(new SSLServerCommunicationChannelInitializer()); } else { b.childHandler(new OnosCommunicationChannelInitializer()); } b.option(ChannelOption.SO_BACKLOG, 128); b.childOption(ChannelOption.SO_KEEPALIVE, true); // Bind and start to accept incoming connections. b.bind(localEp.port()).sync().addListener(future -> { if (future.isSuccess()) { log.info("{} accepting incoming connections on port {}", localEp.host(), localEp.port()); } else { log.warn("{} failed to bind to port {}", localEp.host(), localEp.port(), future.cause()); } }); }
From source file:org.onosproject.artemis.impl.moas.MoasServerController.java
License:Apache License
/** * Create netty server bootstrap.//ww w . java 2s . c o m * * @return bootstrap */ private ServerBootstrap createServerBootStrap() { bossGroup = new NioEventLoopGroup(); workerGroup = new NioEventLoopGroup(); return new ServerBootstrap().group(bossGroup, workerGroup).channel(NioServerSocketChannel.class) .option(ChannelOption.SO_REUSEADDR, true).childOption(ChannelOption.SO_KEEPALIVE, true) .childOption(ChannelOption.TCP_NODELAY, true); }
From source file:org.onosproject.openflow.controller.impl.Controller.java
License:Apache License
/** * Tell controller that we're ready to accept switches loop. *//*from w w w. j av a2 s . c om*/ public void run() { try { final ServerBootstrap bootstrap = createServerBootStrap(); bootstrap.option(ChannelOption.SO_REUSEADDR, true); bootstrap.childOption(ChannelOption.SO_KEEPALIVE, true); bootstrap.childOption(ChannelOption.TCP_NODELAY, true); bootstrap.childOption(ChannelOption.SO_SNDBUF, Controller.SEND_BUFFER_SIZE); // bootstrap.childOption(ChannelOption.WRITE_BUFFER_WATER_MARK, // new WriteBufferWaterMark(8 * 1024, 32 * 1024)); bootstrap.childHandler(new OFChannelInitializer(this, null, sslContext)); openFlowPorts.forEach(port -> { // TODO revisit if this is best way to listen to multiple ports cg.add(bootstrap.bind(port).syncUninterruptibly().channel()); log.info("Listening for switch connections on {}", port); }); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:org.onosproject.ovsdb.controller.impl.Controller.java
License:Apache License
private void connectRetry(IpAddress ip, TpPort port, ChannelFutureListener listener) { try {//from w w w. j a v a 2 s . c o m Bootstrap b = new Bootstrap(); b.group(workerGroup).channel(NioSocketChannel.class).option(ChannelOption.TCP_NODELAY, true) .handler(new ChannelInitializer<SocketChannel>() { @Override protected void initChannel(SocketChannel channel) throws Exception { ChannelPipeline p = channel.pipeline(); p.addLast(new MessageDecoder(), new StringEncoder(CharsetUtil.UTF_8), new IdleStateHandler(IDLE_TIMEOUT_SEC, 0, 0), new ConnectionHandler()); } }); b.remoteAddress(ip.toString(), port.toInt()); b.connect().addListener(listener); } catch (Exception e) { log.warn("Connection to the ovsdb server {}:{} failed", ip.toString(), port.toString()); } }
From source file:org.onosproject.store.cluster.messaging.impl.NettyMessagingManager.java
License:Apache License
private void startAcceptingConnections() throws InterruptedException { ServerBootstrap b = new ServerBootstrap(); b.childOption(ChannelOption.WRITE_BUFFER_HIGH_WATER_MARK, 32 * 1024); b.childOption(ChannelOption.WRITE_BUFFER_LOW_WATER_MARK, 8 * 1024); b.option(ChannelOption.SO_RCVBUF, 1048576); b.option(ChannelOption.TCP_NODELAY, true); b.childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT); b.group(serverGroup, clientGroup);/* w w w . j av a2 s .c o m*/ b.channel(serverChannelClass); if (enableNettyTls) { b.childHandler(new SslServerCommunicationChannelInitializer()); } else { b.childHandler(new OnosCommunicationChannelInitializer()); } b.option(ChannelOption.SO_BACKLOG, 128); b.childOption(ChannelOption.SO_KEEPALIVE, true); // Bind and start to accept incoming connections. b.bind(localEp.port()).sync().addListener(future -> { if (future.isSuccess()) { log.info("{} accepting incoming connections on port {}", localEp.host(), localEp.port()); } else { log.warn("{} failed to bind to port {}", localEp.host(), localEp.port(), future.cause()); } }); }