6
6
package org .hibernate .reactive .context .impl ;
7
7
8
8
import java .lang .invoke .MethodHandles ;
9
+ import java .util .concurrent .ConcurrentHashMap ;
10
+ import java .util .concurrent .ConcurrentMap ;
9
11
10
12
import io .vertx .core .Vertx ;
11
13
import io .vertx .core .impl .ContextInternal ;
14
+ import io .vertx .core .spi .context .storage .AccessMode ;
12
15
13
16
import org .hibernate .reactive .context .Context ;
14
17
import org .hibernate .reactive .logging .impl .Log ;
17
20
import org .hibernate .service .spi .ServiceRegistryAwareService ;
18
21
import org .hibernate .service .spi .ServiceRegistryImplementor ;
19
22
20
- import static org .hibernate .reactive .context .impl .ContextualDataStorage .contextualDataMap ;
21
-
22
23
/**
23
24
* An adaptor for the Vert.x {@link io.vertx.core.Context}.
24
25
*
@@ -41,7 +42,7 @@ public <T> void put(Key<T> key, T instance) {
41
42
final ContextInternal context = ContextInternal .current ();
42
43
if ( context != null ) {
43
44
if ( trace ) LOG .tracef ( "Putting key,value in context: [%1$s, %2$s]" , key , instance );
44
- ContextualDataStorage .<T >contextualDataMap ( context ).put ( key , instance );
45
+ VertxContext .<T >contextualDataMap ( context ).put ( key , instance );
45
46
}
46
47
else {
47
48
if ( trace ) LOG .tracef ( "Context is null for key,value: [%1$s, %2$s]" , key , instance );
@@ -53,7 +54,7 @@ public <T> void put(Key<T> key, T instance) {
53
54
public <T > T get (Key <T > key ) {
54
55
final ContextInternal context = ContextInternal .current ();
55
56
if ( context != null ) {
56
- T local = ContextualDataStorage .<T >contextualDataMap ( context ).get ( key );
57
+ T local = VertxContext .<T >contextualDataMap ( context ).get ( key );
57
58
if ( trace ) LOG .tracef ( "Getting value %2$s from context for key %1$s" , key , local );
58
59
return local ;
59
60
}
@@ -93,4 +94,13 @@ public void execute(Runnable runnable) {
93
94
runnable .run ();
94
95
}
95
96
}
97
+
98
+ @ SuppressWarnings ({ "unchecked" })
99
+ private static <T > ConcurrentMap <Key <T >, T > contextualDataMap (ContextInternal vertxContext ) {
100
+ return vertxContext .getLocal (
101
+ ContextualDataStorage .CONTEXTUAL_DATA_KEY ,
102
+ AccessMode .CONCURRENT ,
103
+ ConcurrentHashMap ::new
104
+ );
105
+ }
96
106
}
0 commit comments