本文整理汇总了Java中io.netty.channel.epoll.EpollServerSocketChannel类的典型用法代码示例。如果您正苦于以下问题:Java EpollServerSocketChannel类的具体用法?Java EpollServerSocketChannel怎么用?Java EpollServerSocketChannel使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
EpollServerSocketChannel类属于io.netty.channel.epoll包,在下文中一共展示了EpollServerSocketChannel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initEventLoopGroup
import io.netty.channel.epoll.EpollServerSocketChannel; //导入依赖的package包/类
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;
}
示例2: AbstractNettyServer
import io.netty.channel.epoll.EpollServerSocketChannel; //导入依赖的package包/类
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());
}
});
}
示例3: PluginGrpcServer
import io.netty.channel.epoll.EpollServerSocketChannel; //导入依赖的package包/类
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();
}
示例4: start
import io.netty.channel.epoll.EpollServerSocketChannel; //导入依赖的package包/类
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();
}
示例5: groups
import io.netty.channel.epoll.EpollServerSocketChannel; //导入依赖的package包/类
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());
}
示例6: run
import io.netty.channel.epoll.EpollServerSocketChannel; //导入依赖的package包/类
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 {
}
}
示例7: init
import io.netty.channel.epoll.EpollServerSocketChannel; //导入依赖的package包/类
@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();
}
示例8: initialise
import io.netty.channel.epoll.EpollServerSocketChannel; //导入依赖的package包/类
@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);
}
示例9: bind
import io.netty.channel.epoll.EpollServerSocketChannel; //导入依赖的package包/类
@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;
}
示例10: main
import io.netty.channel.epoll.EpollServerSocketChannel; //导入依赖的package包/类
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();
}
}
示例11: initChannel
import io.netty.channel.epoll.EpollServerSocketChannel; //导入依赖的package包/类
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);
}
示例12: createBootstrap
import io.netty.channel.epoll.EpollServerSocketChannel; //导入依赖的package包/类
@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;
}
示例13: initEventLoopGroup
import io.netty.channel.epoll.EpollServerSocketChannel; //导入依赖的package包/类
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;
}
示例14: createServerBootstrap
import io.netty.channel.epoll.EpollServerSocketChannel; //导入依赖的package包/类
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;
}
示例15: addEndpoint
import io.netty.channel.epoll.EpollServerSocketChannel; //导入依赖的package包/类
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");
}
});
}