Java 类io.netty.channel.epoll.EpollEventLoopGroup 实例源码
项目:CentauriCloud
文件:Client.java
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);
}
}
项目:JungleTree
文件:PluginGrpcServer.java
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();
}
项目:JungleTree
文件:PluginGrpcServer.java
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);
}
项目:aws-sdk-java-v2
文件:SocketChannelResolver.java
/**
* 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));
}
项目:UnknownPandaServer
文件:ConnectionProvider.java
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();
}
项目:ditb
文件:AsyncRpcClient.java
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);
}
}
项目:nebo
文件:NettyEmbeddedServletContainer.java
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());
}
项目:PocketServer
文件:PipelineUtil.java
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);
}
}
项目:elastic-rabbitmq
文件:HttpServerBoot.java
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 {
}
}
项目:lannister
文件:Application.java
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");
}
项目:LiteGraph
文件:GremlinServer.java
/**
* 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();
}
项目:vast-pubsub
文件:PubSubClient.java
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();
}
项目:Coerce
文件:NettyNetworkingService.java
@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);
}
项目:voxelwind
文件:McpeOverRakNetNetworkListener.java
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);
}
}
项目:ravikumaran201504
文件:NettyMessagingService.java
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;
}
项目:netty.book.kor
文件:EpollEchoServer.java
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();
}
}
项目:taojiane_push
文件:NettyPushListener.java
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);
}
项目:Okra
文件:TcpProtocolServer.java
@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;
}
项目:atomix
文件:NettyMessagingService.java
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;
}
项目:xio
文件:ChannelConfiguration.java
public static ChannelConfiguration clientConfig(EventLoopGroup workerGroup) {
EventLoopGroup parent = workerGroup;
if (parent instanceof EventLoop) {
parent = ((EventLoop) workerGroup).parent();
}
Class<? extends Channel> channelClass;
if (parent instanceof EpollEventLoopGroup) {
channelClass = EpollSocketChannel.class;
} else if (parent instanceof NioEventLoopGroup) {
channelClass = NioSocketChannel.class;
} else {
throw new RuntimeException("Unsupported EventLoopGroup " + workerGroup.getClass());
}
return new ChannelConfiguration(workerGroup, channelClass);
}
项目:xio
文件:ChannelConfiguration.java
/**
* This method will configure a worker EventLoopGroup and a Channel for use by a client. It will
* try to use the correct SocketChannel for the provided workerGroup.
*
* @param workerGroup uses EventLoopGroup in the ClientChannelConfiguration
* @return ClientChannelConfiguration
*/
public static ClientChannelConfiguration clientConfig(EventLoopGroup workerGroup) {
EventLoopGroup parent = workerGroup;
if (parent instanceof EventLoop) {
parent = ((EventLoop) workerGroup).parent();
}
Class<? extends Channel> channelClass;
if (parent instanceof EpollEventLoopGroup) {
channelClass = EpollSocketChannel.class;
} else if (parent instanceof NioEventLoopGroup) {
channelClass = NioSocketChannel.class;
} else {
throw new RuntimeException("Unsupported EventLoopGroup " + workerGroup.getClass());
}
return new ClientChannelConfiguration(workerGroup, channelClass);
}
项目:spring-boot-starter-netty
文件:NettyEmbeddedServletContainer.java
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());
}
项目:qpid-jms
文件:NettyTcpTransportTest.java
private void assertEpoll(String message, boolean expected, Transport transport) throws Exception {
Field group = null;
Class<?> transportType = transport.getClass();
while (transportType != null && group == null) {
try {
group = transportType.getDeclaredField("group");
} catch (NoSuchFieldException error) {
transportType = transportType.getSuperclass();
if (Object.class.equals(transportType)) {
transportType = null;
}
}
}
assertNotNull("Transport implementation unknown", group);
group.setAccessible(true);
if (expected) {
assertTrue(message, group.get(transport) instanceof EpollEventLoopGroup);
} else {
assertFalse(message, group.get(transport) instanceof EpollEventLoopGroup);
}
}
项目:docker-java
文件:NettyDockerCmdExecFactory.java
public EventLoopGroup epollGroup() {
EventLoopGroup epollEventLoopGroup = new EpollEventLoopGroup(0, new DefaultThreadFactory(threadPrefix));
ChannelFactory<EpollDomainSocketChannel> factory = new ChannelFactory<EpollDomainSocketChannel>() {
@Override
public EpollDomainSocketChannel newChannel() {
return configure(new EpollDomainSocketChannel());
}
};
bootstrap.group(epollEventLoopGroup).channelFactory(factory).handler(new ChannelInitializer<UnixChannel>() {
@Override
protected void initChannel(final UnixChannel channel) throws Exception {
channel.pipeline().addLast(new HttpClientCodec());
}
});
return epollEventLoopGroup;
}
项目:docker-plugin
文件:NettyDockerCmdExecFactory.java
public EventLoopGroup epollGroup() {
EventLoopGroup epollEventLoopGroup = new EpollEventLoopGroup(0, new DefaultThreadFactory(threadPrefix));
ChannelFactory<EpollDomainSocketChannel> factory = new ChannelFactory<EpollDomainSocketChannel>() {
@Override
public EpollDomainSocketChannel newChannel() {
return configure(new EpollDomainSocketChannel());
}
};
bootstrap.group(epollEventLoopGroup).channelFactory(factory).handler(new ChannelInitializer<UnixChannel>() {
@Override
protected void initChannel(final UnixChannel channel) throws Exception {
channel.pipeline().addLast(new HttpClientCodec());
}
});
return epollEventLoopGroup;
}
项目:onos
文件:NettyMessagingManager.java
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;
}
项目:angel
文件:NettyUtils.java
/** Creates a Netty EventLoopGroup based on the IOMode. */
public static EventLoopGroup createEventLoop(IOMode mode, int numThreads, String threadPrefix) {
ThreadFactory threadFactory = createThreadFactory(threadPrefix);
switch (mode) {
case NIO:
return new NioEventLoopGroup(numThreads, threadFactory);
case EPOLL:
return new EpollEventLoopGroup(numThreads, threadFactory);
default:
throw new IllegalArgumentException("Unknown io mode: " + mode);
}
}
项目:JungleTree
文件:JungleConnectorGrpcClient.java
@SuppressWarnings("unchecked")
@Override
public void addConnection(ServiceType serviceType, 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();
AbstractStub blocking;
AbstractStub async;
switch (serviceType) {
case WORLD: {
blocking = WorldServiceGrpc.newBlockingStub(channel);
async = WorldServiceGrpc.newStub(channel);
break;
}
case PLUGIN_MANAGER: {
blocking = PluginManagerGrpc.newBlockingStub(channel);
async = PluginManagerGrpc.newStub(channel);
break;
}
default: {
throw new RuntimeException("Service type not handled: " + serviceType.name());
}
}
ServiceConnection connection = ServiceConnection.builder()
.channel(channel)
.blockingStub(blocking)
.asyncStub(async)
.build();
this.connections.put(serviceType, connection);
}
项目:hekate
文件:NettyNetworkService.java
private EventLoopGroup newEventLoop(int size, String threadNamePrefix) {
switch (transport) {
case EPOLL: {
return new EpollEventLoopGroup(size, new HekateThreadFactory(threadNamePrefix));
}
case NIO: {
return new NioEventLoopGroup(size, new HekateThreadFactory(threadNamePrefix));
}
case AUTO: // <-- Fail since AUTO must be resolved in the constructor.
default: {
throw new IllegalArgumentException("Unexpected transport type: " + transport);
}
}
}
项目:hekate
文件:NetworkTestBase.java
protected EventLoopGroup newEventLoop(int thread) {
if (context().transport() == NetworkTransportType.EPOLL) {
return new EpollEventLoopGroup(thread);
} else {
return new NioEventLoopGroup(thread);
}
}
项目:netty-connection-pool
文件:EpollConnDropTest.java
@Before
public void setUp()
throws Exception {
serverMock = new EpollConnDroppingServer(DEFAULT_PORT, FAIL_EVERY_CONN_ATTEMPT);
final Semaphore concurrencyThrottle = new Semaphore(CONCURRENCY);
group = new EpollEventLoopGroup();
final Bootstrap bootstrap = new Bootstrap()
.group(group)
.channel(EpollSocketChannel.class)
.handler(
new ChannelInitializer<SocketChannel>() {
@Override
protected final void initChannel(final SocketChannel conn)
throws Exception {
conn.pipeline().addLast(new DummyClientChannelHandler());
}
}
)
.option(ChannelOption.SO_KEEPALIVE, true)
.option(ChannelOption.SO_REUSEADDR, true)
.option(ChannelOption.TCP_NODELAY, true);
connPool = new BasicMultiNodeConnPool(
concurrencyThrottle, NODES, bootstrap, CPH, DEFAULT_PORT, 0
);
connPool.preCreateConnections(CONCURRENCY);
}
项目:netty-connection-pool
文件:EpollConnDroppingServer.java
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();
}
项目:QDrill
文件:TransportCheck.java
public static EventLoopGroup createEventLoopGroup(int nThreads, String prefix) {
if(SUPPORTS_EPOLL){
return new EpollEventLoopGroup(nThreads, new NamedThreadFactory(prefix));
}else{
return new NioEventLoopGroup(nThreads, new NamedThreadFactory(prefix));
}
}
项目:spark_deep
文件:NettyUtils.java
/** Creates a Netty EventLoopGroup based on the IOMode. */
public static EventLoopGroup createEventLoop(IOMode mode, int numThreads, String threadPrefix) {
ThreadFactory threadFactory = createThreadFactory(threadPrefix);
switch (mode) {
case NIO:
return new NioEventLoopGroup(numThreads, threadFactory);
case EPOLL:
return new EpollEventLoopGroup(numThreads, threadFactory);
default:
throw new IllegalArgumentException("Unknown io mode: " + mode);
}
}
项目:DNCF
文件:NettyConfiguration.java
@Bean(name = "bossGroup")
public EventLoopGroup getBossGroup() {
if (isLinux) {
return new EpollEventLoopGroup(0x1,
new NettyThreadFactory("@+DNBossThread", Thread.NORM_PRIORITY));
} else {
return new NioEventLoopGroup(0x1, new NettyThreadFactory("@+DNBossThread", Thread.NORM_PRIORITY));
}
}
项目:DNCF
文件:NettyConfiguration.java
@Bean(name = "workerGroup")
public EventLoopGroup getWorkerGroup() {
if (isLinux) {
return new EpollEventLoopGroup(Runtime.getRuntime().availableProcessors() + 0x1,
new NettyThreadFactory("@+DNWorkerThread", Thread.NORM_PRIORITY));
} else {
return new NioEventLoopGroup(Runtime.getRuntime().availableProcessors() + 0x1,
new NettyThreadFactory("@+DNWorkerThread", Thread.NORM_PRIORITY));
}
}
项目:DNCF
文件:NettyConfiguration.java
@Bean(name = "bossGroup")
public EventLoopGroup getBossGroup() {
if (isLinux) {
return new EpollEventLoopGroup(0x1,
new NettyThreadFactory("@+DNCSBossThread", Thread.NORM_PRIORITY));
} else {
return new NioEventLoopGroup(0x1, new NettyThreadFactory("@+DNCSBossThread", Thread.NORM_PRIORITY));
}
}
项目:DNCF
文件:NettyConfiguration.java
@Bean(name = "workerGroup")
public EventLoopGroup getWorkerGroup() {
if (isLinux) {
return new EpollEventLoopGroup(Runtime.getRuntime().availableProcessors() + 0x1,
new NettyThreadFactory("@+DNCSWorkerThread", Thread.NORM_PRIORITY));
} else {
return new NioEventLoopGroup(Runtime.getRuntime().availableProcessors() + 0x1,
new NettyThreadFactory("@+DNCSWorkerThread", Thread.NORM_PRIORITY));
}
}
项目:dremio-oss
文件:TransportCheck.java
public static EventLoopGroup createEventLoopGroup(int nThreads, String prefix) {
if(SUPPORTS_EPOLL){
return new EpollEventLoopGroup(nThreads, new NamedThreadFactory(prefix));
}else{
return new NioEventLoopGroup(nThreads, new NamedThreadFactory(prefix));
}
}
项目:ditb
文件:TestAsyncIPC.java
private void setConf(Configuration conf) {
conf.setBoolean(AsyncRpcClient.USE_NATIVE_TRANSPORT, useNativeTransport);
conf.setBoolean(AsyncRpcClient.USE_GLOBAL_EVENT_LOOP_GROUP, useGlobalEventLoopGroup);
if (useGlobalEventLoopGroup && AsyncRpcClient.GLOBAL_EVENT_LOOP_GROUP != null) {
if (useNativeTransport
&& !(AsyncRpcClient.GLOBAL_EVENT_LOOP_GROUP.getFirst() instanceof EpollEventLoopGroup)
|| (!useNativeTransport
&& !(AsyncRpcClient.GLOBAL_EVENT_LOOP_GROUP.getFirst() instanceof NioEventLoopGroup))) {
AsyncRpcClient.GLOBAL_EVENT_LOOP_GROUP.getFirst().shutdownGracefully();
AsyncRpcClient.GLOBAL_EVENT_LOOP_GROUP = null;
}
}
}