mirror of
https://github.com/jlengrand/quarkus.git
synced 2026-03-10 08:41:22 +00:00
Run standalone RESTeasy in main thread pool
This means both Servlet and standalone will both use the main thread pool, and it will avoid Vert.x blocked thread warnings. These warnings are useless as blocking IO can potentially block a thread for a long time if request or response is large and the connection is slow.
This commit is contained in:
committed by
Guillaume Smet
parent
7b15072558
commit
6845309a90
@@ -24,6 +24,7 @@ import io.quarkus.deployment.annotations.BuildProducer;
|
||||
import io.quarkus.deployment.annotations.BuildStep;
|
||||
import io.quarkus.deployment.annotations.Record;
|
||||
import io.quarkus.deployment.builditem.ApplicationArchivesBuildItem;
|
||||
import io.quarkus.deployment.builditem.ExecutorBuildItem;
|
||||
import io.quarkus.deployment.builditem.FeatureBuildItem;
|
||||
import io.quarkus.deployment.builditem.HotDeploymentWatchedFileBuildItem;
|
||||
import io.quarkus.deployment.builditem.ShutdownContextBuildItem;
|
||||
@@ -210,7 +211,8 @@ public class ResteasyStandaloneBuildStep {
|
||||
BeanContainerBuildItem beanContainer,
|
||||
ResteasyStandaloneBuildItem standalone,
|
||||
Optional<RequireVirtualHttpBuildItem> requireVirtual,
|
||||
HttpBuildTimeConfig httpConfig) throws Exception {
|
||||
HttpBuildTimeConfig httpConfig,
|
||||
ExecutorBuildItem executorBuildItem) throws Exception {
|
||||
|
||||
if (standalone == null) {
|
||||
return;
|
||||
@@ -221,7 +223,8 @@ public class ResteasyStandaloneBuildStep {
|
||||
|| standalone.deploymentRootPath.equals("/");
|
||||
if (!isDefaultOrNullDeploymentPath) {
|
||||
// We need to register a special handler for non-default deployment path (specified as application path or resteasyConfig.path)
|
||||
Handler<RoutingContext> handler = recorder.vertxRequestHandler(vertx.getVertx(), beanContainer.getValue());
|
||||
Handler<RoutingContext> handler = recorder.vertxRequestHandler(vertx.getVertx(), beanContainer.getValue(),
|
||||
executorBuildItem.getExecutorProxy());
|
||||
// Exact match for resources matched to the root path
|
||||
routes.produce(new RouteBuildItem(standalone.deploymentRootPath, handler, false));
|
||||
String matchPath = standalone.deploymentRootPath;
|
||||
@@ -238,7 +241,7 @@ public class ResteasyStandaloneBuildStep {
|
||||
Consumer<Route> ut = recorder.start(vertx.getVertx(),
|
||||
shutdown,
|
||||
beanContainer.getValue(),
|
||||
isVirtual, isDefaultOrNullDeploymentPath);
|
||||
isVirtual, isDefaultOrNullDeploymentPath, executorBuildItem.getExecutorProxy());
|
||||
|
||||
defaultRoutes.produce(new DefaultRouteBuildItem(ut));
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
@@ -91,7 +92,8 @@ public class ResteasyStandaloneRecorder {
|
||||
public Consumer<Route> start(RuntimeValue<Vertx> vertx,
|
||||
ShutdownContext shutdown,
|
||||
BeanContainer beanContainer,
|
||||
boolean isVirtual, boolean isDefaultResourcesPath) {
|
||||
boolean isVirtual, boolean isDefaultResourcesPath,
|
||||
Executor executor) {
|
||||
|
||||
shutdown.addShutdownTask(new Runnable() {
|
||||
@Override
|
||||
@@ -147,7 +149,7 @@ public class ResteasyStandaloneRecorder {
|
||||
}
|
||||
|
||||
if (deployment != null && isDefaultResourcesPath) {
|
||||
handlers.add(vertxRequestHandler(vertx, beanContainer));
|
||||
handlers.add(vertxRequestHandler(vertx, beanContainer, executor));
|
||||
}
|
||||
return new Consumer<Route>() {
|
||||
|
||||
@@ -161,9 +163,9 @@ public class ResteasyStandaloneRecorder {
|
||||
}
|
||||
|
||||
public Handler<RoutingContext> vertxRequestHandler(RuntimeValue<Vertx> vertx,
|
||||
BeanContainer beanContainer) {
|
||||
BeanContainer beanContainer, Executor executor) {
|
||||
if (deployment != null) {
|
||||
return new VertxRequestHandler(vertx.getValue(), beanContainer, deployment, contextPath, ALLOCATOR);
|
||||
return new VertxRequestHandler(vertx.getValue(), beanContainer, deployment, contextPath, ALLOCATOR, executor);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package io.quarkus.resteasy.runtime.standalone;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
import javax.enterprise.inject.Instance;
|
||||
import javax.enterprise.inject.spi.CDI;
|
||||
@@ -42,18 +43,20 @@ public class VertxRequestHandler implements Handler<RoutingContext> {
|
||||
protected final BeanContainer beanContainer;
|
||||
protected final CurrentIdentityAssociation association;
|
||||
protected final CurrentVertxRequest currentVertxRequest;
|
||||
protected final Executor executor;
|
||||
|
||||
public VertxRequestHandler(Vertx vertx,
|
||||
BeanContainer beanContainer,
|
||||
ResteasyDeployment deployment,
|
||||
String rootPath,
|
||||
BufferAllocator allocator) {
|
||||
BufferAllocator allocator, Executor executor) {
|
||||
this.vertx = vertx;
|
||||
this.beanContainer = beanContainer;
|
||||
this.dispatcher = new RequestDispatcher((SynchronousDispatcher) deployment.getDispatcher(),
|
||||
deployment.getProviderFactory(), null, Thread.currentThread().getContextClassLoader());
|
||||
this.rootPath = rootPath;
|
||||
this.allocator = allocator;
|
||||
this.executor = executor;
|
||||
Instance<CurrentIdentityAssociation> association = CDI.current().select(CurrentIdentityAssociation.class);
|
||||
this.association = association.isResolvable() ? association.get() : null;
|
||||
currentVertxRequest = CDI.current().select(CurrentVertxRequest.class).get();
|
||||
@@ -75,11 +78,14 @@ public class VertxRequestHandler implements Handler<RoutingContext> {
|
||||
return;
|
||||
}
|
||||
|
||||
vertx.executeBlocking(event -> {
|
||||
dispatch(request, is, new VertxBlockingOutput(request.request()));
|
||||
}, false, event -> {
|
||||
if (event.failed()) {
|
||||
request.fail(event.cause());
|
||||
executor.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
dispatch(request, is, new VertxBlockingOutput(request.request()));
|
||||
} catch (Throwable e) {
|
||||
request.fail(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user