Skip to content

Commit 51372f1

Browse files
committed
fix
1 parent 4b1857b commit 51372f1

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

hibernate-reactive-core/src/main/java/org/hibernate/reactive/context/Context.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
import java.util.concurrent.Executor;
1111

12+
import io.vertx.core.spi.context.storage.ContextLocal;
13+
1214
/**
1315
* Abstracts away from the Vert.x {@link io.vertx.core.Context}
1416
* object, enabling alternative strategies for associating state
@@ -53,5 +55,5 @@ public interface Context extends Executor, Service {
5355
*
5456
* @param <T> the type of thing we're storing in the context
5557
*/
56-
interface Key<T> {}
58+
interface Key<T> extends ContextLocal<T> {}
5759
}

hibernate-reactive-core/src/main/java/org/hibernate/reactive/context/impl/VertxContext.java

+9-4
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,10 @@ public void injectServices(ServiceRegistryImplementor serviceRegistry) {
3636

3737
@Override
3838
public <T> void put(Key<T> key, T instance) {
39-
final io.vertx.core.Context context = Vertx.currentContext();
39+
final ContextInternal context = currentContext();
4040
if ( context != null ) {
4141
if ( trace ) LOG.tracef( "Putting key,value in context: [%1$s, %2$s]", key, instance );
42+
context.putLocal( );
4243
context.putLocal( key, instance );
4344
}
4445
else {
@@ -47,9 +48,13 @@ public <T> void put(Key<T> key, T instance) {
4748
}
4849
}
4950

51+
private static ContextInternal currentContext() {
52+
return (ContextInternal) Vertx.currentContext();
53+
}
54+
5055
@Override
5156
public <T> T get(Key<T> key) {
52-
final io.vertx.core.Context context = Vertx.currentContext();
57+
final ContextInternal context = currentContext();
5358
if ( context != null ) {
5459
T local = context.getLocal( key );
5560
if ( trace ) LOG.tracef( "Getting value %2$s from context for key %1$s", key, local );
@@ -63,7 +68,7 @@ public <T> T get(Key<T> key) {
6368

6469
@Override
6570
public void remove(Key<?> key) {
66-
final io.vertx.core.Context context = Vertx.currentContext();
71+
final ContextInternal context = currentContext();
6772
if ( context != null ) {
6873
boolean removed = context.removeLocal( key );
6974
if ( trace ) LOG.tracef( "Key %s removed from context: %s", key, removed );
@@ -75,7 +80,7 @@ public void remove(Key<?> key) {
7580

7681
@Override
7782
public void execute(Runnable runnable) {
78-
final io.vertx.core.Context currentContext = Vertx.currentContext();
83+
final io.vertx.core.Context currentContext = currentContext();
7984
if ( currentContext == null ) {
8085
if ( trace ) LOG.tracef( "Not in a Vert.x context, checking the VertxInstance service" );
8186
final io.vertx.core.Context newContext = vertxInstance.getVertx().getOrCreateContext();

0 commit comments

Comments
 (0)