static List<BootstrapFactory<ServerBootstrap>> sctpServerChannel() { if (!TestUtils.isSctpSupported()) { return Collections.emptyList(); } List<BootstrapFactory<ServerBootstrap>> list = new ArrayList<BootstrapFactory<ServerBootstrap>>(); // Make the list of ServerBootstrap factories. list.add(new BootstrapFactory<ServerBootstrap>() { @Override public ServerBootstrap newInstance() { return new ServerBootstrap(). group(nioBossGroup, nioWorkerGroup). channel(NioSctpServerChannel.class); } }); list.add(new BootstrapFactory<ServerBootstrap>() { @Override public ServerBootstrap newInstance() { return new ServerBootstrap(). group(oioBossGroup, oioWorkerGroup). channel(OioSctpServerChannel.class); } }); return list; }
static List<Factory<ServerBootstrap>> sctpServerChannel() { if (!TestUtils.isSctpSupported()) { return Collections.emptyList(); } List<Factory<ServerBootstrap>> list = new ArrayList<Factory<ServerBootstrap>>(); // Make the list of ServerBootstrap factories. list.add(new Factory<ServerBootstrap>() { @Override public ServerBootstrap newInstance() { return new ServerBootstrap(). group(nioBossGroup, nioWorkerGroup). channel(NioSctpServerChannel.class); } }); list.add(new Factory<ServerBootstrap>() { @Override public ServerBootstrap newInstance() { return new ServerBootstrap(). group(oioBossGroup, oioWorkerGroup). channel(OioSctpServerChannel.class); } }); return list; }
public void run() throws Exception { // Configure the server. EventLoopGroup bossGroup = new OioEventLoopGroup(); EventLoopGroup workerGroup = new OioEventLoopGroup(); try { ServerBootstrap b = new ServerBootstrap(); b.group(bossGroup, workerGroup) .channel(OioSctpServerChannel.class) .option(ChannelOption.SO_BACKLOG, 100) .handler(new LoggingHandler(LogLevel.INFO)) .childHandler(new ChannelInitializer<SctpChannel>() { @Override public void initChannel(SctpChannel ch) throws Exception { ch.pipeline().addLast( new LoggingHandler(LogLevel.INFO), new SctpEchoServerHandler()); } }); // Start the server. ChannelFuture f = b.bind(port).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(); } }