本文整理汇总了Java中io.netty.channel.epoll.EpollEventLoopGroup类的典型用法代码示例。如果您正苦于以下问题:Java EpollEventLoopGroup类的具体用法?Java EpollEventLoopGroup怎么用?Java EpollEventLoopGroup使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
EpollEventLoopGroup类属于io.netty.channel.epoll包,在下文中一共展示了EpollEventLoopGroup类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: connectPlugin
import io.netty.channel.epoll.EpollEventLoopGroup; //导入依赖的package包/类
public void connectPlugin(String host, int port) {
ManagedChannel channel = NettyChannelBuilder.forAddress(host, port)
.negotiationType(NegotiationType.PLAINTEXT) // TODO: gRPC encryption
.keepAliveTime(1, TimeUnit.MINUTES)
.keepAliveTimeout(5, TimeUnit.SECONDS)
.directExecutor()
.channelType(EpollSocketChannel.class)
.eventLoopGroup(new EpollEventLoopGroup())
.build();
PluginManagerGrpc.PluginManagerBlockingStub blocking = PluginManagerGrpc.newBlockingStub(channel);
PluginManagerGrpc.PluginManagerStub async = PluginManagerGrpc.newStub(channel);
ServiceConnection connection = ServiceConnection.builder()
.channel(channel)
.blockingStub(blocking)
.asyncStub(async)
.build();
this.pluginConnections.put(PLUGIN_MANAGER, connection);
}
示例2: start
import io.netty.channel.epoll.EpollEventLoopGroup; //导入依赖的package包/类
public void start() throws InterruptedException {
final EventLoopGroup workerGroup = Epoll.isAvailable() ? new EpollEventLoopGroup() : new NioEventLoopGroup();
try {
Bootstrap bootstrap = new Bootstrap();
bootstrap.group(workerGroup)
.channel(Epoll.isAvailable() ? EpollSocketChannel.class : NioSocketChannel.class)
.handler(new OpenCloudChannelInitializer(this))
.connect(this.host, this.port).sync().channel().closeFuture().syncUninterruptibly();
} catch (Exception ex) {
if (ex.getClass().getSimpleName().equals("AnnotatedConnectException")) {
System.err.println("Cannot connect to master!");
channel.close();
} else {
ex.printStackTrace();
}
} finally {
workerGroup.shutdownGracefully();
System.out.println("Netty client stopped");
Runtime.getRuntime().halt(0);
}
}
示例3: PluginGrpcServer
import io.netty.channel.epoll.EpollEventLoopGroup; //导入依赖的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: resolveSocketChannelClass
import io.netty.channel.epoll.EpollEventLoopGroup; //导入依赖的package包/类
/**
* Attempts to determine the {@link Channel} class that corresponds to the given
* event loop group.
*
* @param eventLoopGroup the event loop group to determine the {@link Channel} for
* @return A {@link Channel} class for the given event loop group.
*/
public static Class<? extends Channel> resolveSocketChannelClass(EventLoopGroup eventLoopGroup) {
if (eventLoopGroup instanceof DelegatingEventLoopGroup) {
return resolveSocketChannelClass(((DelegatingEventLoopGroup) eventLoopGroup).getDelegate());
}
if (eventLoopGroup instanceof NioEventLoopGroup) {
return NioSocketChannel.class;
}
if (eventLoopGroup instanceof EpollEventLoopGroup) {
return EpollSocketChannel.class;
}
String socketFqcn = KNOWN_EL_GROUPS.get(eventLoopGroup.getClass().getName());
if (socketFqcn == null) {
throw new IllegalArgumentException("Unknown event loop group : " + eventLoopGroup.getClass());
}
return invokeSafely(() -> (Class<? extends Channel>) Class.forName(socketFqcn));
}
示例5: start
import io.netty.channel.epoll.EpollEventLoopGroup; //导入依赖的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();
}
示例6: createEventLoopGroup
import io.netty.channel.epoll.EpollEventLoopGroup; //导入依赖的package包/类
private static Pair<EventLoopGroup, Class<? extends Channel>> createEventLoopGroup(
Configuration conf) {
// Max amount of threads to use. 0 lets Netty decide based on amount of cores
int maxThreads = conf.getInt(CLIENT_MAX_THREADS, 0);
// Config to enable native transport. Does not seem to be stable at time of implementation
// although it is not extensively tested.
boolean epollEnabled = conf.getBoolean(USE_NATIVE_TRANSPORT, false);
// Use the faster native epoll transport mechanism on linux if enabled
if (epollEnabled && JVM.isLinux() && JVM.isAmd64()) {
if (LOG.isDebugEnabled()) {
LOG.debug("Create EpollEventLoopGroup with maxThreads = " + maxThreads);
}
return new Pair<EventLoopGroup, Class<? extends Channel>>(new EpollEventLoopGroup(maxThreads,
Threads.newDaemonThreadFactory("AsyncRpcChannel")), EpollSocketChannel.class);
} else {
if (LOG.isDebugEnabled()) {
LOG.debug("Create NioEventLoopGroup with maxThreads = " + maxThreads);
}
return new Pair<EventLoopGroup, Class<? extends Channel>>(new NioEventLoopGroup(maxThreads,
Threads.newDaemonThreadFactory("AsyncRpcChannel")), NioSocketChannel.class);
}
}
示例7: initialize
import io.netty.channel.epoll.EpollEventLoopGroup; //导入依赖的package包/类
/**
* Initializes this socket and binds its internal udp socket to a free port.
* If the socket is already initialized any invocation of this method will
* result in an IllegalStateException.
*
* @throws SocketException Thrown in case the socket could not be initialized
*/
public void initialize() throws SocketException {
if ( this.isInitialized() ) {
throw new IllegalStateException( "Cannot re-initialized ClientSocket" );
}
this.udpSocket = new Bootstrap();
this.udpSocket.group( Epoll.isAvailable() ? new EpollEventLoopGroup() : new NioEventLoopGroup() );
this.udpSocket.channel( Epoll.isAvailable() ? EpollDatagramChannel.class : NioDatagramChannel.class );
this.udpSocket.handler( new ChannelInboundHandlerAdapter() {
@Override
public void channelRead( ChannelHandlerContext ctx, Object msg ) throws Exception {
io.netty.channel.socket.DatagramPacket packet = (io.netty.channel.socket.DatagramPacket) msg;
PacketBuffer content = new PacketBuffer( packet.content() );
InetSocketAddress sender = packet.sender();
if ( !receiveDatagram( sender, content ) ) {
// Push datagram to update queue:
handleDatagram( sender, content, System.currentTimeMillis() );
}
}
} );
try {
this.channel = this.udpSocket.bind( ThreadLocalRandom.current().nextInt( 45000, 65000 ) ).sync().channel();
} catch ( InterruptedException e ) {
SocketException exception = new SocketException( "Could not bind to socket" );
exception.initCause( e );
throw exception;
}
this.afterInitialize();
}
示例8: createEpollServer
import io.netty.channel.epoll.EpollEventLoopGroup; //导入依赖的package包/类
@SuppressWarnings("unused")
private void createEpollServer(Listener listener) {
EpollEventLoopGroup eventLoopGroup = new EpollEventLoopGroup(
1, new DefaultThreadFactory(ThreadNames.T_GATEWAY_WORKER)
);
eventLoopGroup.setIoRatio(100);
createServer(listener, eventLoopGroup, EpollDatagramChannel::new);
}
示例9: groups
import io.netty.channel.epoll.EpollEventLoopGroup; //导入依赖的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());
}
示例10: newEventLoop
import io.netty.channel.epoll.EpollEventLoopGroup; //导入依赖的package包/类
public static EventLoopGroup newEventLoop(int numThreads) {
ThreadFactory threadFactory = new ThreadFactory() {
private final AtomicInteger counter = new AtomicInteger(1);
@Override
public Thread newThread(Runnable r) {
return new Thread(r, String.format("Netty IO Thread #%1$d", counter.getAndIncrement()));
}
};
ExecutorService executor = Executors.newFixedThreadPool(numThreads, threadFactory);
if (useEpoll) {
return new EpollEventLoopGroup(0, executor);
} else {
return new NioEventLoopGroup(0, executor);
}
}
示例11: run
import io.netty.channel.epoll.EpollEventLoopGroup; //导入依赖的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 {
}
}
示例12: startServers
import io.netty.channel.epoll.EpollEventLoopGroup; //导入依赖的package包/类
public void startServers() throws Exception {
int bossThreadCount = Settings.INSTANCE.getInt("netty.bossThreadCount", 0);
int workerThreadCount = Settings.INSTANCE.getInt("netty.workerThreadCount", 0);
ThreadFactory bossThreadFactory = new DefaultThreadFactory("lannister/boss");
ThreadFactory workerThreadFactory = new DefaultThreadFactory("lannister/worker");
if (Literals.NETTY_EPOLL.equals(Settings.INSTANCE.nettyTransportMode())) {
bossGroup = new EpollEventLoopGroup(bossThreadCount, bossThreadFactory);
workerGroup = new EpollEventLoopGroup(workerThreadCount, workerThreadFactory);
}
else {
bossGroup = new NioEventLoopGroup(bossThreadCount, bossThreadFactory);
workerGroup = new NioEventLoopGroup(workerThreadCount, workerThreadFactory);
}
mqttServer = new MqttServer(bossGroup, workerGroup);
mqttServer.start();
webServer = new WebServer(bossGroup, workerGroup);
webServer.start("net.anyflow");
}
示例13: GremlinServer
import io.netty.channel.epoll.EpollEventLoopGroup; //导入依赖的package包/类
/**
* Construct a Gremlin Server instance from the {@link ServerGremlinExecutor} which internally carries some
* pre-constructed objects used by the server as well as the {@link Settings} object itself. This constructor
* is useful when Gremlin Server is being used in an embedded style and there is a need to share thread pools
* with the hosting application.
*
* @deprecated As of release 3.1.1-incubating, not replaced.
* @see <a href="https://issues.apache.org/jira/browse/TINKERPOP-912">TINKERPOP-912</a>
*/
@Deprecated
public GremlinServer(final ServerGremlinExecutor<EventLoopGroup> serverGremlinExecutor) {
this.serverGremlinExecutor = serverGremlinExecutor;
this.settings = serverGremlinExecutor.getSettings();
this.isEpollEnabled = settings.useEpollEventLoop && SystemUtils.IS_OS_LINUX;
if(settings.useEpollEventLoop && !SystemUtils.IS_OS_LINUX){
logger.warn("cannot use epoll in non-linux env, falling back to NIO");
}
Runtime.getRuntime().addShutdownHook(new Thread(() -> this.stop().join(), SERVER_THREAD_PREFIX + "shutdown"));
final ThreadFactory threadFactoryBoss = ThreadFactoryUtil.create("boss-%d");
if(isEpollEnabled) {
bossGroup = new EpollEventLoopGroup(settings.threadPoolBoss, threadFactoryBoss);
} else{
bossGroup = new NioEventLoopGroup(settings.threadPoolBoss, threadFactoryBoss);
}
workerGroup = serverGremlinExecutor.getScheduledExecutorService();
gremlinExecutorService = serverGremlinExecutor.getGremlinExecutorService();
}
示例14: connect
import io.netty.channel.epoll.EpollEventLoopGroup; //导入依赖的package包/类
public void connect(String apiKey) {
Bootstrap bootstrap = new Bootstrap();
Class<? extends Channel> channelClazz;
if (Epoll.isAvailable()) {
channelClazz = EpollSocketChannel.class;
eventLoopGroup = new EpollEventLoopGroup();
} else {
channelClazz = NioSocketChannel.class;
eventLoopGroup = new NioEventLoopGroup();
}
bootstrap.group(eventLoopGroup)
.channel(channelClazz)
.option(ChannelOption.SO_KEEPALIVE, true)
// TODO: add function to get data class by topic and add handler
.remoteAddress(host, port)
.connect();
}
示例15: initialise
import io.netty.channel.epoll.EpollEventLoopGroup; //导入依赖的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);
}