List of usage examples for io.netty.bootstrap ServerBootstrap childGroup
EventLoopGroup childGroup
To view the source code for io.netty.bootstrap ServerBootstrap childGroup.
Click Source Link
From source file:com.fjn.helper.frameworkex.netty.v4.echotest.EchoServer.java
License:Apache License
public void start() throws Exception { EventLoopGroup group = new NioEventLoopGroup(); try {/* w w w .j a v a 2 s . c om*/ // Bootstraps the server ServerBootstrap b = new ServerBootstrap(); // Specifies NIO transport, local socket address b.group(group); b.childGroup(); b.channel(NioServerSocketChannel.class); b.localAddress(new InetSocketAddress(port)); // Adds handler to channel pipeline b.childHandler(new ChannelInitializer<SocketChannel>() { @Override protected void initChannel(SocketChannel ch) throws Exception { ch.pipeline().addLast(new EchoServerHandler()); } }); // Binds server, waits for server to close, and releases resources ChannelFuture f = b.bind().sync(); System.out.println(EchoServer.class.getName() + " started and listen on " + f.channel().localAddress()); f.channel().closeFuture().sync(); } finally { group.shutdownGracefully().sync(); } }
From source file:jj.repl.ReplServer.java
License:Apache License
private void start() { port = (configuration.port() < 1023 || configuration.port() > 65535) ? DEFAULT_PORT : configuration.port(); final ServerBootstrap bootstrap = new ServerBootstrap() .group(new NioEventLoopGroup(1, bossThreadFactory), new NioEventLoopGroup(1, workerThreadFactory)) .channel(NioServerSocketChannel.class).childHandler(channelInitializer); bootstrap.bind("localhost", port).addListener(new ChannelFutureListener() { @Override//w ww . jav a 2s . c om public void operationComplete(ChannelFuture future) throws Exception { if (future.isSuccess()) { publisher.publish(new ReplListening(port)); server = bootstrap; } else { publisher.publish(new Emergency("could not start the REPL server", future.cause())); bootstrap.group().shutdownGracefully(0, 0, SECONDS); bootstrap.childGroup().shutdownGracefully(0, 0, SECONDS); } } }); }
From source file:org.apache.flink.runtime.io.network.netty.NettyConnectionManagerTest.java
License:Apache License
/** * Tests that the number of arenas and number of threads of the client and * server are set to the same number, that is the number of configured * task slots.//w ww.java2s .c om */ @Test public void testMatchingNumberOfArenasAndThreadsAsDefault() throws Exception { // Expected number of arenas and threads int numberOfSlots = 2; NettyConfig config = new NettyConfig(InetAddress.getLocalHost(), NetUtils.getAvailablePort(), 1024, numberOfSlots, new Configuration()); NettyConnectionManager connectionManager = new NettyConnectionManager(config); connectionManager.start(mock(ResultPartitionProvider.class), mock(TaskEventDispatcher.class), mock(NetworkBufferPool.class)); assertEquals(numberOfSlots, connectionManager.getBufferPool().getNumberOfArenas()); { // Client event loop group Bootstrap boostrap = connectionManager.getClient().getBootstrap(); EventLoopGroup group = boostrap.group(); Field f = group.getClass().getSuperclass().getSuperclass().getDeclaredField("children"); f.setAccessible(true); Object[] eventExecutors = (Object[]) f.get(group); assertEquals(numberOfSlots, eventExecutors.length); } { // Server event loop group ServerBootstrap bootstrap = connectionManager.getServer().getBootstrap(); EventLoopGroup group = bootstrap.group(); Field f = group.getClass().getSuperclass().getSuperclass().getDeclaredField("children"); f.setAccessible(true); Object[] eventExecutors = (Object[]) f.get(group); assertEquals(numberOfSlots, eventExecutors.length); } { // Server child event loop group ServerBootstrap bootstrap = connectionManager.getServer().getBootstrap(); EventLoopGroup group = bootstrap.childGroup(); Field f = group.getClass().getSuperclass().getSuperclass().getDeclaredField("children"); f.setAccessible(true); Object[] eventExecutors = (Object[]) f.get(group); assertEquals(numberOfSlots, eventExecutors.length); } }
From source file:org.apache.flink.runtime.io.network.netty.NettyConnectionManagerTest.java
License:Apache License
/** * Tests that the number of arenas and threads can be configured manually. *//*from www. ja va2s . co m*/ @Test public void testManualConfiguration() throws Exception { // Expected numbers int numberOfArenas = 1; int numberOfClientThreads = 3; int numberOfServerThreads = 4; // Expected number of threads Configuration flinkConfig = new Configuration(); flinkConfig.setInteger(NettyConfig.NUM_ARENAS, numberOfArenas); flinkConfig.setInteger(NettyConfig.NUM_THREADS_CLIENT, 3); flinkConfig.setInteger(NettyConfig.NUM_THREADS_SERVER, 4); NettyConfig config = new NettyConfig(InetAddress.getLocalHost(), NetUtils.getAvailablePort(), 1024, 1337, flinkConfig); NettyConnectionManager connectionManager = new NettyConnectionManager(config); connectionManager.start(mock(ResultPartitionProvider.class), mock(TaskEventDispatcher.class), mock(NetworkBufferPool.class)); assertEquals(numberOfArenas, connectionManager.getBufferPool().getNumberOfArenas()); { // Client event loop group Bootstrap boostrap = connectionManager.getClient().getBootstrap(); EventLoopGroup group = boostrap.group(); Field f = group.getClass().getSuperclass().getSuperclass().getDeclaredField("children"); f.setAccessible(true); Object[] eventExecutors = (Object[]) f.get(group); assertEquals(numberOfClientThreads, eventExecutors.length); } { // Server event loop group ServerBootstrap bootstrap = connectionManager.getServer().getBootstrap(); EventLoopGroup group = bootstrap.group(); Field f = group.getClass().getSuperclass().getSuperclass().getDeclaredField("children"); f.setAccessible(true); Object[] eventExecutors = (Object[]) f.get(group); assertEquals(numberOfServerThreads, eventExecutors.length); } { // Server child event loop group ServerBootstrap bootstrap = connectionManager.getServer().getBootstrap(); EventLoopGroup group = bootstrap.childGroup(); Field f = group.getClass().getSuperclass().getSuperclass().getDeclaredField("children"); f.setAccessible(true); Object[] eventExecutors = (Object[]) f.get(group); assertEquals(numberOfServerThreads, eventExecutors.length); } }
From source file:se.sics.gvod.net.NettyNetwork.java
License:Open Source License
private void closeSeverBootstrap(ServerBootstrap serverBootstrap) { serverBootstrap.childGroup().shutdownGracefully(); serverBootstrap.group().shutdownGracefully(); }