Skip to content

Commit

Permalink
Rollback breaking change of internal API
Browse files Browse the repository at this point in the history
  • Loading branch information
vietj committed Aug 15, 2024
1 parent 334e2cd commit 6ddbde4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
3 changes: 2 additions & 1 deletion src/main/java/io/vertx/core/Vertx.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -177,7 +178,7 @@ static Future<Vertx> 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());
}

/**
Expand Down
14 changes: 3 additions & 11 deletions src/main/java/io/vertx/core/impl/ContextInternal.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -236,7 +228,7 @@ default void execute(Handler<Void> 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();
}

/**
Expand Down
17 changes: 16 additions & 1 deletion src/main/java/io/vertx/core/impl/VertxImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 6ddbde4

Please sign in to comment.