Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions ratis-netty/src/main/java/org/apache/ratis/netty/NettyUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,37 @@

import javax.net.ssl.KeyManager;
import javax.net.ssl.TrustManager;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Function;

public interface NettyUtils {
Logger LOG = LoggerFactory.getLogger(NettyUtils.class);

class Print {
private static final AtomicBoolean PRINTED_EPOLL_UNAVAILABILITY_CAUSE = new AtomicBoolean();

private Print() {}

static void epollUnavailability(String message) {
if (!LOG.isWarnEnabled()) {
return;
}
if (PRINTED_EPOLL_UNAVAILABILITY_CAUSE.compareAndSet(false, true)) {
LOG.warn(message, new IllegalStateException("Epoll is unavailable.", Epoll.unavailabilityCause()));
} else {
LOG.warn(message);
}
}
}

static EventLoopGroup newEventLoopGroup(String name, int size, boolean useEpoll) {
if (useEpoll) {
if (Epoll.isAvailable()) {
LOG.info("Create EpollEventLoopGroup for {}; Thread size is {}.", name, size);
return new EpollEventLoopGroup(size, ConcurrentUtils.newThreadFactory(name + "-"));
} else {
LOG.warn("Failed to create EpollEventLoopGroup for " + name + "; fall back on NioEventLoopGroup.",
Epoll.unavailabilityCause());
Print.epollUnavailability("Failed to create EpollEventLoopGroup for " + name
+ "; fall back on NioEventLoopGroup.");
}
}
return new NioEventLoopGroup(size, ConcurrentUtils.newThreadFactory(name + "-"));
Expand Down