Distinguish between available and epollable

This commit is contained in:
Dave Syer
2024-09-16 11:46:49 +01:00
parent 1bdcee5930
commit 9c20aa0ea0
3 changed files with 16 additions and 5 deletions

View File

@@ -102,10 +102,10 @@ public class DefaultGrpcServerFactory<T extends ServerBuilder<T>> implements Grp
@SuppressWarnings("unchecked")
private T unixDomainServerBuilder(String path) {
if (NettyServerFactoryHelper.isAvailable()) {
if (NettyServerFactoryHelper.isEpollAvailable()) {
return (T) NettyServerFactoryHelper.forUnixDomainSocket(path);
}
else if (ShadedNettyServerFactoryHelper.isAvailable()) {
else if (ShadedNettyServerFactoryHelper.isEpollAvailable()) {
return (T) ShadedNettyServerFactoryHelper.forUnixDomainSocket(path);
}
throw new IllegalStateException(

View File

@@ -30,13 +30,18 @@ import io.netty.channel.unix.DomainSocketAddress;
class NettyServerFactoryHelper {
private static final boolean AVAILABLE = ClassUtils.isPresent("io.netty.channel.epoll.Epoll", null)
&& Epoll.isAvailable();
private static final boolean AVAILABLE = ClassUtils.isPresent("io.netty.channel.epoll.Epoll", null);
private static final boolean EPOLL_AVAILABLE = AVAILABLE && Epoll.isAvailable();
public static boolean isAvailable() {
return AVAILABLE;
}
public static boolean isEpollAvailable() {
return EPOLL_AVAILABLE;
}
public static ServerBuilder<?> forUnixDomainSocket(String path) {
return NettyServerBuilder.forAddress(new DomainSocketAddress(path))
.channelType(EpollServerDomainSocketChannel.class)

View File

@@ -31,12 +31,18 @@ import io.grpc.netty.shaded.io.netty.channel.unix.DomainSocketAddress;
class ShadedNettyServerFactoryHelper {
private static final boolean AVAILABLE = ClassUtils.isPresent("io.grpc.netty.shaded.io.netty.channel.epoll.Epoll",
null) && Epoll.isAvailable();
null);
private static final boolean EPOLL_AVAILABLE = AVAILABLE && Epoll.isAvailable();
public static boolean isAvailable() {
return AVAILABLE;
}
public static boolean isEpollAvailable() {
return EPOLL_AVAILABLE;
}
public static ServerBuilder<?> forUnixDomainSocket(String path) {
return NettyServerBuilder.forAddress(new DomainSocketAddress(path))
.channelType(EpollServerDomainSocketChannel.class)