-
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.
Added synthetic beans for the managed ExecutorService backed by virtu…
…al threads
- Loading branch information
1 parent
9fc4b2a
commit 3044b38
Showing
6 changed files
with
112 additions
and
23 deletions.
There are no files selected for viewing
26 changes: 25 additions & 1 deletion
26
...-threads/deployment/src/main/java/io/quarkus/virtual/threads/VirtualThreadsProcessor.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 |
---|---|---|
@@ -1,19 +1,43 @@ | ||
package io.quarkus.virtual.threads; | ||
|
||
import java.util.concurrent.Executor; | ||
import java.util.concurrent.ExecutorService; | ||
|
||
import io.quarkus.arc.deployment.SyntheticBeanBuildItem; | ||
import io.quarkus.arc.processor.BuiltinScope; | ||
import io.quarkus.deployment.annotations.BuildProducer; | ||
import io.quarkus.deployment.annotations.BuildStep; | ||
import io.quarkus.deployment.annotations.ExecutionTime; | ||
import io.quarkus.deployment.annotations.Record; | ||
import io.quarkus.deployment.builditem.LaunchModeBuildItem; | ||
import io.quarkus.deployment.builditem.ShutdownContextBuildItem; | ||
import io.smallrye.common.annotation.Identifier; | ||
|
||
public class VirtualThreadsProcessor { | ||
|
||
@BuildStep | ||
@Record(ExecutionTime.STATIC_INIT) | ||
public void setup(VirtualThreadsConfig config, VirtualThreadsRecorder recorder, | ||
ShutdownContextBuildItem shutdownContextBuildItem, | ||
LaunchModeBuildItem launchModeBuildItem) { | ||
LaunchModeBuildItem launchModeBuildItem, | ||
BuildProducer<SyntheticBeanBuildItem> producer) { | ||
recorder.setupVirtualThreads(config, shutdownContextBuildItem, launchModeBuildItem.getLaunchMode()); | ||
producer.produce( | ||
SyntheticBeanBuildItem.configure(VirtualThreadsExecutor.class) | ||
.scope(BuiltinScope.APPLICATION.getInfo()) | ||
.unremovable() | ||
.setRuntimeInit() | ||
.supplier(recorder.getCurrentSupplier()) | ||
.done()); | ||
producer.produce( | ||
SyntheticBeanBuildItem.configure(VirtualThreadsExecutor.class) | ||
.types(ExecutorService.class, Executor.class) | ||
.addQualifier().annotation(Identifier.class).addValue("value", "virtual-threads").done() | ||
.scope(BuiltinScope.APPLICATION.getInfo()) | ||
.unremovable() | ||
.setRuntimeInit() | ||
.supplier(recorder.getCurrentSupplier()) | ||
.done()); | ||
} | ||
|
||
} |
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
54 changes: 54 additions & 0 deletions
54
...ntime/src/main/java/io/quarkus/virtual/threads/FallbackVirtualThreadsExecutorService.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,54 @@ | ||
package io.quarkus.virtual.threads; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.concurrent.AbstractExecutorService; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import io.smallrye.mutiny.infrastructure.Infrastructure; | ||
import io.vertx.core.Vertx; | ||
import io.vertx.core.impl.ContextInternal; | ||
|
||
/** | ||
* Fallback executor service in case the Virtual threads | ||
*/ | ||
class FallbackVirtualThreadsExecutorService extends AbstractExecutorService implements VirtualThreadsExecutor { | ||
|
||
@Override | ||
public void execute(Runnable command) { | ||
var context = Vertx.currentContext(); | ||
if (!(context instanceof ContextInternal)) { | ||
Infrastructure.getDefaultWorkerPool().execute(command); | ||
} else { | ||
context.executeBlocking(() -> { | ||
command.run(); | ||
return null; | ||
}, false); | ||
} | ||
} | ||
|
||
@Override | ||
public void shutdown() { | ||
// no-op | ||
} | ||
|
||
@Override | ||
public List<Runnable> shutdownNow() { | ||
return Collections.EMPTY_LIST; | ||
} | ||
|
||
@Override | ||
public boolean isShutdown() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public boolean isTerminated() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public boolean awaitTermination(long timeout, TimeUnit unit) { | ||
return false; | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
...tual-threads/runtime/src/main/java/io/quarkus/virtual/threads/VirtualThreadsExecutor.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,9 @@ | ||
package io.quarkus.virtual.threads; | ||
|
||
import java.util.concurrent.ExecutorService; | ||
|
||
/** | ||
* Marker interface for Quarkus managed VirtualThreadPerTaskExecutor | ||
*/ | ||
public interface VirtualThreadsExecutor extends ExecutorService { | ||
} |
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