本文整理汇总了Java中io.netty.channel.epoll.EpollChannelOption类的典型用法代码示例。如果您正苦于以下问题:Java EpollChannelOption类的具体用法?Java EpollChannelOption怎么用?Java EpollChannelOption使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
EpollChannelOption类属于io.netty.channel.epoll包,在下文中一共展示了EpollChannelOption类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: groups
import io.netty.channel.epoll.EpollChannelOption; //导入依赖的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());
}
示例2: McpeOverRakNetNetworkListener
import io.netty.channel.epoll.EpollChannelOption; //导入依赖的package包/类
public McpeOverRakNetNetworkListener(VoxelwindServer voxelwindServer, String host, int port, boolean useSoReuseport) {
this.server = voxelwindServer;
this.address = new InetSocketAddress(host, port);
this.useSoReuseport = useSoReuseport;
if (Epoll.isAvailable()) {
bootstrap = new Bootstrap()
.channel(EpollDatagramChannel.class)
.group(new EpollEventLoopGroup(0, new ThreadFactoryBuilder().setDaemon(true).setNameFormat("Voxelwind MCPE Listener - #%d").build()))
.option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT)
.handler(this);
if (useSoReuseport) {
bootstrap.option(EpollChannelOption.SO_REUSEPORT, true);
}
} else {
bootstrap = new Bootstrap()
.channel(NioDatagramChannel.class)
.group(new NioEventLoopGroup(0, new ThreadFactoryBuilder().setDaemon(true).setNameFormat("Voxelwind MCPE Listener - #%d").build()))
.option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT)
.handler(this);
}
}
示例3: createServerBootstrap
import io.netty.channel.epoll.EpollChannelOption; //导入依赖的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;
}
示例4: createServerBootstrap
import io.netty.channel.epoll.EpollChannelOption; //导入依赖的package包/类
public static ServerBootstrap createServerBootstrap(
@Nonnull final BmpSessionFactory sessionFactory,
@Nonnull final BmpHandlerFactory hf,
@Nonnull final BmpSessionListenerFactory slf,
@Nonnull CreateChannel createChannel,
@Nonnull final EventLoopGroup bossGroup,
@Nonnull final EventLoopGroup workerGroup,
@Nonnull final 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;
}
示例5: setChannelFactory
import io.netty.channel.epoll.EpollChannelOption; //导入依赖的package包/类
private static void setChannelFactory(final Bootstrap bootstrap, final KeyMapping keys) {
if (Epoll.isAvailable()) {
bootstrap.channel(EpollSocketChannel.class);
bootstrap.option(EpollChannelOption.EPOLL_MODE, EpollMode.LEVEL_TRIGGERED);
} else {
bootstrap.channel(NioSocketChannel.class);
}
if (!keys.isEmpty()) {
if (Epoll.isAvailable()) {
bootstrap.option(EpollChannelOption.TCP_MD5SIG, keys);
} else {
throw new UnsupportedOperationException(Epoll.unavailabilityCause().getCause());
}
}
}
示例6: createServerBootstrap
import io.netty.channel.epoll.EpollChannelOption; //导入依赖的package包/类
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;
}
示例7: onPeerAdded
import io.netty.channel.epoll.EpollChannelOption; //导入依赖的package包/类
@Override
public void onPeerAdded(@Nonnull final IpAddress ip, @Nonnull final BGPSessionPreferences prefs) {
if (prefs.getMd5Password().isPresent()) {
this.keys.put(IetfInetUtil.INSTANCE.inetAddressFor(ip), prefs.getMd5Password().get());
this.channelConfig.setOption(EpollChannelOption.TCP_MD5SIG, this.keys);
}
}
示例8: createClientBootStrap
import io.netty.channel.epoll.EpollChannelOption; //导入依赖的package包/类
private synchronized Bootstrap createClientBootStrap(final KeyMapping keys, final boolean reuseAddress) {
final Bootstrap bootstrap = new Bootstrap();
if (Epoll.isAvailable()) {
bootstrap.channel(EpollSocketChannel.class);
bootstrap.option(EpollChannelOption.EPOLL_MODE, EpollMode.LEVEL_TRIGGERED);
} else {
bootstrap.channel(NioSocketChannel.class);
}
if (keys != null && !keys.isEmpty()) {
if (Epoll.isAvailable()) {
bootstrap.option(EpollChannelOption.TCP_MD5SIG, keys);
} else {
throw new UnsupportedOperationException(Epoll.unavailabilityCause().getCause());
}
}
// Make sure we are doing round-robin processing
bootstrap.option(ChannelOption.RCVBUF_ALLOCATOR, new FixedRecvByteBufAllocator(FIX_BUFFER_SIZE));
bootstrap.option(ChannelOption.SO_KEEPALIVE, Boolean.TRUE);
bootstrap.option(ChannelOption.WRITE_BUFFER_WATER_MARK, WATER_MARK);
bootstrap.option(ChannelOption.SO_REUSEADDR, reuseAddress);
if (bootstrap.config().group() == null) {
bootstrap.group(this.workerGroup);
}
return bootstrap;
}
示例9: findOption
import io.netty.channel.epoll.EpollChannelOption; //导入依赖的package包/类
@SuppressWarnings("rawtypes")
private Map.Entry<ChannelOption, Class<?>> findOption(final String optionName) {
try {
Field field = EpollChannelOption.class.getField(optionName);
ChannelOption option = (ChannelOption) field.get(null);
Class optionType = (Class) ((ParameterizedType) field.getGenericType())
.getActualTypeArguments()[0];
return Maps.immutableEntry(option, optionType);
} catch (NoSuchFieldException | SecurityException | IllegalAccessException ex) {
return null;
}
}
示例10: enableTriggeredMode
import io.netty.channel.epoll.EpollChannelOption; //导入依赖的package包/类
public static void enableTriggeredMode(ServerBootstrap bootstrap) {
if (Epoll.isAvailable()) {
bootstrap.childOption(EpollChannelOption.EPOLL_MODE, EpollMode.LEVEL_TRIGGERED);
}
}
示例11: startServer
import io.netty.channel.epoll.EpollChannelOption; //导入依赖的package包/类
private void startServer(long startTime) throws Exception {
ResourceLeakDetector.setLevel(ResourceLeakDetector.Level.DISABLED);
boolean SSL = environment.getBoolean(ENV_KEY_SSL, false);
// Configure SSL.
SslContext sslCtx = null;
if (SSL) {
String certFilePath = environment.get(ENV_KEY_SSL_CERT, null);
String privateKeyPath = environment.get(ENE_KEY_SSL_PRIVATE_KEY, null);
String privateKeyPassword = environment.get(ENE_KEY_SSL_PRIVATE_KEY_PASS, null);
log.info("⬢ SSL CertChainFile Path: {}", certFilePath);
log.info("⬢ SSL PrivateKeyFile Path: {}", privateKeyPath);
sslCtx = SslContextBuilder.forServer(new File(certFilePath), new File(privateKeyPath), privateKeyPassword).build();
}
// Configure the server.
int backlog = environment.getInt(ENV_KEY_NETTY_SO_BACKLOG, 8192);
ServerBootstrap b = new ServerBootstrap();
b.option(ChannelOption.SO_BACKLOG, backlog);
b.option(ChannelOption.SO_REUSEADDR, true);
b.childOption(ChannelOption.SO_REUSEADDR, true);
int acceptThreadCount = environment.getInt(ENC_KEY_NETTY_ACCEPT_THREAD_COUNT, 0);
int ioThreadCount = environment.getInt(ENV_KEY_NETTY_IO_THREAD_COUNT, 0);
// enable epoll
if (BladeKit.epollIsAvailable()) {
log.info("⬢ Use EpollEventLoopGroup");
b.option(EpollChannelOption.SO_REUSEPORT, true);
NettyServerGroup nettyServerGroup = EpollKit.group(acceptThreadCount, ioThreadCount);
this.bossGroup = nettyServerGroup.getBoosGroup();
this.workerGroup = nettyServerGroup.getWorkerGroup();
b.group(bossGroup, workerGroup).channel(nettyServerGroup.getSocketChannel());
} else {
log.info("⬢ Use NioEventLoopGroup");
this.bossGroup = new NioEventLoopGroup(acceptThreadCount, new NamedThreadFactory("[email protected]"));
this.workerGroup = new NioEventLoopGroup(ioThreadCount, new NamedThreadFactory("[email protected]"));
b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class);
}
b.handler(new LoggingHandler(LogLevel.DEBUG))
.childHandler(new HttpServerInitializer(sslCtx, blade, bossGroup.next()));
String address = environment.get(ENV_KEY_SERVER_ADDRESS, DEFAULT_SERVER_ADDRESS);
int port = environment.getInt(ENV_KEY_SERVER_PORT, DEFAULT_SERVER_PORT);
channel = b.bind(address, port).sync().channel();
String appName = environment.get(ENV_KEY_APP_NAME, "Blade");
log.info("⬢ {} initialize successfully, Time elapsed: {} ms", appName, (System.currentTimeMillis() - startTime));
log.info("⬢ Blade start with {}:{}", address, port);
log.info("⬢ Open your web browser and navigate to {}://{}:{} ⚡", "http", address.replace(DEFAULT_SERVER_ADDRESS, LOCAL_IP_ADDRESS), port);
blade.eventManager().fireEvent(EventType.SERVER_STARTED, blade);
}
示例12: createClientBootstrap
import io.netty.channel.epoll.EpollChannelOption; //导入依赖的package包/类
public static Bootstrap createClientBootstrap(
@Nonnull final BmpSessionFactory sessionFactory,
@Nonnull final BmpHandlerFactory hf,
@Nonnull CreateChannel createChannel,
@Nonnull final BmpSessionListenerFactory slf,
@Nonnull final InetSocketAddress remoteAddress,
@Nullable final SocketAddress localAddress,
@Nonnull final EventLoopGroup workerGroup,
final int connectTimeout,
@Nonnull final KeyMapping keys,
boolean reuseAddress,
boolean tryEpollSocket) {
final Bootstrap bootstrap = new Bootstrap();
bootstrap.option(ChannelOption.SO_REUSEADDR, reuseAddress);
bootstrap.option(ChannelOption.SO_KEEPALIVE, true);
bootstrap.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, connectTimeout);
bootstrap.group(workerGroup);
bootstrap.handler(createChannel.create(sessionFactory, hf, slf));
if (localAddress != null) {
bootstrap.localAddress(localAddress);
}
bootstrap.remoteAddress(remoteAddress);
if (!tryEpollSocket) {
bootstrap.channel(NioSocketChannel.class);
} else {
if (Epoll.isAvailable()) {
bootstrap.channel(EpollSocketChannel.class);
} else {
bootstrap.channel(NioSocketChannel.class);
}
if (!keys.isEmpty()) {
if (Epoll.isAvailable()) {
bootstrap.option(EpollChannelOption.TCP_MD5SIG, keys);
} else {
throw new UnsupportedOperationException(Epoll.unavailabilityCause().getCause());
}
}
}
return bootstrap;
}
示例13: onPeerRemoved
import io.netty.channel.epoll.EpollChannelOption; //导入依赖的package包/类
@Override
public void onPeerRemoved(@Nonnull final IpAddress ip) {
if (this.keys.remove(IetfInetUtil.INSTANCE.inetAddressFor(ip)) != null) {
this.channelConfig.setOption(EpollChannelOption.TCP_MD5SIG, this.keys);
}
}