[undertow-dev] Delay execution of a HttpHandler
Carter Kozak
ckozak at apache.org
Fri Jan 4 09:40:20 EST 2019
Perhaps some thing along these lines:
public void handleRequest(HttpServerExchange exchange) throws Exception {
exchange.dispatch(SameThreadExecutor.INSTANCE, () -> {
exchange.getIoThread().executeAfter(() ->
Connectors.executeRootHandler(next, exchange), duration, unit);
});
}
Best,
Carter
On Fri, Jan 4, 2019 at 12:53 AM Bill O'Neil <bill at dartalley.com> wrote:
>
> Hello,
>
> I'm looking for a way to add artificial latency to requests and I'm having trouble finding a way that wouldn't require a blocking pool with 1 thread per request.
>
> What I would like to happen if possible.
>
> handler marks exchange as not ready (yield / pause)
> async runnable from another thread marks it ready to resume after some time
> next iteration of IO loop catches that it is ready and actually executes it now.
>
>
> public void handle(HttpServerExchange exchange) {
> if (firstExecution) {
> scheduledExec.schedule(() -> exchange.resume(), duration, unit);
> return;
> }
> next.handle(exchange);
> }
>
> Is something like this possible while staying on the IO threads the whole time other than the ScheduledExecutorService? I was thinking of using dispatch and dispatching back to the IO executor but I don't think that will do what I intend.
>
> The end goal would be a way to handle N requests with various delays built in to simulate latency without blocking connections. For instance if the worker pool has 30 threads and I submit 100 requests with a 1 minute delay followed by 1 request with a 10 second delay the final request should come back first.
>
> Thanks,
> Bill
> _______________________________________________
> undertow-dev mailing list
> undertow-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/undertow-dev
More information about the undertow-dev
mailing list