Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
import java.util.Collections;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.function.Supplier;

import io.netty.util.concurrent.FastThreadLocal;
import io.quarkus.arc.CurrentContext;
import io.quarkus.arc.CurrentContextFactory;
import io.quarkus.arc.InjectableContext;
import io.quarkus.arc.InjectableContext.ContextState;
import io.quarkus.arc.impl.LazyValue;
import io.quarkus.vertx.core.runtime.context.VertxContextSafetyToggle;
import io.smallrye.common.vertx.VertxContext;
import io.vertx.core.Context;
Expand Down Expand Up @@ -52,7 +54,13 @@ public List<String> keys() {
private static final class VertxCurrentContext<T extends ContextState> implements CurrentContext<T> {

private final String key;
private final FastThreadLocal<T> fallback = new FastThreadLocal<>();
private final LazyValue<FastThreadLocal<T>> fallback = new LazyValue<>(
new Supplier<>() {
@Override
public FastThreadLocal<T> get() {
return new FastThreadLocal<>();
}
});

private VertxCurrentContext(String key) {
this.key = key;
Expand All @@ -64,7 +72,7 @@ public T get() {
if (context != null && VertxContext.isDuplicatedContext(context)) {
return context.getLocal(key);
}
return fallback.get();
return fallback.get().get();
}

@Override
Expand All @@ -80,7 +88,7 @@ public void set(T state) {
}

} else {
fallback.set(state);
fallback.get().set(state);
}
}

Expand All @@ -91,7 +99,7 @@ public void remove() {
// NOOP - the DC should not be shared.
// context.removeLocal(key);
} else {
fallback.remove();
fallback.get().remove();
}
}

Expand Down
Loading