List of usage examples for io.netty.channel ChannelOption WRITE_BUFFER_HIGH_WATER_MARK
ChannelOption WRITE_BUFFER_HIGH_WATER_MARK
To view the source code for io.netty.channel ChannelOption WRITE_BUFFER_HIGH_WATER_MARK.
Click Source Link
From source file:org.opendaylight.ocpjava.protocol.impl.core.TcpHandler.java
License:Open Source License
/** * Starts server on selected port./*from w ww .ja v a 2 s .c o m*/ */ @Override public void run() { /* * We generally do not perform IO-unrelated tasks, so we want to have * all outstanding tasks completed before the executing thread goes * back into select. * * Any other setting means netty will measure the time it spent selecting * and spend roughly proportional time executing tasks. */ workerGroup.setIoRatio(100); final ChannelFuture f; try { ServerBootstrap b = new ServerBootstrap(); b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class) .handler(new LoggingHandler(LogLevel.DEBUG)).childHandler(channelInitializer) .option(ChannelOption.SO_BACKLOG, 128).option(ChannelOption.SO_REUSEADDR, true) //modify to "false" for OCP health-check .childOption(ChannelOption.SO_KEEPALIVE, false).childOption(ChannelOption.TCP_NODELAY, true) .childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT) .childOption(ChannelOption.WRITE_BUFFER_HIGH_WATER_MARK, DEFAULT_WRITE_HIGH_WATERMARK * 1024) .childOption(ChannelOption.WRITE_BUFFER_LOW_WATER_MARK, DEFAULT_WRITE_LOW_WATERMARK * 1024) .childOption(ChannelOption.WRITE_SPIN_COUNT, DEFAULT_WRITE_SPIN_COUNT); if (startupAddress != null) { f = b.bind(startupAddress.getHostAddress(), port).sync(); } else { f = b.bind(port).sync(); } } catch (InterruptedException e) { LOG.error("Interrupted while binding port {}", port, e); return; } try { InetSocketAddress isa = (InetSocketAddress) f.channel().localAddress(); address = isa.getHostString(); // Update port, as it may have been specified as 0 this.port = isa.getPort(); LOG.debug("address from tcphandler: {}", address); isOnlineFuture.set(true); LOG.info("RadioHead listener started and ready to accept incoming tcp/tls connections on port: {}", port); f.channel().closeFuture().sync(); } catch (InterruptedException e) { LOG.error("Interrupted while waiting for port {} shutdown", port, e); } finally { shutdown(); } }
From source file:org.opendaylight.protocol.bgp.rib.impl.BGPDispatcherImpl.java
License:Open Source License
protected Bootstrap createClientBootStrap(final Optional<KeyMapping> keys, final EventLoopGroup workerGroup) { final Bootstrap bootstrap = new Bootstrap(); if (Epoll.isAvailable()) { bootstrap.channel(EpollSocketChannel.class); bootstrap.option(EpollChannelOption.EPOLL_MODE, EpollMode.LEVEL_TRIGGERED); } else {//w w w . j a va2s . c o m bootstrap.channel(NioSocketChannel.class); } if (keys.isPresent()) { if (Epoll.isAvailable()) { bootstrap.option(EpollChannelOption.TCP_MD5SIG, keys.get()); } else { throw new UnsupportedOperationException(Epoll.unavailabilityCause().getCause()); } } // Make sure we are doing round-robin processing bootstrap.option(ChannelOption.MAX_MESSAGES_PER_READ, 1); bootstrap.option(ChannelOption.SO_KEEPALIVE, Boolean.TRUE); bootstrap.option(ChannelOption.WRITE_BUFFER_HIGH_WATER_MARK, HIGH_WATER_MARK); bootstrap.option(ChannelOption.WRITE_BUFFER_LOW_WATER_MARK, LOW_WATER_MARK); if (bootstrap.group() == null) { bootstrap.group(workerGroup); } return bootstrap; }
From source file:org.opendaylight.protocol.bgp.rib.impl.BGPDispatcherImpl.java
License:Open Source License
public static ServerBootstrap createServerBootstrap(final ChannelPipelineInitializer initializer, final EventLoopGroup bossGroup, final EventLoopGroup workerGroup) { final ServerBootstrap serverBootstrap = new ServerBootstrap(); if (Epoll.isAvailable()) { serverBootstrap.channel(EpollServerSocketChannel.class); serverBootstrap.childOption(EpollChannelOption.EPOLL_MODE, EpollMode.LEVEL_TRIGGERED); } else {//from w ww . j av a 2 s. co m serverBootstrap.channel(NioServerSocketChannel.class); } final ChannelHandler serverChannelHandler = BGPChannel.createServerChannelHandler(initializer); serverBootstrap.childHandler(serverChannelHandler); serverBootstrap.option(ChannelOption.SO_BACKLOG, Integer.valueOf(SOCKET_BACKLOG_SIZE)); serverBootstrap.childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT); serverBootstrap.childOption(ChannelOption.WRITE_BUFFER_HIGH_WATER_MARK, HIGH_WATER_MARK); serverBootstrap.childOption(ChannelOption.WRITE_BUFFER_LOW_WATER_MARK, LOW_WATER_MARK); // Make sure we are doing round-robin processing serverBootstrap.option(ChannelOption.MAX_MESSAGES_PER_READ, 1); if (serverBootstrap.group() == null) { serverBootstrap.group(bossGroup, workerGroup); } return serverBootstrap; }
From source file:org.wenxueliu.netty.client.ClientTest.java
License:Apache License
/** * Accepts incoming connections.//from w w w. j a va2 s . c o m */ private void startAcceptingConnections() throws InterruptedException { ServerBootstrap b = new ServerBootstrap(); b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class) .childHandler(new CommunicationChannelInitializer()); b.option(ChannelOption.SO_BACKLOG, 128); b.option(ChannelOption.WRITE_BUFFER_HIGH_WATER_MARK, 32 * 1024); b.option(ChannelOption.WRITE_BUFFER_LOW_WATER_MARK, 8 * 1024); b.option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT); b.childOption(ChannelOption.SO_KEEPALIVE, true); b.bind(80).sync(); }
From source file:ru.releng.shameonyou.core.graphite.GraphiteClient.java
License:Apache License
private Bootstrap configureBootstrap(Bootstrap bootstrap, EventLoopGroup eventLoopGroup) { return bootstrap.group(eventLoopGroup).channel(NioSocketChannel.class) .remoteAddress(graphiteHost, graphitePort).option(ChannelOption.SO_KEEPALIVE, true) .option(ChannelOption.WRITE_BUFFER_HIGH_WATER_MARK, 1024 * 1024) .option(ChannelOption.WRITE_BUFFER_LOW_WATER_MARK, 128 * 1024) .option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT) .handler(new ChannelInitializer<SocketChannel>() { @Override/*from ww w. jav a 2 s . com*/ public void initChannel(SocketChannel ch) throws Exception { ch.pipeline().addLast("decoder", decoder); ch.pipeline().addLast("encoder", encoder); ch.pipeline().addLast("writeTimeoutHandler", new WriteTimeoutHandler(1)); ch.pipeline().addLast("handler", handler); } }); }
From source file:storage.netty.HTTPUploadClientAsync.java
License:Apache License
public void putBlob(String filepath) throws Exception { String resourceUrl = "/mycontainer/" + randomString(5); String putBlobUrl = base_url + resourceUrl; URI uriSimple = new URI(putBlobUrl); String scheme = uriSimple.getScheme() == null ? "http" : uriSimple.getScheme(); String host = uriSimple.getHost() == null ? "127.0.0.1" : uriSimple.getHost(); int port = uriSimple.getPort(); if (port == -1) { if ("http".equalsIgnoreCase(scheme)) { port = 80;/*from w ww. j av a 2 s . c o m*/ } else if ("https".equalsIgnoreCase(scheme)) { port = 443; } } if (!"http".equalsIgnoreCase(scheme) && !"https".equalsIgnoreCase(scheme)) { System.err.println("Only HTTP(S) is supported."); return; } final boolean ssl = "https".equalsIgnoreCase(scheme); final SslContext sslCtx; if (ssl) { sslCtx = SslContextBuilder.forClient().trustManager(InsecureTrustManagerFactory.INSTANCE).build(); } else { sslCtx = null; } File path = new File(filepath); if (!path.canRead()) { throw new FileNotFoundException(filepath); } // Configure the client. EventLoopGroup group = new NioEventLoopGroup(); // setup the factory: here using a mixed memory/disk based on size threshold HttpDataFactory factory = new DefaultHttpDataFactory(DefaultHttpDataFactory.MINSIZE); // Disk if MINSIZE exceed DiskFileUpload.deleteOnExitTemporaryFile = true; // should delete file on exit (in normal exit) DiskFileUpload.baseDirectory = null; // system temp directory DiskAttribute.deleteOnExitTemporaryFile = true; // should delete file on exit (in normal exit) DiskAttribute.baseDirectory = null; // system temp directory try { Bootstrap b = new Bootstrap(); b.group(group).channel(NioSocketChannel.class).handler(new HttpUploadClientInitializer(sslCtx)); b.option(ChannelOption.WRITE_BUFFER_HIGH_WATER_MARK, 10 * 64 * 1024); b.option(ChannelOption.SO_SNDBUF, 1048576); b.option(ChannelOption.SO_RCVBUF, 1048576); b.option(ChannelOption.TCP_NODELAY, true); b.option(ChannelOption.SO_REUSEADDR, true); b.option(ChannelOption.AUTO_CLOSE, true); //Iterate over files Collection<ChannelFuture> futures = new ArrayList<ChannelFuture>(); for (final File file : path.listFiles()) { String blobname = file.getName(); System.out.println(blobname); HttpRequest request = formpost(host, port, resourceUrl + blobname, file, factory); ChannelFuture cf = b.connect(host, port); futures.add(cf); cf.channel().attr(HTTPREQUEST).set(request); cf.channel().attr(FILETOUPLOAD).set(file); cf.addListener(new ChannelFutureListener() { public void operationComplete(ChannelFuture future) throws Exception { // check to see if we succeeded if (future.isSuccess()) { System.out.println("connected for " + blobname); } else { System.out.println(future.cause().getMessage()); } } }); } for (ChannelFuture cf : futures) { cf.channel().closeFuture().awaitUninterruptibly(); } } finally { // Shut down executor threads to exit. group.shutdownGracefully(); // Really clean all temporary files if they still exist factory.cleanAllHttpDatas(); } }
From source file:tachyon.worker.netty.NettyDataServer.java
License:Apache License
private ServerBootstrap createBootstrap() { final ServerBootstrap boot = createBootstrapOfType( mTachyonConf.getEnum(Constants.WORKER_NETWORK_NETTY_CHANNEL, ChannelType.class)); // use pooled buffers boot.option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT); boot.childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT); // set write buffer // this is the default, but its recommended to set it in case of change in future netty. boot.childOption(ChannelOption.WRITE_BUFFER_HIGH_WATER_MARK, (int) mTachyonConf.getBytes(Constants.WORKER_NETTY_WATERMARK_HIGH)); boot.childOption(ChannelOption.WRITE_BUFFER_LOW_WATER_MARK, (int) mTachyonConf.getBytes(Constants.WORKER_NETTY_WATERMARK_LOW)); // more buffer settings on Netty socket option, one can tune them by specifying // properties, e.g.: // tachyon.worker.network.netty.backlog=50 // tachyon.worker.network.netty.buffer.send=64KB // tachyon.worker.network.netty.buffer.receive=64KB if (mTachyonConf.containsKey(Constants.WORKER_NETTY_BACKLOG)) { boot.option(ChannelOption.SO_BACKLOG, mTachyonConf.getInt(Constants.WORKER_NETTY_BACKLOG)); }//from w ww . ja va 2 s . c om if (mTachyonConf.containsKey(Constants.WORKER_NETTY_SEND_BUFFER)) { boot.option(ChannelOption.SO_SNDBUF, (int) mTachyonConf.getBytes(Constants.WORKER_NETTY_SEND_BUFFER)); } if (mTachyonConf.containsKey(Constants.WORKER_NETTY_RECEIVE_BUFFER)) { boot.option(ChannelOption.SO_RCVBUF, (int) mTachyonConf.getBytes(Constants.WORKER_NETTY_RECEIVE_BUFFER)); } return boot; }