protected AbstractNettyServer(String serverName) {
this.serverName = Objects.requireNonNull(serverName, "server name");
bootstrap = new ServerBootstrap();
if (Epoll.isAvailable()) {
bootstrap.option(ChannelOption.SO_BACKLOG, 1024).channel(EpollServerSocketChannel.class)
.childOption(ChannelOption.SO_LINGER, 0).childOption(ChannelOption.SO_REUSEADDR, true)
.childOption(ChannelOption.SO_KEEPALIVE, true);
log.info(serverName + " epoll init");
} else {
bootstrap.channel(NioServerSocketChannel.class);
log.info(serverName + " nio init");
}
bootstrap.group(bossGroup, workerGroup).option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT)
.childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT)
.childOption(ChannelOption.TCP_NODELAY, true).childHandler(new ChannelInitializer<SocketChannel>() {
@Override
protected void initChannel(SocketChannel ch) throws Exception {
initPipeline(ch.pipeline());
}
});
}
java类io.netty.channel.epoll.EpollServerSocketChannel的实例源码
AbstractNettyServer.java 文件源码
项目:Limitart
阅读 26
收藏 0
点赞 0
评论 0
PluginGrpcServer.java 文件源码
项目:JungleTree
阅读 26
收藏 0
点赞 0
评论 0
public PluginGrpcServer(int port) {
this.pluginConnections = new HashMap<>();
PlayerEvents playerEvents = new PlayerEvents(this);
this.server = NettyServerBuilder.forPort(port)
.keepAliveTime(1, TimeUnit.MINUTES)
.keepAliveTimeout(5, TimeUnit.SECONDS)
.addService(playerEvents)
.directExecutor()
.channelType(EpollServerSocketChannel.class)
.bossEventLoopGroup(new EpollEventLoopGroup())
.workerEventLoopGroup(new EpollEventLoopGroup())
.build();
// demoPluginConnections();
}
ConnectionProvider.java 文件源码
项目:UnknownPandaServer
阅读 25
收藏 0
点赞 0
评论 0
public void start() throws Exception {
UnknownPandaServer.getLogger().info("Loading protocol");
Protocol protocol = ProtocolSpecification.getProtocol();
protocol.load();
UnknownPandaServer.getLogger().info("Binding UniverseServer at *::" + port + " [tcp]");
this.channel = new ServerBootstrap()
.group(Epoll.isAvailable() ? new EpollEventLoopGroup() : new NioEventLoopGroup())
.channel(Epoll.isAvailable() ? EpollServerSocketChannel.class : NioServerSocketChannel.class)
//.childOption(ChannelOption.TCP_NODELAY, true)
.childHandler(new ConnectionInitializer(this))
.localAddress("", port)
.bind()
.addListeners(this)
.sync()
.channel();
}
NettyEmbeddedServletContainer.java 文件源码
项目:nebo
阅读 28
收藏 0
点赞 0
评论 0
private void groups(ServerBootstrap b) {
if (StandardSystemProperty.OS_NAME.value().equals("Linux")) {
bossGroup = new EpollEventLoopGroup(1);
workerGroup = new EpollEventLoopGroup();
b.channel(EpollServerSocketChannel.class)
.group(bossGroup, workerGroup)
.option(EpollChannelOption.TCP_CORK, true);
} else {
bossGroup = new NioEventLoopGroup(1);
workerGroup = new NioEventLoopGroup();
b.channel(NioServerSocketChannel.class)
.group(bossGroup, workerGroup);
}
b.option(ChannelOption.TCP_NODELAY, true)
.option(ChannelOption.SO_REUSEADDR, true)
.option(ChannelOption.SO_BACKLOG, 100);
logger.info("Bootstrap configuration: " + b.toString());
}
HttpServerBoot.java 文件源码
项目:elastic-rabbitmq
阅读 26
收藏 0
点赞 0
评论 0
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 {
}
}
ServerConnection.java 文件源码
项目:Diorite-old
阅读 24
收藏 0
点赞 0
评论 0
@Override
public void init(final InetAddress address, final int port, final boolean useEpoll)
{
final Class<? extends ServerSocketChannel> socketChannelClass;
final LazyValue<? extends EventLoopGroup> lazyInit;
if ((Epoll.isAvailable()) && useEpoll)
{
socketChannelClass = EpollServerSocketChannel.class;
lazyInit = this.epollEventLoopGroupLazyValue;
CoreMain.debug("[Netty] Using epoll channel type");
}
else
{
socketChannelClass = NioServerSocketChannel.class;
lazyInit = this.nioEventLoopGroupLazyValue;
CoreMain.debug("[Netty] Using default channel type");
}
this.channelFuture = new ServerBootstrap().channel(socketChannelClass).childHandler(new ServerConnectionChannel(this)).group(lazyInit.get()).localAddress(address, port).bind().syncUninterruptibly();
}
NettyNetworkingService.java 文件源码
项目:Coerce
阅读 25
收藏 0
点赞 0
评论 0
@Override
public void initialise(NetworkChannelHandler channelHandler) {
this.channelHandler = channelHandler;
final boolean useEpoll = this.configuration.getBoolean("epoll") && Epoll.isAvailable();
EventLoopGroup acceptGroup = useEpoll ? new EpollEventLoopGroup(this.configuration.getInt("acceptGroup")) :
new NioEventLoopGroup(this.configuration.getInt("acceptGroup"));
EventLoopGroup ioGroup = useEpoll ? new EpollEventLoopGroup(this.configuration.getInt("ioGroup")) :
new NioEventLoopGroup(this.configuration.getInt("ioGroup"));
EventLoopGroup channelGroup = useEpoll ? new EpollEventLoopGroup(this.configuration.getInt("channelGroup")) :
new NioEventLoopGroup(this.configuration.getInt("channelGroup"));
this.serverBootstrap = new ServerBootstrap()
.group(acceptGroup, ioGroup)
.channel(useEpoll ? EpollServerSocketChannel.class : NioServerSocketChannel.class)
.childHandler(new ChannelInitialiser(channelGroup, this.channelHandler, null))
.option(ChannelOption.SO_BACKLOG, this.configuration.getInt("backlog"))
.option(ChannelOption.TCP_NODELAY, true)
.option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT)
.option(ChannelOption.MESSAGE_SIZE_ESTIMATOR, DefaultMessageSizeEstimator.DEFAULT)
.childOption(ChannelOption.TCP_NODELAY, this.configuration.getBoolean("tcpNoDelay"))
.childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);
}
RconNetworkListener.java 文件源码
项目:voxelwind
阅读 22
收藏 0
点赞 0
评论 0
@Override
public boolean bind() {
ChannelFuture future = new ServerBootstrap()
.channel(Epoll.isAvailable() ? EpollServerSocketChannel.class : NioServerSocketChannel.class)
.option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT)
.group(group)
.childHandler(this)
.bind(server.getConfiguration().getRcon().getHost(), server.getConfiguration().getRcon().getPort())
.awaitUninterruptibly();
if (future.isSuccess()) {
this.channel = future.channel();
return true;
}
return false;
}
NettyMessagingService.java 文件源码
项目:ravikumaran201504
阅读 26
收藏 0
点赞 0
评论 0
private void initEventLoopGroup() {
// try Epoll first and if that does work, use nio.
try {
clientGroup = new EpollEventLoopGroup();
serverGroup = new EpollEventLoopGroup();
serverChannelClass = EpollServerSocketChannel.class;
clientChannelClass = EpollSocketChannel.class;
return;
} catch (Throwable t) {
log.warn("Failed to initialize native (epoll) transport. Reason: {}. Proceeding with nio.", t.getMessage());
}
clientGroup = new NioEventLoopGroup();
serverGroup = new NioEventLoopGroup();
serverChannelClass = NioServerSocketChannel.class;
clientChannelClass = NioSocketChannel.class;
}
EpollEchoServer.java 文件源码
项目:netty.book.kor
阅读 20
收藏 0
点赞 0
评论 0
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();
}
}
NettyPushListener.java 文件源码
项目:taojiane_push
阅读 25
收藏 0
点赞 0
评论 0
public void initChannel() throws Exception {
bossGroup = new EpollEventLoopGroup();
workerGroup = new EpollEventLoopGroup(pushListenerWorkerNum,
new ThreadFactoryWithName(NettyPushListener.class));
serverBootstarp = new ServerBootstrap()
.group(bossGroup, workerGroup)
.channel(EpollServerSocketChannel.class)
.option(ChannelOption.SO_TIMEOUT, sockTimout)
.option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT)
.option(ChannelOption.TCP_NODELAY, true)
.childOption(ChannelOption.ALLOCATOR,
PooledByteBufAllocator.DEFAULT)
.childOption(ChannelOption.TCP_NODELAY, true)
.childHandler(pushListenerChannelInitializer);
serverBootstarp.bind(port).sync();
logger.info("Netty TCP Push Listener nio provider: {} with {} workers", serverBootstarp
.getClass().getCanonicalName(), pushListenerWorkerNum);
}
TcpProtocolServer.java 文件源码
项目:Okra
阅读 22
收藏 0
点赞 0
评论 0
@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;
}
NettyMessagingService.java 文件源码
项目:atomix
阅读 33
收藏 0
点赞 0
评论 0
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;
}
NettyEmbeddedServletContainer.java 文件源码
项目:spring-boot-starter-netty
阅读 38
收藏 0
点赞 0
评论 0
private void groups(ServerBootstrap b) {
if (StandardSystemProperty.OS_NAME.value().equals("Linux")) {
bossGroup = new EpollEventLoopGroup(1);
workerGroup = new EpollEventLoopGroup();
b.channel(EpollServerSocketChannel.class)
.group(bossGroup, workerGroup)
.option(EpollChannelOption.TCP_CORK, true);
} else {
bossGroup = new NioEventLoopGroup(1);
workerGroup = new NioEventLoopGroup();
b.channel(NioServerSocketChannel.class)
.group(bossGroup, workerGroup);
}
b.option(ChannelOption.TCP_NODELAY, true)
.option(ChannelOption.SO_REUSEADDR, true)
.option(ChannelOption.SO_BACKLOG, 100);
logger.info("Bootstrap configuration: " + b.toString());
}
BGPDispatcherImpl.java 文件源码
项目:bgpcep
阅读 26
收藏 0
点赞 0
评论 0
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, new FixedRecvByteBufAllocator(FIX_BUFFER_SIZE));
if (serverBootstrap.config().group() == null) {
serverBootstrap.group(this.bossGroup, this.workerGroup);
}
return serverBootstrap;
}
NailedNetworkManager.java 文件源码
项目:nailed
阅读 34
收藏 0
点赞 0
评论 0
public static void addEndpoint(final SocketAddress address){
ServerBootstrap bootstrap = new ServerBootstrap();
if(epollSupported && !disableEpoll){
bootstrap.channel(EpollServerSocketChannel.class);
}else{
bootstrap.channel(NioServerSocketChannel.class);
}
bootstrap.localAddress(address);
bootstrap.childHandler(NettyChannelInitializer.INSTANCE);
bootstrap.group(workers);
logger.info("Opening endpoint " + address.toString());
bootstrap.bind().syncUninterruptibly().addListener(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture future){
endpoints.add(future.channel());
logger.info("Endpoint " + address.toString() + " started");
}
});
}
NettyMessagingManager.java 文件源码
项目:onos
阅读 26
收藏 0
点赞 0
评论 0
private void initEventLoopGroup() {
// try Epoll first and if that does work, use nio.
try {
clientGroup = new EpollEventLoopGroup(0, groupedThreads("NettyMessagingEvt", "epollC-%d", log));
serverGroup = new EpollEventLoopGroup(0, groupedThreads("NettyMessagingEvt", "epollS-%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, groupedThreads("NettyMessagingEvt", "nioC-%d", log));
serverGroup = new NioEventLoopGroup(0, groupedThreads("NettyMessagingEvt", "nioS-%d", log));
serverChannelClass = NioServerSocketChannel.class;
clientChannelClass = NioSocketChannel.class;
}
NettyUtils.java 文件源码
项目:angel
阅读 24
收藏 0
点赞 0
评论 0
/** Returns the correct ServerSocketChannel class based on IOMode. */
public static Class<? extends ServerChannel> getServerChannelClass(IOMode mode) {
switch (mode) {
case NIO:
return NioServerSocketChannel.class;
case EPOLL:
return EpollServerSocketChannel.class;
default:
throw new IllegalArgumentException("Unknown io mode: " + mode);
}
}
EpollConnDroppingServer.java 文件源码
项目:netty-connection-pool
阅读 18
收藏 0
点赞 0
评论 0
public EpollConnDroppingServer(final int port, final int dropEveryRequest)
throws InterruptedException {
dispatchGroup = new EpollEventLoopGroup();
workerGroup = new EpollEventLoopGroup();
final ServerBootstrap bootstrap = new ServerBootstrap()
.group(dispatchGroup, workerGroup)
.channel(EpollServerSocketChannel.class)
.childHandler(
new ChannelInitializer<SocketChannel>() {
@Override
public final void initChannel(final SocketChannel ch) {
if(dropEveryRequest > 0) {
ch.pipeline().addLast(
new SimpleChannelInboundHandler<Object>() {
@Override
protected final void channelRead0(
final ChannelHandlerContext ctx, final Object msg
) throws Exception {
if(0 == reqCounter.incrementAndGet() % dropEveryRequest) {
final Channel conn = ctx.channel();
System.out.println("Dropping the connection " + conn);
conn.close();
}
}
}
);
}
}
}
);
bindFuture = bootstrap.bind(port).sync();
}
TransportCheck.java 文件源码
项目:QDrill
阅读 23
收藏 0
点赞 0
评论 0
public static Class<? extends ServerSocketChannel> getServerSocketChannel(){
if(SUPPORTS_EPOLL){
return EpollServerSocketChannel.class;
}else{
return NioServerSocketChannel.class;
}
}
NettyUtils.java 文件源码
项目:spark_deep
阅读 32
收藏 0
点赞 0
评论 0
/** Returns the correct ServerSocketChannel class based on IOMode. */
public static Class<? extends ServerChannel> getServerChannelClass(IOMode mode) {
switch (mode) {
case NIO:
return NioServerSocketChannel.class;
case EPOLL:
return EpollServerSocketChannel.class;
default:
throw new IllegalArgumentException("Unknown io mode: " + mode);
}
}
GrpcServer.java 文件源码
项目:rpc-thunderdome
阅读 26
收藏 0
点赞 0
评论 0
public static void main(String... args) throws Exception {
System.out.println("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();
System.out.println("server started");
start.awaitTermination();
}
TransportCheck.java 文件源码
项目:dremio-oss
阅读 30
收藏 0
点赞 0
评论 0
public static Class<? extends ServerSocketChannel> getServerSocketChannel(){
if(SUPPORTS_EPOLL){
return EpollServerSocketChannel.class;
}else{
return NioServerSocketChannel.class;
}
}
ServerContext.java 文件源码
项目:Okra-Ax
阅读 32
收藏 0
点赞 0
评论 0
/**
* 初始化
*
* @param pThreadCount parent thread count.
* @param cThreadCount worker thread count.
* @param options netty network options。
*/
public void initialize(int pThreadCount, int cThreadCount,
Map<ChannelOption<Object>, Object> options) {
this.bootstrap = new ServerBootstrap();
if (Epoll.isAvailable()) {
this.parentGroup = new EpollEventLoopGroup(pThreadCount);
this.childGroup = new EpollEventLoopGroup(cThreadCount);
this.bootstrap.group(parentGroup, childGroup).channel(EpollServerSocketChannel.class);
} else {
this.parentGroup = new NioEventLoopGroup(pThreadCount);
this.childGroup = new NioEventLoopGroup(cThreadCount);
this.bootstrap.group(parentGroup, childGroup).channel(NioServerSocketChannel.class);
}
// handlers
this.prepender = new LengthFieldPrepender(this.lengthFieldLength, false);
bootstrap.childHandler(new ChannelInitializer() {
@Override
protected void initChannel(Channel ch) throws Exception {
ServerContext.this.initChannel(ch);
}
});
//
this.defaultOptions();
if (!options.isEmpty()) {
for (Map.Entry<ChannelOption<Object>, Object> entry : options.entrySet()) {
bootstrap.childOption(entry.getKey(), entry.getValue());
}
}
}
Server.java 文件源码
项目:restnext
阅读 34
收藏 0
点赞 0
评论 0
private ServerBootstrap newEpoolServerBootstrap() {
bossGroup = new EpollEventLoopGroup();
workerGroup = new EpollEventLoopGroup();
return new ServerBootstrap()
.group(bossGroup, workerGroup)
.channel(EpollServerSocketChannel.class);
}
MqttServer.java 文件源码
项目:lannister
阅读 26
收藏 0
点赞 0
评论 0
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();
}
EventLoopUtil.java 文件源码
项目:incubator-pulsar
阅读 26
收藏 0
点赞 0
评论 0
public static Class<? extends ServerSocketChannel> getServerSocketChannelClass(EventLoopGroup eventLoopGroup) {
if (eventLoopGroup instanceof EpollEventLoopGroup) {
return EpollServerSocketChannel.class;
} else {
return NioServerSocketChannel.class;
}
}
TransportCheck.java 文件源码
项目:drill
阅读 24
收藏 0
点赞 0
评论 0
public static Class<? extends ServerSocketChannel> getServerSocketChannel(){
if(SUPPORTS_EPOLL){
return EpollServerSocketChannel.class;
}else{
return NioServerSocketChannel.class;
}
}
TransportTypeHolder.java 文件源码
项目:blynk-server
阅读 21
收藏 0
点赞 0
评论 0
private TransportTypeHolder(int workerThreads) {
if (Epoll.isAvailable()) {
log.info("Using native epoll transport.");
bossGroup = new EpollEventLoopGroup(1);
workerGroup = new EpollEventLoopGroup(workerThreads);
channelClass = EpollServerSocketChannel.class;
} else {
bossGroup = new NioEventLoopGroup(1);
workerGroup = new NioEventLoopGroup(workerThreads);
channelClass = NioServerSocketChannel.class;
}
}
TChannel.java 文件源码
项目:tchannel-java
阅读 25
收藏 0
点赞 0
评论 0
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)
.option(
ChannelOption.WRITE_BUFFER_WATER_MARK,
new WriteBufferWaterMark(WRITE_BUFFER_LOW_WATER_MARK, WRITE_BUFFER_HIGH_WATER_MARK)
)
.validate();
}