-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use the new Vertx local context storage
- Loading branch information
Showing
7 changed files
with
177 additions
and
47 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
extensions/vertx/runtime/src/main/java/io/quarkus/vertx/core/runtime/QuarkusAccessModes.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package io.quarkus.vertx.core.runtime; | ||
|
||
import java.util.concurrent.atomic.AtomicReferenceArray; | ||
import java.util.function.Supplier; | ||
|
||
import io.vertx.core.Context; | ||
import io.vertx.core.spi.context.storage.AccessMode; | ||
|
||
final class QuarkusAccessModes { | ||
|
||
/** | ||
* Beware this {@link AccessMode#getOrCreate(AtomicReferenceArray, int, Supplier)} because, differently from | ||
* {@link io.vertx.core.spi.context.storage.ContextLocal#get(Context, Supplier)}, | ||
* is not suitable to be used with {@link io.vertx.core.spi.context.storage.ContextLocal#get(Context, AccessMode, Supplier)} | ||
* with the same guarantees of atomicity i.e. the supplier can get called more than once by different racing threads! | ||
*/ | ||
public static final AccessMode ACQUIRE_RELEASE = new AccessMode() { | ||
@Override | ||
public Object get(AtomicReferenceArray<Object> locals, int idx) { | ||
return locals.getAcquire(idx); | ||
} | ||
|
||
@Override | ||
public void put(AtomicReferenceArray<Object> locals, int idx, Object value) { | ||
// This is still ensuring visibility across threads and happens-before, | ||
// but won't impose setVolatile total ordering i.e. StoreLoad barriers after write | ||
// to make it faster | ||
locals.setRelease(idx, value); | ||
} | ||
|
||
@Override | ||
public Object getOrCreate(AtomicReferenceArray<Object> locals, int idx, Supplier<Object> initialValueSupplier) { | ||
Object value = locals.getAcquire(idx); | ||
if (value == null) { | ||
value = initialValueSupplier.get(); | ||
locals.setRelease(idx, value); | ||
} | ||
return value; | ||
} | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
...ain/java/io/quarkus/vertx/runtime/storage/QuarkusLocalStorageKeyVertxServiceProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package io.quarkus.vertx.runtime.storage; | ||
|
||
import io.quarkus.arc.InjectableContext; | ||
import io.quarkus.vertx.core.runtime.context.VertxContextSafetyToggle; | ||
import io.vertx.core.impl.VertxBuilder; | ||
import io.vertx.core.spi.VertxServiceProvider; | ||
import io.vertx.core.spi.context.storage.ContextLocal; | ||
|
||
/** | ||
* This provider exists with the sole purpose of reliably get the optimized local keys created before | ||
* the Vertx instance is created. | ||
*/ | ||
public class QuarkusLocalStorageKeyVertxServiceProvider implements VertxServiceProvider { | ||
|
||
public static final ContextLocal<Boolean> ACCESS_TOGGLE_KEY = VertxContextSafetyToggle.registerAccessToggleKey(); | ||
public static final ContextLocal<InjectableContext.ContextState> REQUEST_SCOPED_LOCAL_KEY = ContextLocal | ||
.registerLocal(InjectableContext.ContextState.class); | ||
|
||
@Override | ||
public void init(VertxBuilder builder) { | ||
|
||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...vertx/runtime/src/main/resources/META-INF/services/io.vertx.core.spi.VertxServiceProvider
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
io.quarkus.vertx.runtime.storage.QuarkusLocalStorageKeyVertxServiceProvider |