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.apache.tajo.worker.RemoteFetcher.java
License:Apache License
public RemoteFetcher(TajoConf conf, URI uri, FileChunk chunk) { super(conf, uri, chunk); String scheme = uri.getScheme() == null ? "http" : uri.getScheme(); this.host = uri.getHost() == null ? "localhost" : uri.getHost(); this.port = uri.getPort(); if (port == -1) { if (scheme.equalsIgnoreCase("http")) { this.port = 80; } else if (scheme.equalsIgnoreCase("https")) { this.port = 443; }//w w w . ja v a 2 s . c o m } bootstrap = new Bootstrap() .group(NettyUtils.getSharedEventLoopGroup(NettyUtils.GROUP.FETCHER, conf.getIntVar(TajoConf.ConfVars.SHUFFLE_RPC_CLIENT_WORKER_THREAD_NUM))) .channel(NioSocketChannel.class).option(ChannelOption.ALLOCATOR, NettyUtils.ALLOCATOR) .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, conf.getIntVar(TajoConf.ConfVars.SHUFFLE_FETCHER_CONNECT_TIMEOUT) * 1000) .option(ChannelOption.SO_RCVBUF, 1048576) // set 1M .option(ChannelOption.TCP_NODELAY, true); }
From source file:org.apache.zookeeper.ClientCnxnSocketNetty.java
License:Apache License
@Override void connect(InetSocketAddress addr) throws IOException { firstConnect = new CountDownLatch(1); Bootstrap bootstrap = new Bootstrap().group(eventLoopGroup).channel(NettyUtils.nioOrEpollSocketChannel()) .option(ChannelOption.SO_LINGER, -1).option(ChannelOption.TCP_NODELAY, true) .handler(new ZKClientPipelineFactory(addr.getHostString(), addr.getPort())); bootstrap = configureBootstrapAllocator(bootstrap); bootstrap.validate();//w w w . jav a 2s . c o m connectLock.lock(); try { connectFuture = bootstrap.connect(addr); connectFuture.addListener(new ChannelFutureListener() { @Override public void operationComplete(ChannelFuture channelFuture) throws Exception { // this lock guarantees that channel won't be assigned after cleanup(). connectLock.lock(); try { if (!channelFuture.isSuccess()) { LOG.info("future isn't success, cause:", channelFuture.cause()); return; } else if (connectFuture == null) { LOG.info("connect attempt cancelled"); // If the connect attempt was cancelled but succeeded // anyway, make sure to close the channel, otherwise // we may leak a file descriptor. channelFuture.channel().close(); return; } // setup channel, variables, connection, etc. channel = channelFuture.channel(); disconnected.set(false); initialized = false; lenBuffer.clear(); incomingBuffer = lenBuffer; sendThread.primeConnection(); updateNow(); updateLastSendAndHeard(); if (sendThread.tunnelAuthInProgress()) { waitSasl.drainPermits(); needSasl.set(true); sendPrimePacket(); } else { needSasl.set(false); } LOG.info("channel is connected: {}", channelFuture.channel()); } finally { connectFuture = null; connectLock.unlock(); // need to wake on connect success or failure to avoid // timing out ClientCnxn.SendThread which may be // blocked waiting for first connect in doTransport(). wakeupCnxn(); firstConnect.countDown(); } } }); } finally { connectLock.unlock(); } }
From source file:org.apache.zookeeper.server.NettyServerCnxnFactory.java
License:Apache License
NettyServerCnxnFactory() { x509Util = new ClientX509Util(); EventLoopGroup bossGroup = NettyUtils.newNioOrEpollEventLoopGroup(); EventLoopGroup workerGroup = NettyUtils.newNioOrEpollEventLoopGroup(); ServerBootstrap bootstrap = new ServerBootstrap().group(bossGroup, workerGroup) .channel(NettyUtils.nioOrEpollServerSocketChannel()) // parent channel options .option(ChannelOption.SO_REUSEADDR, true) // child channels options .childOption(ChannelOption.TCP_NODELAY, true).childOption(ChannelOption.SO_LINGER, -1) .childHandler(new ChannelInitializer<SocketChannel>() { @Override//w w w.j av a2 s . c o m protected void initChannel(SocketChannel ch) throws Exception { ChannelPipeline pipeline = ch.pipeline(); if (secure) { initSSL(pipeline); } pipeline.addLast("servercnxnfactory", channelHandler); } }); this.bootstrap = configureBootstrapAllocator(bootstrap); this.bootstrap.validate(); }
From source file:org.asciidoctor.maven.http.AsciidoctorHttpServer.java
License:Apache License
public void start() { final AtomicInteger threadId = new AtomicInteger(1); workerGroup = new NioEventLoopGroup(THREAD_NUMBER, new ThreadFactory() { @Override/*from ww w . jav a 2 s. c om*/ public Thread newThread(final Runnable r) { final Thread t = new Thread(r, THREAD_PREFIX + threadId.getAndIncrement()); if (t.getPriority() != Thread.NORM_PRIORITY) { t.setPriority(Thread.NORM_PRIORITY); } if (t.isDaemon()) { t.setDaemon(false); } return t; } }); try { bootstrap = new ServerBootstrap(); bootstrap.option(ChannelOption.SO_REUSEADDR, true).option(ChannelOption.SO_SNDBUF, 1024) .option(ChannelOption.TCP_NODELAY, true).group(workerGroup) .channel(NioServerSocketChannel.class).childHandler(new ChannelInitializer<SocketChannel>() { @Override protected void initChannel(final SocketChannel ch) throws Exception { ch.pipeline().addLast("decoder", new HttpRequestDecoder()) .addLast("aggregator", new HttpObjectAggregator(Integer.MAX_VALUE)) .addLast("encoder", new HttpResponseEncoder()) .addLast("chunked-writer", new ChunkedWriteHandler()) .addLast("asciidoctor", new AsciidoctorHandler(workDir, defaultPage)); } }).bind(port).addListener(new ChannelFutureListener() { @Override public void operationComplete(final ChannelFuture future) throws Exception { if (!future.isSuccess()) { logger.error("Can't start HTTP server"); } else { logger.info(String.format("Server started on http://%s:%s", HOST, port)); } } }).sync(); } catch (final InterruptedException e) { logger.error(e.getMessage(), e); } }
From source file:org.asterisque.netty.Netty.java
License:Apache License
/** * ???????/*from w w w .j av a 2s . c o m*/ * @param options * @return Wire ? Future */ public CompletableFuture<Wire> newWire(Node node, SocketAddress address, Options options) { Bootstrap client = new Bootstrap(); CompletableFuture<Wire> future = new CompletableFuture<>(); Initializer factory = new Initializer(node, false, options, wire -> { logger.debug(Asterisque.logPrefix(false) + ": onConnect(" + wire + ")"); future.complete(wire); }); client.group(worker()).channel(NioSocketChannel.class).remoteAddress(address) .option(ChannelOption.TCP_NODELAY, java.lang.Boolean.TRUE).handler(factory); client.connect(address).addListener(f -> { if (f.isSuccess()) { logger.debug(Asterisque.logPrefix(false) + ": connection success"); } else { logger.debug(Asterisque.logPrefix(false) + ": connection failure"); future.completeExceptionally(f.cause()); } }); return future; }
From source file:org.asterisque.netty.Netty.java
License:Apache License
/** * ??????????//from www. j av a 2 s .c om * * @return Server ? Future */ public CompletableFuture<Server> newServer(Node node, SocketAddress address, Options options, Consumer<Wire> onAccept) { NioEventLoopGroup master = new NioEventLoopGroup(); // ?????? ServerBootstrap server = new ServerBootstrap(); CompletableFuture<Server> future = new CompletableFuture<>(); Initializer factory = new Initializer(node, true, options, wire -> { logger.debug(Asterisque.logPrefix(true) + ": onAccept(" + wire + ")"); onAccept.accept(wire); }); server.group(master, worker()).channel(NioServerSocketChannel.class).localAddress(address) .option(ChannelOption.SO_BACKLOG, options.get(Options.KEY_SERVER_BACKLOG).get()) .childOption(ChannelOption.TCP_NODELAY, Boolean.TRUE).childHandler(factory); server.bind().addListener(f -> { if (f.isSuccess()) { logger.info(Asterisque.logPrefix(true) + ": startup server: " + Debug.toString(address)); future.complete(new Server(node, address, options) { @Override public void close() { master.shutdownGracefully(); } }); } else { logger.error(Asterisque.logPrefix(true) + ": server bind failure: " + Debug.toString(address), f.cause()); future.completeExceptionally(f.cause()); master.shutdownGracefully(); } }); return future; }
From source file:org.asynchttpclient.netty.channel.ChannelManager.java
License:Open Source License
private Bootstrap newBootstrap(ChannelFactory<? extends Channel> channelFactory, EventLoopGroup eventLoopGroup, AsyncHttpClientConfig config) {//from w w w . j a v a 2 s . c om @SuppressWarnings("deprecation") Bootstrap bootstrap = new Bootstrap().channelFactory(channelFactory).group(eventLoopGroup)// // default to PooledByteBufAllocator .option(ChannelOption.ALLOCATOR, config.isUsePooledMemory() ? PooledByteBufAllocator.DEFAULT : UnpooledByteBufAllocator.DEFAULT)// .option(ChannelOption.TCP_NODELAY, config.isTcpNoDelay())// .option(ChannelOption.SO_REUSEADDR, config.isSoReuseAddress())// .option(ChannelOption.AUTO_CLOSE, false); if (config.getConnectTimeout() > 0) { bootstrap.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, config.getConnectTimeout()); } if (config.getSoLinger() >= 0) { bootstrap.option(ChannelOption.SO_LINGER, config.getSoLinger()); } if (config.getSoSndBuf() >= 0) { bootstrap.option(ChannelOption.SO_SNDBUF, config.getSoSndBuf()); } if (config.getSoRcvBuf() >= 0) { bootstrap.option(ChannelOption.SO_RCVBUF, config.getSoRcvBuf()); } for (Entry<ChannelOption<Object>, Object> entry : config.getChannelOptions().entrySet()) { bootstrap.option(entry.getKey(), entry.getValue()); } return bootstrap; }
From source file:org.asynchttpclient.netty.NettyAsyncProviderBasicTest.java
License:Open Source License
@Override protected AsyncHttpProviderConfig<?, ?> getProviderConfig() { return new NettyAsyncHttpProviderConfig().addChannelOption(ChannelOption.TCP_NODELAY, Boolean.TRUE); }
From source file:org.atmosphere.nettosphere.Nettosphere.java
License:Apache License
private void configureBootstrap(ServerBootstrap bootstrap, Config config) { bootstrap.childOption(ChannelOption.TCP_NODELAY, config.socketNoTcpDelay()); bootstrap.childOption(ChannelOption.SO_KEEPALIVE, config.socketKeepAlive()); }
From source file:org.beaconmc.network.socket.NetworkHandler.java
License:Open Source License
public NetworkHandler(BeaconServer beaconServer) { this.beaconServer = beaconServer; serverBootstrap.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class) .childHandler(new ChannelInitalizer(this)).childOption(ChannelOption.TCP_NODELAY, true); }