From 6ddbde4316c05e2ef6f53d100775e427e6f45b26 Mon Sep 17 00:00:00 2001 From: Julien Viet Date: Thu, 15 Aug 2024 17:03:53 +0200 Subject: [PATCH] Rollback breaking change of internal API --- src/main/java/io/vertx/core/Vertx.java | 3 ++- .../io/vertx/core/impl/ContextInternal.java | 14 +++----------- src/main/java/io/vertx/core/impl/VertxImpl.java | 17 ++++++++++++++++- 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/src/main/java/io/vertx/core/Vertx.java b/src/main/java/io/vertx/core/Vertx.java index 32860e68dde..f8d3120bdfd 100644 --- a/src/main/java/io/vertx/core/Vertx.java +++ b/src/main/java/io/vertx/core/Vertx.java @@ -21,6 +21,7 @@ import io.vertx.core.file.FileSystem; import io.vertx.core.http.*; import io.vertx.core.impl.ContextInternal; +import io.vertx.core.impl.VertxImpl; import io.vertx.core.metrics.Measured; import io.vertx.core.metrics.MetricsOptions; import io.vertx.core.net.NetClient; @@ -177,7 +178,7 @@ static Future clusteredVertx(VertxOptions options) { * @return The current context or {@code null} if there is no current context */ static @Nullable Context currentContext() { - return ContextInternal.current(Thread.currentThread()); + return VertxImpl.currentContext(Thread.currentThread()); } /** diff --git a/src/main/java/io/vertx/core/impl/ContextInternal.java b/src/main/java/io/vertx/core/impl/ContextInternal.java index f2819275878..a182d018013 100644 --- a/src/main/java/io/vertx/core/impl/ContextInternal.java +++ b/src/main/java/io/vertx/core/impl/ContextInternal.java @@ -41,16 +41,8 @@ public interface ContextInternal extends Context { /** * @return the current context */ - static ContextInternal current(Thread thread) { - if (thread instanceof VertxThread) { - return ((VertxThread) thread).context(); - } else { - VertxImpl.ContextDispatch current = VertxImpl.nonVertxContextDispatch.get(); - if (current != null) { - return current.context; - } - } - return null; + static ContextInternal current() { + return VertxImpl.currentContext(Thread.currentThread()); } @Override @@ -236,7 +228,7 @@ default void execute(Handler task) { * @return whether the current thread is running on this context */ default boolean isRunningOnContext() { - return current(Thread.currentThread()) == this && inThread(); + return VertxImpl.currentContext(Thread.currentThread()) == this && inThread(); } /** diff --git a/src/main/java/io/vertx/core/impl/VertxImpl.java b/src/main/java/io/vertx/core/impl/VertxImpl.java index 50dda04b644..1fed3fef477 100644 --- a/src/main/java/io/vertx/core/impl/VertxImpl.java +++ b/src/main/java/io/vertx/core/impl/VertxImpl.java @@ -688,8 +688,23 @@ public ContextInternal getContext() { return getContext(Thread.currentThread()); } + /** + * @return the current context + */ + public static ContextInternal currentContext(Thread thread) { + if (thread instanceof VertxThread) { + return ((VertxThread) thread).context(); + } else { + VertxImpl.ContextDispatch current = VertxImpl.nonVertxContextDispatch.get(); + if (current != null) { + return current.context; + } + } + return null; + } + private ContextInternal getContext(Thread current) { - ContextInternal context = ContextInternal.current(current); + ContextInternal context = currentContext(current); if (context != null && context.owner() == this) { return context; } else {