Skip to content
Draft
Show file tree
Hide file tree
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
7 changes: 5 additions & 2 deletions vertx-core/src/main/java/io/vertx/core/impl/LocalSeq.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

/**
* @author <a href="mailto:julien@julienviet.com">Julien Viet</a>
Expand All @@ -38,7 +37,11 @@ public synchronized static void reset() {
locals.add(ContextInternal.LOCAL_MAP);
}

synchronized static ContextLocal<?>[] get() {
synchronized static ContextLocal<?>[] getArray() {
return locals.toArray(new ContextLocal[0]);
}

synchronized static List<ContextLocal<?>> getList() {
return List.copyOf(locals);
}
}
8 changes: 3 additions & 5 deletions vertx-core/src/main/java/io/vertx/core/impl/VertxImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,6 @@ private static ThreadFactory virtualThreadFactory() {
private final FileResolver fileResolver;
private final EventExecutorProvider eventExecutorProvider;
private final Map<ServerID, NetServerInternal> sharedNetServers = new HashMap<>();
private final ContextLocal<?>[] contextLocals;
private final List<ContextLocal<?>> contextLocalsList;
final WorkerPool workerPool;
final WorkerPool internalWorkerPool;
final WorkerPool virtualThreadWorkerPool;
Expand Down Expand Up @@ -211,8 +209,6 @@ private static ThreadFactory virtualThreadFactory() {
ThreadFactory virtualThreadFactory = virtualThreadFactory();
PoolMetrics virtualThreadWorkerPoolMetrics = metrics != null && virtualThreadFactory != null ? metrics.createPoolMetrics("worker", "vert.x-virtual-thread", -1) : null;

contextLocals = LocalSeq.get();
contextLocalsList = Collections.unmodifiableList(Arrays.asList(contextLocals));
closeFuture = new CloseFuture(log);
maxEventLoopExecTime = maxEventLoopExecuteTime;
maxEventLoopExecTimeUnit = maxEventLoopExecuteTimeUnit;
Expand Down Expand Up @@ -619,6 +615,7 @@ public boolean cancelTimer(long id) {
}

private Object[] createContextLocals() {
ContextLocal<?>[] contextLocals = LocalSeq.getArray();
if (contextLocals.length == 0) {
return EMPTY_CONTEXT_LOCALS;
} else {
Expand Down Expand Up @@ -951,7 +948,7 @@ public NameResolver nameResolver() {

@Override
public List<ContextLocal<?>> contextLocals() {
return contextLocalsList;
return LocalSeq.getList();
}

@Override
Expand Down Expand Up @@ -1340,6 +1337,7 @@ public <C> C createSharedResource(String resourceKey, String resourceName, Close
}

void duplicate(ContextBase src, ContextBase dst) {
ContextLocal<?>[] contextLocals = LocalSeq.getArray();
for (int i = 0;i < contextLocals.length;i++) {
ContextLocalImpl<?> contextLocal = (ContextLocalImpl<?>) contextLocals[i];
Object local = AccessMode.CONCURRENT.get(src.locals, i);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1242,7 +1242,10 @@ public void testContextLocals() {
List<ContextLocal<?>> locals = ((VertxInternal) vertx).contextLocals();
assertSame(ContextInternal.LOCAL_MAP, locals.get(0));
assertSame(contextLocal, locals.get(1));
assertSame(locals, ((VertxInternal) vertx).contextLocals());
List<ContextLocal<?>> localsAgain = ((VertxInternal) vertx).contextLocals();
assertNotSame(locals, localsAgain);
assertSame(ContextInternal.LOCAL_MAP, localsAgain.get(0));
assertSame(contextLocal, localsAgain.get(1));
}

@Test
Expand Down
Loading