Skip to content

Commit c020c0d

Browse files
authored
Register EventLoop as a Non-Blocking Thread in Reactor Scheduler 3.7.0+ (#6148)
Motivation: The method `Schedulers.registerNonBlockingThreadPredicate` was introduced in Reactor 3.7.0+. To maintain compatibility with older Reactor versions, we should only register the EventLoop as a non-blocking thread if this method is available. If the method is unavailable (i.e., in Reactor versions lower than 3.7.0), a warning log should be emitted instead of causing an error. Modifications: - Check for the existence of `Schedulers.registerNonBlockingThreadPredicate` before invoking it. - If the method is unavailable, log a warning instead of attempting registration. Result: - Ensured compatibility with both newer and older Reactor versions.
1 parent ff7e294 commit c020c0d

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

core/src/main/java/com/linecorp/armeria/client/endpoint/healthcheck/HealthCheckedEndpointGroup.java

-2
Original file line numberDiff line numberDiff line change
@@ -292,8 +292,6 @@ private void destroyOldContexts(HealthCheckContextGroup contextGroup) {
292292

293293
private void updateHealth(Endpoint endpoint, boolean health) {
294294
if (isClosing()) {
295-
logger.debug("HealthCheckedEndpointGroup is closed. Ignoring health update for: {}. (healthy: {})",
296-
endpoint, health);
297295
return;
298296
}
299297

core/src/main/java/com/linecorp/armeria/common/CommonPools.java

+17-3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@
1616

1717
package com.linecorp.armeria.common;
1818

19+
import java.lang.reflect.Method;
20+
import java.util.function.Predicate;
21+
22+
import org.slf4j.Logger;
23+
import org.slf4j.LoggerFactory;
24+
1925
import com.linecorp.armeria.client.ClientFactoryBuilder;
2026
import com.linecorp.armeria.common.metric.MeterIdPrefix;
2127
import com.linecorp.armeria.common.metric.MoreMeterBinders;
@@ -30,6 +36,8 @@
3036
*/
3137
public final class CommonPools {
3238

39+
private static final Logger logger = LoggerFactory.getLogger(CommonPools.class);
40+
3341
// Threads spawned as needed and reused, with a 60s timeout and unbounded work queue.
3442
private static final BlockingTaskExecutor BLOCKING_TASK_EXECUTOR =
3543
BlockingTaskExecutor.builder().threadNamePrefix("armeria-common-blocking-tasks").build();
@@ -43,11 +51,17 @@ public final class CommonPools {
4351
.bindTo(Flags.meterRegistry());
4452

4553
try {
46-
Class.forName("reactor.core.scheduler.Schedulers",
47-
true, CommonPools.class.getClassLoader());
54+
final Class<?> aClass = Class.forName("reactor.core.scheduler.Schedulers",
55+
true, CommonPools.class.getClassLoader());
56+
final Method ignored = aClass.getDeclaredMethod(
57+
"registerNonBlockingThreadPredicate", Predicate.class);
58+
// Call only when the method exists.
4859
ReactorNonBlockingUtil.registerEventLoopAsNonBlocking();
4960
} catch (ClassNotFoundException e) {
50-
// Do nothing.
61+
// Do nothing because reactor is not available.
62+
} catch (NoSuchMethodException e) {
63+
logger.warn("Failed to register the common worker group as non-blocking for Reactor. " +
64+
"Please consider upgrading Reactor to 3.7.0 or newer.");
5165
}
5266
}
5367

0 commit comments

Comments
 (0)