io.netty.channel.epoll.EpollServerSocketChannel Java Examples
The following examples show how to use
io.netty.channel.epoll.EpollServerSocketChannel.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TransportServerSupport.java From journalkeeper with Apache License 2.0 | 6 votes |
protected ServerBootstrap newBootstrap(ChannelHandler channelHandler, EventLoopGroup acceptEventGroup, EventLoopGroup ioEventGroup) throws Exception { ServerBootstrap serverBootstrap = new ServerBootstrap(); serverBootstrap.channel(Epoll.isAvailable() ? EpollServerSocketChannel.class : NioServerSocketChannel.class) .group(acceptEventGroup, ioEventGroup) .childHandler(channelHandler) .option(ChannelOption.SO_REUSEADDR, serverConfig.isReuseAddress()) .option(ChannelOption.SO_RCVBUF, serverConfig.getSocketBufferSize()) .option(ChannelOption.SO_BACKLOG, serverConfig.getBacklog()) .option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT) .childOption(ChannelOption.SO_SNDBUF, serverConfig.getSocketBufferSize()) .childOption(ChannelOption.TCP_NODELAY, serverConfig.isTcpNoDelay()) .childOption(ChannelOption.SO_KEEPALIVE, serverConfig.isKeepAlive()) .childOption(ChannelOption.SO_LINGER, serverConfig.getSoLinger()) .childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT); return serverBootstrap; }
Example #2
Source File: NettyNetworking.java From Cleanstone with MIT License | 6 votes |
@Override public void start() { bossGroup = epoll ? new EpollEventLoopGroup() : new NioEventLoopGroup(); workerGroup = epoll ? new EpollEventLoopGroup() : new NioEventLoopGroup(); ServerBootstrap bootstrap = new ServerBootstrap(); bootstrap.group(bossGroup, workerGroup) .channel(epoll ? EpollServerSocketChannel.class : NioServerSocketChannel.class) .childHandler(new ServerChannelInitializer(this)) .option(ChannelOption.SO_BACKLOG, socketBacklog) .childOption(ChannelOption.SO_KEEPALIVE, socketKeepAlive); bootstrap.localAddress(this.getAddress(), this.getPort()); bootstrap.bind().addListener(future -> { if (future.isSuccess()) { log.info(CleanstoneServer.getMessage("net.netty.bind-successful", protocol.getClass().getSimpleName(), getAddress(), getPort() + "")); } else { log.error(CleanstoneServer.getMessage("net.netty.bind-failure", getAddress().getHostAddress(), getPort() + ""), future.cause()); } }); running = true; }
Example #3
Source File: DefaultLoopEpoll.java From reactor-netty with Apache License 2.0 | 6 votes |
@Override @SuppressWarnings("unchecked") public <CHANNEL extends Channel> CHANNEL getChannel(Class<CHANNEL> channelClass) { if (channelClass.equals(SocketChannel.class)) { return (CHANNEL) new EpollSocketChannel(); } if (channelClass.equals(ServerSocketChannel.class)) { return (CHANNEL) new EpollServerSocketChannel(); } if (channelClass.equals(DatagramChannel.class)) { return (CHANNEL) new EpollDatagramChannel(); } if (channelClass.equals(DomainSocketChannel.class)) { return (CHANNEL) new EpollDomainSocketChannel(); } if (channelClass.equals(ServerDomainSocketChannel.class)) { return (CHANNEL) new EpollServerDomainSocketChannel(); } throw new IllegalArgumentException("Unsupported channel type: " + channelClass.getSimpleName()); }
Example #4
Source File: NettyServer.java From rpcx-java with Apache License 2.0 | 6 votes |
private ServerBootstrap createServerBootstrap() { return this.serverBootstrap.group(this.eventLoopGroupBoss, this.eventLoopGroupWorker) .channel(useEpoll() ? EpollServerSocketChannel.class : NioServerSocketChannel.class) .option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT) .option(ChannelOption.SO_BACKLOG, 1024) .option(ChannelOption.SO_REUSEADDR, true) .option(ChannelOption.SO_KEEPALIVE, false) .option(ChannelOption.SO_LINGER, 3) .childOption(ChannelOption.TCP_NODELAY, true) .option(ChannelOption.SO_SNDBUF, nettyServerConfig.getServerSocketSndBufSize()) .option(ChannelOption.SO_RCVBUF, nettyServerConfig.getServerSocketRcvBufSize()) .localAddress(new InetSocketAddress(this.nettyServerConfig.getListenPort())) .childHandler(new ChannelInitializer<SocketChannel>() { @Override public void initChannel(SocketChannel ch) { ch.pipeline().addLast( new RpcxProcessHandler(nettyServerConfig.getServerChannelMaxIdleTimeSeconds(), NettyServer.this) ); } }); }
Example #5
Source File: HttpServerBoot.java From elastic-rabbitmq with MIT License | 6 votes |
public void run() throws Exception { ServerBootstrap b = new ServerBootstrap(); try { if (isEpollAvailable) { b.group(new EpollEventLoopGroup(this.conf.getEventLoopThreadCount())) .channel(EpollServerSocketChannel.class); } else { b.group(new NioEventLoopGroup(this.conf.getEventLoopThreadCount())) .channel(NioServerSocketChannel.class); } b.childHandler(new DefaultServerInitializer(conf, context)) .option(ChannelOption.SO_BACKLOG, conf.getBacklog()) .option(ChannelOption.SO_REUSEADDR, true); Channel ch = b.bind(conf.getPort()).sync().channel(); ch.closeFuture().sync(); } finally { } }
Example #6
Source File: EpollEchoServer.java From netty.book.kor with MIT License | 6 votes |
public static void main(String[] args) throws Exception { EventLoopGroup bossGroup = new EpollEventLoopGroup(1); EventLoopGroup workerGroup = new EpollEventLoopGroup(); try { ServerBootstrap b = new ServerBootstrap(); b.group(bossGroup, workerGroup) .channel(EpollServerSocketChannel.class) .childHandler(new ChannelInitializer<SocketChannel>() { @Override public void initChannel(SocketChannel ch) { ChannelPipeline p = ch.pipeline(); p.addLast(new EchoServerHandler()); } }); ChannelFuture f = b.bind(8888).sync(); f.channel().closeFuture().sync(); } finally { workerGroup.shutdownGracefully(); bossGroup.shutdownGracefully(); } }
Example #7
Source File: TcpProtocolServer.java From Okra with Apache License 2.0 | 6 votes |
@Override public ServerBootstrap createBootstrap() { bootstrap = new ServerBootstrap(); if (isEpollAvailable) { this.parentGroup = new EpollEventLoopGroup(); this.childGroup = new EpollEventLoopGroup(); bootstrap.channel(EpollServerSocketChannel.class); } else { this.parentGroup = new NioEventLoopGroup(); this.childGroup = new NioEventLoopGroup(); bootstrap.channel(NioServerSocketChannel.class); } bootstrap.group(parentGroup(), childGroup()); bootstrap.childHandler(newChannelInitializer()); bootstrap.option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT); // bootstrap.option(ChannelOption.SO_REUSEADDR, true); // bootstrap.childOption(ChannelOption.TCP_NODELAY, true); bootstrap.childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT); return bootstrap; }
Example #8
Source File: NettyServerTransport.java From joyrpc with Apache License 2.0 | 6 votes |
/** * 配置 * * @param bootstrap * @param sslContext */ protected ServerBootstrap configure(final ServerBootstrap bootstrap, final SslContext sslContext) { //io.netty.bootstrap.Bootstrap - Unknown channel option 'SO_BACKLOG' for channel bootstrap.channel(Constants.isUseEpoll(url) ? EpollServerSocketChannel.class : NioServerSocketChannel.class) .childHandler(new MyChannelInitializer(url, sslContext)) .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, url.getPositiveInt(Constants.CONNECT_TIMEOUT_OPTION)) .option(ChannelOption.SO_REUSEADDR, url.getBoolean(Constants.SO_REUSE_PORT_OPTION)) .option(ChannelOption.SO_BACKLOG, url.getPositiveInt(Constants.SO_BACKLOG_OPTION)) .option(ChannelOption.RCVBUF_ALLOCATOR, AdaptiveRecvByteBufAllocator.DEFAULT) .option(ChannelOption.WRITE_BUFFER_WATER_MARK, new WriteBufferWaterMark(url.getPositiveInt(Constants.WRITE_BUFFER_LOW_WATERMARK_OPTION), url.getPositiveInt(Constants.WRITE_BUFFER_HIGH_WATERMARK_OPTION))) .childOption(ChannelOption.SO_RCVBUF, url.getPositiveInt(Constants.SO_RECEIVE_BUF_OPTION)) .childOption(ChannelOption.SO_SNDBUF, url.getPositiveInt(Constants.SO_SEND_BUF_OPTION)) .childOption(ChannelOption.SO_KEEPALIVE, url.getBoolean(Constants.SO_KEEPALIVE_OPTION)) .childOption(ChannelOption.TCP_NODELAY, url.getBoolean(Constants.TCP_NODELAY)) .childOption(ChannelOption.ALLOCATOR, BufAllocator.create(url)); return bootstrap; }
Example #9
Source File: TransportServerSupport.java From joyqueue with Apache License 2.0 | 6 votes |
protected ServerBootstrap newBootstrap(ChannelHandler channelHandler, EventLoopGroup acceptEventGroup, EventLoopGroup ioEventGroup) throws Exception { ServerBootstrap serverBootstrap = new ServerBootstrap(); serverBootstrap.channel(Epoll.isAvailable() ? EpollServerSocketChannel.class : NioServerSocketChannel.class) .group(acceptEventGroup, ioEventGroup) .childHandler(channelHandler) .option(ChannelOption.SO_REUSEADDR, config.isReuseAddress()) .option(ChannelOption.SO_RCVBUF, config.getSocketBufferSize()) .option(ChannelOption.SO_BACKLOG, config.getBacklog()) .option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT) .childOption(ChannelOption.SO_SNDBUF, config.getSocketBufferSize()) .childOption(ChannelOption.TCP_NODELAY, config.isTcpNoDelay()) .childOption(ChannelOption.SO_KEEPALIVE, config.isKeepAlive()) .childOption(ChannelOption.SO_LINGER, config.getSoLinger()) .childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT); return serverBootstrap; }
Example #10
Source File: NettyMessagingService.java From atomix with Apache License 2.0 | 6 votes |
private void initEventLoopGroup() { // try Epoll first and if that does work, use nio. try { clientGroup = new EpollEventLoopGroup(0, namedThreads("netty-messaging-event-epoll-client-%d", log)); serverGroup = new EpollEventLoopGroup(0, namedThreads("netty-messaging-event-epoll-server-%d", log)); serverChannelClass = EpollServerSocketChannel.class; clientChannelClass = EpollSocketChannel.class; return; } catch (Throwable e) { log.debug("Failed to initialize native (epoll) transport. " + "Reason: {}. Proceeding with nio.", e.getMessage()); } clientGroup = new NioEventLoopGroup(0, namedThreads("netty-messaging-event-nio-client-%d", log)); serverGroup = new NioEventLoopGroup(0, namedThreads("netty-messaging-event-nio-server-%d", log)); serverChannelClass = NioServerSocketChannel.class; clientChannelClass = NioSocketChannel.class; }
Example #11
Source File: NettyServer.java From Kepler with GNU Lesser General Public License v3.0 | 6 votes |
/** * Create the Netty sockets. */ public void createSocket() { int threads = Runtime.getRuntime().availableProcessors(); this.bossGroup = (Epoll.isAvailable()) ? new EpollEventLoopGroup(threads) : new NioEventLoopGroup(threads); this.workerGroup = (Epoll.isAvailable()) ? new EpollEventLoopGroup(threads) : new NioEventLoopGroup(threads); this.bootstrap.group(bossGroup, workerGroup) .channel((Epoll.isAvailable()) ? EpollServerSocketChannel.class : NioServerSocketChannel.class) .childHandler(new NettyChannelInitializer(this)) .option(ChannelOption.SO_BACKLOG, BACK_LOG) .childOption(ChannelOption.TCP_NODELAY, true) .childOption(ChannelOption.SO_KEEPALIVE, true) .childOption(ChannelOption.SO_RCVBUF, BUFFER_SIZE) .childOption(ChannelOption.RCVBUF_ALLOCATOR, new FixedRecvByteBufAllocator(BUFFER_SIZE)) .childOption(ChannelOption.ALLOCATOR, new PooledByteBufAllocator(true)); }
Example #12
Source File: MusServer.java From Kepler with GNU Lesser General Public License v3.0 | 6 votes |
/** * Create the Netty sockets. */ public void createSocket() { int threads = Runtime.getRuntime().availableProcessors(); this.bossGroup = (Epoll.isAvailable()) ? new EpollEventLoopGroup(threads) : new NioEventLoopGroup(threads); this.workerGroup = (Epoll.isAvailable()) ? new EpollEventLoopGroup(threads) : new NioEventLoopGroup(threads); this.bootstrap.group(bossGroup, workerGroup) .channel((Epoll.isAvailable()) ? EpollServerSocketChannel.class : NioServerSocketChannel.class) .childHandler(new MusChannelInitializer(this)) .option(ChannelOption.SO_BACKLOG, BACK_LOG) .childOption(ChannelOption.TCP_NODELAY, true) .childOption(ChannelOption.SO_KEEPALIVE, true) .childOption(ChannelOption.SO_RCVBUF, BUFFER_SIZE) .childOption(ChannelOption.RCVBUF_ALLOCATOR, new FixedRecvByteBufAllocator(BUFFER_SIZE)) .childOption(ChannelOption.ALLOCATOR, new PooledByteBufAllocator(true)); }
Example #13
Source File: BGPDispatcherImpl.java From bgpcep with Eclipse Public License 1.0 | 6 votes |
private synchronized ServerBootstrap createServerBootstrap(final ChannelPipelineInitializer<?> initializer) { final ServerBootstrap serverBootstrap = new ServerBootstrap(); if (Epoll.isAvailable()) { serverBootstrap.channel(EpollServerSocketChannel.class); serverBootstrap.childOption(EpollChannelOption.EPOLL_MODE, EpollMode.LEVEL_TRIGGERED); } else { serverBootstrap.channel(NioServerSocketChannel.class); } final ChannelHandler serverChannelHandler = BGPChannel.createServerChannelHandler(initializer); serverBootstrap.childHandler(serverChannelHandler); serverBootstrap.option(ChannelOption.SO_BACKLOG, SOCKET_BACKLOG_SIZE); serverBootstrap.childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT); serverBootstrap.childOption(ChannelOption.WRITE_BUFFER_WATER_MARK, WATER_MARK); // Make sure we are doing round-robin processing serverBootstrap.option(ChannelOption.RCVBUF_ALLOCATOR, RECV_ALLOCATOR); if (serverBootstrap.config().group() == null) { serverBootstrap.group(this.bossGroup, this.workerGroup); } return serverBootstrap; }
Example #14
Source File: NettyExecutor.java From styx with Apache License 2.0 | 6 votes |
/** * Constructs an netty/io event executor. * * @param name thread group name. * @param count thread count. * @return */ public static NettyExecutor create(String name, int count) { if (Epoll.isAvailable()) { LOG.info("Epoll is available. Using the native socket transport."); return new NettyExecutor( epollEventLoopGroup(count, name + "-%d-Thread"), EpollServerSocketChannel.class, EpollSocketChannel.class); } else { LOG.info("Epoll not available. Using nio socket transport."); return new NettyExecutor( nioEventLoopGroup(count, name + "-%d-Thread"), NioServerSocketChannel.class, NioSocketChannel.class); } }
Example #15
Source File: DefaultLoopEpoll.java From reactor-netty with Apache License 2.0 | 5 votes |
@Override @SuppressWarnings("unchecked") public <CHANNEL extends Channel> Class<? extends CHANNEL> getChannelClass(Class<CHANNEL> channelClass) { if (channelClass.equals(SocketChannel.class)) { return (Class<? extends CHANNEL>) EpollSocketChannel.class; } if (channelClass.equals(ServerSocketChannel.class)) { return (Class<? extends CHANNEL>) EpollServerSocketChannel.class; } if (channelClass.equals(DatagramChannel.class)) { return (Class<? extends CHANNEL>) EpollDatagramChannel.class; } throw new IllegalArgumentException("Unsupported channel type: " + channelClass.getSimpleName()); }
Example #16
Source File: EventLoopUtil.java From pulsar with Apache License 2.0 | 5 votes |
public static Class<? extends ServerSocketChannel> getServerSocketChannelClass(EventLoopGroup eventLoopGroup) { if (eventLoopGroup instanceof EpollEventLoopGroup) { return EpollServerSocketChannel.class; } else { return NioServerSocketChannel.class; } }
Example #17
Source File: ShardingSphereProxy.java From shardingsphere with Apache License 2.0 | 5 votes |
private void groupsEpoll(final ServerBootstrap bootstrap) { workerGroup = new EpollEventLoopGroup(); bootstrap.group(bossGroup, workerGroup) .channel(EpollServerSocketChannel.class) .option(EpollChannelOption.SO_BACKLOG, 128) .option(EpollChannelOption.WRITE_BUFFER_WATER_MARK, new WriteBufferWaterMark(8 * 1024 * 1024, 16 * 1024 * 1024)) .option(EpollChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT) .childOption(EpollChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT) .childOption(EpollChannelOption.TCP_NODELAY, true) .handler(new LoggingHandler(LogLevel.INFO)) .childHandler(new ServerHandlerInitializer()); }
Example #18
Source File: SocketChannelProvider.java From Jupiter with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") @Override public T newChannel() { switch (channelType) { case ACCEPTOR: switch (socketType) { case JAVA_NIO: return (T) new NioServerSocketChannel(); case NATIVE_EPOLL: return (T) new EpollServerSocketChannel(); case NATIVE_KQUEUE: return (T) new KQueueServerSocketChannel(); case NATIVE_EPOLL_DOMAIN: return (T) new EpollServerDomainSocketChannel(); case NATIVE_KQUEUE_DOMAIN: return (T) new KQueueServerDomainSocketChannel(); default: throw new IllegalStateException("Invalid socket type: " + socketType); } case CONNECTOR: switch (socketType) { case JAVA_NIO: return (T) new NioSocketChannel(); case NATIVE_EPOLL: return (T) new EpollSocketChannel(); case NATIVE_KQUEUE: return (T) new KQueueSocketChannel(); case NATIVE_EPOLL_DOMAIN: return (T) new EpollDomainSocketChannel(); case NATIVE_KQUEUE_DOMAIN: return (T) new KQueueDomainSocketChannel(); default: throw new IllegalStateException("Invalid socket type: " + socketType); } default: throw new IllegalStateException("Invalid channel type: " + channelType); } }
Example #19
Source File: BmpDispatcherUtil.java From bgpcep with Eclipse Public License 1.0 | 5 votes |
public static ServerBootstrap createServerBootstrap(final @NonNull BmpSessionFactory sessionFactory, final @NonNull BmpHandlerFactory hf, final @NonNull BmpSessionListenerFactory slf, final @NonNull CreateChannel createChannel, final @NonNull EventLoopGroup bossGroup, final @NonNull EventLoopGroup workerGroup, final @NonNull KeyMapping keys, boolean tryEpollSocket) { final ServerBootstrap serverBootstrap = new ServerBootstrap(); serverBootstrap.childHandler(createChannel.create(sessionFactory, hf, slf)); serverBootstrap.option(ChannelOption.SO_BACKLOG, MAX_CONNECTIONS_COUNT); serverBootstrap.childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT); serverBootstrap.group(bossGroup, workerGroup); if (!tryEpollSocket) { serverBootstrap.channel(NioServerSocketChannel.class); } else { if (Epoll.isAvailable()) { serverBootstrap.channel(EpollServerSocketChannel.class); } else { serverBootstrap.channel(NioServerSocketChannel.class); } if (!keys.isEmpty()) { if (Epoll.isAvailable()) { serverBootstrap.option(EpollChannelOption.TCP_MD5SIG, keys); } else { throw new UnsupportedOperationException(Epoll.unavailabilityCause().getCause()); } } } return serverBootstrap; }
Example #20
Source File: PCEPDispatcherImpl.java From bgpcep with Eclipse Public License 1.0 | 5 votes |
synchronized ServerBootstrap createServerBootstrap(final ChannelPipelineInitializer initializer) { final ServerBootstrap b = new ServerBootstrap(); b.childHandler(new ChannelInitializer<SocketChannel>() { @Override protected void initChannel(final SocketChannel ch) { initializer.initializeChannel(ch, new DefaultPromise<>(PCEPDispatcherImpl.this.executor)); } }); b.option(ChannelOption.SO_BACKLOG, SOCKET_BACKLOG_SIZE); b.childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT); if (Epoll.isAvailable()) { b.channel(EpollServerSocketChannel.class); b.childOption(EpollChannelOption.EPOLL_MODE, EpollMode.LEVEL_TRIGGERED); } else { b.channel(NioServerSocketChannel.class); } if (!this.keys.isEmpty()) { if (Epoll.isAvailable()) { b.option(EpollChannelOption.TCP_MD5SIG, this.keys); } else { throw new UnsupportedOperationException(Epoll.unavailabilityCause().getCause()); } } // Make sure we are doing round-robin processing b.childOption(ChannelOption.RCVBUF_ALLOCATOR, new FixedRecvByteBufAllocator(1)); if (b.config().group() == null) { b.group(this.bossGroup, this.workerGroup); } return b; }
Example #21
Source File: HelloWebServer.java From crow-benchmark with BSD 3-Clause "New" or "Revised" License | 5 votes |
public void run() throws Exception { // Configure the server. if (Epoll.isAvailable()) { doRun(new EpollEventLoopGroup(), EpollServerSocketChannel.class); } else { doRun(new NioEventLoopGroup(), NioServerSocketChannel.class); } }
Example #22
Source File: HelloWebServer.java From FrameworkBenchmarks with BSD 3-Clause "New" or "Revised" License | 5 votes |
public void run() throws Exception { // Configure the server. if (Epoll.isAvailable()) { doRun(new EpollEventLoopGroup(), EpollServerSocketChannel.class, IoMultiplexer.EPOLL); } else if (KQueue.isAvailable()) { doRun(new EpollEventLoopGroup(), KQueueServerSocketChannel.class, IoMultiplexer.KQUEUE); } else { doRun(new NioEventLoopGroup(), NioServerSocketChannel.class, IoMultiplexer.JDK); } }
Example #23
Source File: NettyServer.java From ambry with Apache License 2.0 | 5 votes |
/** * Bootstrap a new server with a {@link ChannelInitializer} and bind it to a port. * @param port the port number to bind this server to. * @param channelInitializer the {@link ChannelInitializer} for request handling on this server. * @param bossGroup the pool of boss threads that this server uses. * @param workerGroup the pool of worker threads that this server uses. * @throws InterruptedException if binding to the port failed. */ private void bindServer(int port, ChannelInitializer<SocketChannel> channelInitializer, EventLoopGroup bossGroup, EventLoopGroup workerGroup) throws InterruptedException { ServerBootstrap b = new ServerBootstrap(); Class<? extends ServerSocketChannel> channelClass = Epoll.isAvailable() ? EpollServerSocketChannel.class : NioServerSocketChannel.class; // Note: ServerSocketChannel option doesn't apply to SocketChannel b.group(bossGroup, workerGroup) .channel(channelClass) .option(ChannelOption.SO_BACKLOG, nettyConfig.nettyServerSoBacklog) .handler(new LoggingHandler(LogLevel.DEBUG)) .childHandler(channelInitializer); b.bind(port).sync(); logger.info("NettyServer now listening on port {}", port); }
Example #24
Source File: TChannel.java From tchannel-java with MIT License | 5 votes |
private @NotNull ServerBootstrap serverBootstrap(@NotNull TChannel topChannel) { return new ServerBootstrap() .group(this.bossGroup, this.childGroup) .channel(useEpoll ? EpollServerSocketChannel.class : NioServerSocketChannel.class) .handler(new LoggingHandler(LogLevel.INFO)) .option(ChannelOption.SO_BACKLOG, 128) .childHandler(this.channelInitializer(true, topChannel)) .childOption(ChannelOption.SO_KEEPALIVE, true) .childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT) .childOption( ChannelOption.WRITE_BUFFER_WATER_MARK, new WriteBufferWaterMark(WRITE_BUFFER_LOW_WATER_MARK, WRITE_BUFFER_HIGH_WATER_MARK) ) .validate(); }
Example #25
Source File: Connector.java From multi-model-server with Apache License 2.0 | 5 votes |
public Class<? extends ServerChannel> getServerChannel() { if (useNativeIo && Epoll.isAvailable()) { return uds ? EpollServerDomainSocketChannel.class : EpollServerSocketChannel.class; } else if (useNativeIo && KQueue.isAvailable()) { return uds ? KQueueServerDomainSocketChannel.class : KQueueServerSocketChannel.class; } return NioServerSocketChannel.class; }
Example #26
Source File: TransportCheck.java From Bats with Apache License 2.0 | 5 votes |
public static Class<? extends ServerSocketChannel> getServerSocketChannel(){ if(SUPPORTS_EPOLL){ return EpollServerSocketChannel.class; }else{ return NioServerSocketChannel.class; } }
Example #27
Source File: MqttServer.java From lannister with Apache License 2.0 | 5 votes |
private void executeBootstrap(ScheduledExecutor scheduledExecutor, int port, boolean useWebSocket, boolean useSsl) throws InterruptedException { ServerBootstrap bootstrap = new ServerBootstrap(); Class<? extends ServerChannel> serverChannelClass; if (Literals.NETTY_EPOLL.equals(Settings.INSTANCE.nettyTransportMode())) { serverChannelClass = EpollServerSocketChannel.class; } else { serverChannelClass = NioServerSocketChannel.class; } bootstrap = bootstrap.group(bossGroup, workerGroup).channel(serverChannelClass); bootstrap.option(ChannelOption.TCP_NODELAY, true); if (scheduledExecutor != null) { bootstrap.handler(scheduledExecutor); } bootstrap.childHandler(new MqttChannelInitializer(useWebSocket, useSsl)); bootstrap.childOption(ChannelOption.TCP_NODELAY, true) // setting buffer size can improve I/O .childOption(ChannelOption.SO_SNDBUF, 1048576).childOption(ChannelOption.SO_RCVBUF, 1048576) // recommended in // http://normanmaurer.me/presentations/2014-facebook-eng-netty/slides.html#11.0 .childOption(ChannelOption.WRITE_BUFFER_WATER_MARK, new WriteBufferWaterMark(8 * 1024, 32 * 1024)) .childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT); bootstrap.bind(port).sync(); }
Example #28
Source File: GrpcServer.java From rpc-thunderdome with Apache License 2.0 | 5 votes |
public static void main(String... args) throws Exception { logger.info("starting server"); String host = System.getProperty("host", "0.0.0.0"); int port = Integer.getInteger("port", 8001); boolean useEpoll = Boolean.getBoolean("usePoll"); Class channel; if (useEpoll) { channel = EpollServerSocketChannel.class; } else { channel = NioServerSocketChannel.class; } ThreadFactory tf = new DefaultThreadFactory("server-elg-", true /*daemon */); NioEventLoopGroup boss = new NioEventLoopGroup(1, tf); NioEventLoopGroup worker = new NioEventLoopGroup(0, tf); NettyServerBuilder builder = NettyServerBuilder.forPort(port) .bossEventLoopGroup(boss) .workerEventLoopGroup(worker) .channelType(channel) .addService(new DefaultService()) .directExecutor() .maxConcurrentCallsPerConnection(Runtime.getRuntime().availableProcessors() * 256) .flowControlWindow(NettyChannelBuilder.DEFAULT_FLOW_CONTROL_WINDOW * 10); io.grpc.Server start = builder.build(); start.start(); logger.info("server started"); start.awaitTermination(); }
Example #29
Source File: TransportCheck.java From dremio-oss with Apache License 2.0 | 5 votes |
public static Class<? extends ServerSocketChannel> getServerSocketChannel(){ if(SUPPORTS_EPOLL){ return EpollServerSocketChannel.class; }else{ return NioServerSocketChannel.class; } }
Example #30
Source File: Server.java From rpc-benchmark with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws InterruptedException { if (Epoll.isAvailable()) { doRun(// new EpollEventLoopGroup(), // EpollServerSocketChannel.class, // true); } else { doRun(// new NioEventLoopGroup(), // NioServerSocketChannel.class, // false); } }