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:de.jackwhite20.apex.tcp.pipeline.handler.SocketUpstreamHandler.java
License:Open Source License
@Override public void channelActive(ChannelHandlerContext ctx) { final Channel inboundChannel = ctx.channel(); Bootstrap b = new Bootstrap().group(inboundChannel.eventLoop()).channel(PipelineUtils.getChannel()) .handler(new SocketDownstreamHandler(inboundChannel)).option(ChannelOption.TCP_NODELAY, true) // No initial connection should take longer than 4 seconds .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, BackendInfo.DEFAULT_TCP_TIMEOUT) .option(ChannelOption.AUTO_READ, false); ChannelFuture f = b.connect(backendInfo.getHost(), backendInfo.getPort()); downstreamChannel = f.channel();//from www.j a v a 2s . c o m f.addListener((ChannelFutureListener) future -> { if (future.isSuccess()) { inboundChannel.read(); } else { inboundChannel.close(); } }); // Add the channel to the channel group Apex.getChannelGroup().add(inboundChannel); }
From source file:de.jackwhite20.cascade.server.impl.CascadeServer.java
License:Open Source License
@Override public void start() { bossGroup = new NioEventLoopGroup(); workerGroup = PipelineUtils.newEventLoopGroup(serverConfig.workerThreads(), new CascadeThreadFactory("Server")); try {/*from w ww. j ava 2 s. c o m*/ ServerBootstrap b = new ServerBootstrap(); serverChannel = b.group(bossGroup, workerGroup).channel(PipelineUtils.getServerChannel()) .childHandler(new CascadeChannelInitializer(serverConfig.protocol(), serverConfig.sessionListener().stream().collect(Collectors.toList()))) .option(ChannelOption.TCP_NODELAY, true).option(ChannelOption.SO_BACKLOG, 200) .bind(serverConfig.host(), serverConfig.port()).sync().channel(); serverConfig.sessionListener().forEach(SessionListener::onStarted); } catch (Exception e) { e.printStackTrace(); } }
From source file:de.jackwhite20.comix.Comix.java
License:Open Source License
public void start() { System.setProperty("java.net.preferIPv4Stack", "true"); ResourceLeakDetector.setLevel(ResourceLeakDetector.Level.DISABLED); AnsiConsole.systemInstall();/*from w w w .ja v a2 s .c o m*/ LogManager.getLogManager().reset(); logger = new ComixLogger(consoleReader); logger.log(Level.INFO, "Comix", "------ Comix v.0.1 ------"); loadConfig(); logger.log(Level.INFO, "Load-Balancer", (targets.size() > 0) ? "Targets:" : "No Target Servers found!"); targets.forEach(t -> logger.log(Level.INFO, "Load-Balancer", t.getName() + " - " + t.getHost() + ":" + t.getPort())); logger.log(Level.INFO, "Commands", "Registering commands..."); registerCommands(); logger.log(Level.INFO, "Comix", "Starting Comix on " + balancerHost + ":" + balancerPort + "..."); balancingStrategy = new RoundRobinBalancingStrategy(targets); new Timer("CheckTargets").scheduleAtFixedRate(new CheckTargets(balancingStrategy), 0, TimeUnit.SECONDS.toMillis(comixConfig.getCheckTime())); bossGroup = new NioEventLoopGroup(1); workerGroup = new NioEventLoopGroup(comixConfig.getThreads()); try { ServerBootstrap bootstrap = new ServerBootstrap(); bootstrap.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class) .option(ChannelOption.TCP_NODELAY, true) .option(ChannelOption.SO_BACKLOG, comixConfig.getBacklog()) .option(ChannelOption.SO_REUSEADDR, true).childOption(ChannelOption.TCP_NODELAY, true) .childOption(ChannelOption.AUTO_READ, false).childOption(ChannelOption.SO_TIMEOUT, 4000) .childHandler(new ComixChannelInitializer()); ChannelFuture f = bootstrap.bind(comixConfig.getPort()).sync(); reload(); logger.log(Level.INFO, "Comix", "Comix is started!"); f.channel().closeFuture().sync(); running = false; } catch (Exception e) { e.printStackTrace(); } finally { shutdown(); } }
From source file:de.jackwhite20.comix.handler.UpstreamHandler.java
License:Open Source License
public void connectDownstream(ByteBuf initPacket) { InetSocketAddress address = (InetSocketAddress) upstreamChannel.remoteAddress(); TargetData target = this.strategy.selectTarget(address.getHostName(), address.getPort()); Bootstrap bootstrap = new Bootstrap(); bootstrap.group(upstreamChannel.eventLoop()).channel(upstreamChannel.getClass()) .option(ChannelOption.TCP_NODELAY, true).option(ChannelOption.AUTO_READ, false) .option(ChannelOption.SO_TIMEOUT, 5000).option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 2000) .handler(downstreamHandler = new DownstreamHandler(client, upstreamChannel)); ChannelFuture f = bootstrap.connect(target.getHost(), target.getPort()); downstreamChannel = f.channel();/*from w w w . j a v a 2 s . co m*/ initialPackets.add(initPacket); f.addListener((future) -> { if (future.isSuccess()) { downstreamConnected = true; for (ByteBuf packet : initialPackets) { downstreamChannel.writeAndFlush(packet); } Comix.getLogger().log(Level.INFO, "Proxy", "[" + client.getName() + "] <-> [Comix] <-> [" + target.getName() + "] tunneled"); } else { upstreamChannel.close(); } }); }
From source file:de.jackwhite20.japs.server.JaPSServer.java
License:Open Source License
private void start() { if (PipelineUtils.isEpoll()) { LOGGER.info("Using high performance epoll event notification mechanism"); } else {/* w w w . j a v a 2 s. c o m*/ LOGGER.info("Using normal select/poll event notification mechanism"); } bossGroup = PipelineUtils.newEventLoopGroup(1); workerGroup = PipelineUtils.newEventLoopGroup(workerThreads); try { ServerBootstrap serverBootstrap = new ServerBootstrap(); serverChannel = serverBootstrap.group(bossGroup, workerGroup).channel(PipelineUtils.getServerChannel()) .childHandler(new ServerChannelInitializer(this)).option(ChannelOption.TCP_NODELAY, true) .option(ChannelOption.SO_BACKLOG, backlog).bind(new InetSocketAddress(host, port)).sync() .channel(); } catch (InterruptedException e) { e.printStackTrace(); } LOGGER.log(Level.INFO, "JaPS server started on {0}:{1}", new Object[] { host, String.valueOf(port) }); }
From source file:de.jackwhite20.japs.shared.nio.NioSocketClient.java
License:Open Source License
public boolean connect(String host, int port) { ChannelFuture channelFuture = new Bootstrap().group(PipelineUtils.newEventLoopGroup(1)) .channel(PipelineUtils.getChannel()).handler(new ClientChannelInitializer(this)) .option(ChannelOption.TCP_NODELAY, true) .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, CONNECT_TIMEOUT).connect(host, port); channelFuture.awaitUninterruptibly(); channel = channelFuture.channel();// w ww. jav a 2s . c o m CountDownLatch countDownLatch = new CountDownLatch(1); channelFuture.addListener(new ChannelFutureListener() { @Override public void operationComplete(ChannelFuture channelFuture) throws Exception { connected = channelFuture.isSuccess(); countDownLatch.countDown(); } }); try { countDownLatch.await(2, TimeUnit.SECONDS); } catch (InterruptedException e) { e.printStackTrace(); } return connected; }
From source file:de.jpaw.bonaparte.netty.testServer.SslServer.java
License:Apache License
public void run() throws Exception { // Configure the server. ServerBootstrap b = new ServerBootstrap(); EventLoopGroup bossGroup = new NioEventLoopGroup(); EventLoopGroup workerGroup = new NioEventLoopGroup(); try {/*from w w w.ja va 2 s . c om*/ b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class) .option(ChannelOption.SO_BACKLOG, 100).localAddress(new InetSocketAddress(port)) .childOption(ChannelOption.TCP_NODELAY, true).handler(new LoggingHandler(LogLevel.INFO)) .childHandler(new BonaparteNettySslPipelineFactory(1000, new TestServerHandler(), useSsl, false, requirePeerAuthentication, null)); // Start the server. ChannelFuture f = b.bind().sync(); // Wait until the server socket is closed. f.channel().closeFuture().sync(); } finally { // Shut down all event loops to terminate all threads. bossGroup.shutdownGracefully(); workerGroup.shutdownGracefully(); } }
From source file:de.jpaw.bonaparte.netty.testServer.TestServer.java
License:Apache License
public void run() throws Exception { // Configure the server. EventLoopGroup bossGroup = new NioEventLoopGroup(3); EventLoopGroup workerGroup = new NioEventLoopGroup(6); try {//from w ww . j ava 2s.c o m ServerBootstrap b = new ServerBootstrap(); b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class) .option(ChannelOption.SO_BACKLOG, 100).localAddress(new InetSocketAddress(port)) .childOption(ChannelOption.TCP_NODELAY, true).childOption(ChannelOption.SO_KEEPALIVE, true) .handler(new LoggingHandler(LogLevel.INFO)) .childHandler(new BonaparteNettyPipelineFactory(1000, new TestServerHandler(), null, 1)); // Start the server. ChannelFuture f = b.bind().sync(); // Wait until the server socket is closed. f.channel().closeFuture().sync(); } catch (Exception e) { System.out.println("Exception " + e + " occured"); } finally { // Shut down all event loops to terminate all threads. bossGroup.shutdownGracefully(); workerGroup.shutdownGracefully(); } }
From source file:de.ocarthon.core.network.HttpClient.java
License:Apache License
private static Bootstrap defaultBootstrap() { if (defaultHttpBootstrap == null) { defaultHttpBootstrap = new Bootstrap(); defaultHttpBootstrap.group(eventLoopGroup); defaultHttpBootstrap.option(ChannelOption.TCP_NODELAY, true); defaultHttpBootstrap.option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT); defaultHttpBootstrap.channelFactory(channelFactory); }//from w w w .j a v a 2 s. co m return defaultHttpBootstrap; }
From source file:de.saxsys.synchronizefx.netty.base.server.NettyBasicServer.java
License:Open Source License
@Override public void start() throws SynchronizeFXException { this.connectionAccptorGroup = new NioEventLoopGroup(); this.clientConnectionGroup = new NioEventLoopGroup(); BasicChannelInitializerServer channelInitializer = createChannelInitializer(); channelInitializer.setTopologyCallback(callback); ServerBootstrap bootstrap = new ServerBootstrap(); bootstrap.group(connectionAccptorGroup, clientConnectionGroup).channel(NioServerSocketChannel.class) .childHandler(channelInitializer).childOption(ChannelOption.TCP_NODELAY, true) .childOption(ChannelOption.SO_KEEPALIVE, true); bootstrap.bind(port).syncUninterruptibly(); }