List of usage examples for io.netty.channel.udt.nio NioUdtProvider BYTE_ACCEPTOR
ChannelFactory BYTE_ACCEPTOR
To view the source code for io.netty.channel.udt.nio NioUdtProvider BYTE_ACCEPTOR.
Click Source Link
From source file:com.flysoloing.learning.network.netty.udt.echo.bytes.ByteEchoServer.java
License:Apache License
public static void main(String[] args) throws Exception { final ThreadFactory acceptFactory = new DefaultThreadFactory("accept"); final ThreadFactory connectFactory = new DefaultThreadFactory("connect"); final NioEventLoopGroup acceptGroup = new NioEventLoopGroup(1, acceptFactory, NioUdtProvider.BYTE_PROVIDER); final NioEventLoopGroup connectGroup = new NioEventLoopGroup(1, connectFactory, NioUdtProvider.BYTE_PROVIDER); // Configure the server. try {//from w w w .j a va 2s . c om final ServerBootstrap boot = new ServerBootstrap(); boot.group(acceptGroup, connectGroup).channelFactory(NioUdtProvider.BYTE_ACCEPTOR) .option(ChannelOption.SO_BACKLOG, 10).handler(new LoggingHandler(LogLevel.INFO)) .childHandler(new ChannelInitializer<UdtChannel>() { @Override public void initChannel(final UdtChannel ch) throws Exception { ch.pipeline().addLast(new LoggingHandler(LogLevel.INFO), new ByteEchoServerHandler()); } }); // Start the server. final ChannelFuture future = boot.bind(PORT).sync(); // Wait until the server socket is closed. future.channel().closeFuture().sync(); } finally { // Shut down all event loops to terminate all threads. acceptGroup.shutdownGracefully(); connectGroup.shutdownGracefully(); } }
From source file:com.mpush.core.server.GatewayServer.java
License:Apache License
@Override public ChannelFactory<? extends ServerChannel> getChannelFactory() { if (CC.mp.net.tcpGateway()) return super.getChannelFactory(); if (CC.mp.net.udtGateway()) return NioUdtProvider.BYTE_ACCEPTOR; if (CC.mp.net.sctpGateway()) return NioSctpServerChannel::new; return super.getChannelFactory(); }
From source file:io.aos.netty5.udt.echo.bytes.ByteEchoServer.java
License:Apache License
public static void main(String[] args) throws Exception { ExecutorServiceFactory acceptFactory = new DefaultExecutorServiceFactory("accept"); ExecutorServiceFactory connectFactory = new DefaultExecutorServiceFactory("connect"); NioEventLoopGroup acceptGroup = new NioEventLoopGroup(1, acceptFactory, NioUdtProvider.BYTE_PROVIDER); NioEventLoopGroup connectGroup = new NioEventLoopGroup(1, connectFactory, NioUdtProvider.BYTE_PROVIDER); // Configure the server. try {// w ww.j a va2 s .c o m final ServerBootstrap boot = new ServerBootstrap(); boot.group(acceptGroup, connectGroup).channelFactory(NioUdtProvider.BYTE_ACCEPTOR) .option(ChannelOption.SO_BACKLOG, 10).handler(new LoggingHandler(LogLevel.INFO)) .childHandler(new ChannelInitializer<UdtChannel>() { @Override public void initChannel(final UdtChannel ch) throws Exception { ch.pipeline().addLast(new LoggingHandler(LogLevel.INFO), new ByteEchoServerHandler()); } }); // Start the server. final ChannelFuture future = boot.bind(PORT).sync(); // Wait until the server socket is closed. future.channel().closeFuture().sync(); } finally { // Shut down all event loops to terminate all threads. acceptGroup.shutdownGracefully(); connectGroup.shutdownGracefully(); } }
From source file:org.jupiter.transport.netty.JNettyUdtAcceptor.java
License:Apache License
@Override public ChannelFuture bind(SocketAddress localAddress) { ServerBootstrap boot = bootstrap();//from w ww. j a v a 2s . c o m boot.channelFactory(NioUdtProvider.BYTE_ACCEPTOR).childHandler(new ChannelInitializer<UdtChannel>() { @Override protected void initChannel(UdtChannel ch) throws Exception { ch.pipeline().addLast(new IdleStateChecker(timer, READER_IDLE_TIME_SECONDS, 0, 0), idleStateTrigger, new ProtocolDecoder(), encoder, handler); } }); setOptions(); return boot.bind(localAddress); }
From source file:se.sics.gvod.net.NettyNetwork.java
License:Open Source License
/** * Start listening as a server at the given address.. * * @param addr the address to listen at/* w w w. j a v a 2 s .c om*/ * @param port the port number to listen at * @param bindAllNetworkIfs whether to bind on all network interfaces * @return true if listening was started * @throws ChannelException in case binding failed */ private boolean bindUdtPort(InetAddress addr, int port, boolean bindAllNetworkIfs) { if (udtPortsToSockets.containsKey(port)) { return true; } ThreadFactory bossFactory = new UtilThreadFactory("boss"); ThreadFactory workerFactory = new UtilThreadFactory("worker"); NioEventLoopGroup bossGroup = new NioEventLoopGroup(1, bossFactory, NioUdtProvider.BYTE_PROVIDER); NioEventLoopGroup workerGroup = new NioEventLoopGroup(1, workerFactory, NioUdtProvider.BYTE_PROVIDER); NettyUdtServerHandler handler = new NettyUdtServerHandler(component); ServerBootstrap bootstrap = new ServerBootstrap(); bootstrap.group(bossGroup, workerGroup).channelFactory(NioUdtProvider.BYTE_ACCEPTOR) .childHandler(new NettyInitializer<UdtChannel>(handler, msgDecoderClass)) .option(ChannelOption.SO_REUSEADDR, true); try { if (bindAllNetworkIfs) { bootstrap.bind(new InetSocketAddress(port)).sync(); } else { bootstrap.bind(new InetSocketAddress(addr, port)).sync(); } logger.debug("Successfully bound to ip:port {}:{}", addr, port); } catch (InterruptedException e) { logger.warn("Problem when trying to bind to {}:{}", addr.getHostAddress(), port); trigger(new Fault(e.getCause()), control); return false; } InetSocketAddress iAddr = new InetSocketAddress(addr, port); udtPortsToSockets.put(port, iAddr); udtSocketsToServerBootstraps.put(iAddr, bootstrap); return true; }
From source file:se.sics.kompics.network.netty.NettyNetwork.java
License:Open Source License
private boolean bindUdtPort(InetAddress addr) { ThreadFactory bossFactory = Executors.defaultThreadFactory(); ThreadFactory workerFactory = Executors.defaultThreadFactory(); NioEventLoopGroup bossGroup = new NioEventLoopGroup(1, bossFactory, NioUdtProvider.BYTE_PROVIDER); NioEventLoopGroup workerGroup = new NioEventLoopGroup(1, workerFactory, NioUdtProvider.BYTE_PROVIDER); UDTServerHandler handler = new UDTServerHandler(this); bootstrapUDT = new ServerBootstrap(); bootstrapUDT.group(bossGroup, workerGroup).channelFactory(NioUdtProvider.BYTE_ACCEPTOR) .childHandler(new NettyInitializer<UdtChannel>(handler)).option(ChannelOption.SO_REUSEADDR, true); try {//from w w w . j av a 2s. c o m Channel c = bootstrapUDT.bind(addr, 0).sync().channel(); InetSocketAddress localAddress = (InetSocketAddress) c.localAddress(); // Should work boundUDTPort = localAddress.getPort(); LOG.info("Successfully bound UDT to ip:port {}:{}", addr, boundUDTPort); } catch (InterruptedException e) { LOG.error("Problem when trying to bind UDT to {}", addr); return false; } return true; }