Skip to content

Commit

Permalink
RATIS-1917. Print Epoll.unavailabilityCause() only once. (apache#949)
Browse files Browse the repository at this point in the history
* RATIS-1917. Print Epoll.unavailabilityCause() only once.
  • Loading branch information
szetszwo authored Oct 24, 2023
1 parent eab143a commit 94a8fbe
Showing 1 changed file with 20 additions and 2 deletions.
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

0 comments on commit 94a8fbe

Please sign in to comment.