Skip to content

Commit add72a5

Browse files
committed
context: remove detach from Context
- fix #3791 - handle undertow dispatch/detach internally
1 parent 7e16c69 commit add72a5

File tree

18 files changed

+35
-127
lines changed

18 files changed

+35
-127
lines changed

jooby/src/main/java/io/jooby/Context.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,18 +1010,6 @@ default Value lookup(String name) {
10101010
*/
10111011
Context dispatch(@NonNull Executor executor, @NonNull Runnable action);
10121012

1013-
/**
1014-
* Tells context that response will be generated form a different thread. This operation is
1015-
* similar to {@link #dispatch(Runnable)} except there is no thread dispatching here.
1016-
*
1017-
* <p>This operation integrates easily with third-party libraries like rxJava or others.
1018-
*
1019-
* @param next Application code.
1020-
* @return This context.
1021-
* @throws Exception When detach operation fails.
1022-
*/
1023-
Context detach(@NonNull Route.Handler next) throws Exception;
1024-
10251013
/**
10261014
* Perform a websocket handsahke and upgrade a HTTP GET into a websocket protocol.
10271015
*

jooby/src/main/java/io/jooby/ForwardingContext.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,12 +1044,6 @@ public Context dispatch(@NonNull Executor executor, @NonNull Runnable action) {
10441044
return this;
10451045
}
10461046

1047-
@Override
1048-
public Context detach(@NonNull Route.Handler next) throws Exception {
1049-
ctx.detach(next);
1050-
return this;
1051-
}
1052-
10531047
@Override
10541048
public Context upgrade(@NonNull WebSocket.Initializer handler) {
10551049
ctx.upgrade(handler);

jooby/src/main/java/io/jooby/Route.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ public void setRoute(Route route) {
106106
}
107107
}
108108

109+
/** Marker interface for reactive responses. */
110+
public interface Reactive extends Filter {}
111+
109112
/**
110113
* Decorates a handler and run logic before handler is executed.
111114
*
@@ -699,7 +702,7 @@ public Route setEncoder(@NonNull MessageEncoder encoder) {
699702
*
700703
* @return Truth when route is non-blocking. False otherwise or <code>null</code> otherwise.
701704
*/
702-
@NonNull public boolean isNonBlocking() {
705+
public boolean isNonBlocking() {
703706
return nonBlocking == Boolean.TRUE;
704707
}
705708

jooby/src/main/java/io/jooby/internal/Pipeline.java

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
package io.jooby.internal;
77

88
import static io.jooby.internal.handler.DefaultHandler.DEFAULT;
9-
import static io.jooby.internal.handler.DetachHandler.DETACH;
109
import static io.jooby.internal.handler.WorkerHandler.WORKER;
1110

1211
import java.util.concurrent.Executor;
@@ -20,19 +19,11 @@
2019
public class Pipeline {
2120

2221
public static Handler build(
23-
boolean requiresDetach,
24-
Route route,
25-
ExecutionMode mode,
26-
Executor executor,
27-
ContextInitializer initializer) {
22+
Route route, ExecutionMode mode, Executor executor, ContextInitializer initializer) {
2823
// Set default wrapper and blocking mode
2924
if (!route.isNonBlockingSet()) {
3025
route.setNonBlocking(isDefaultNonblocking(executor, mode));
3126
}
32-
Route.Filter wrapper = DEFAULT;
33-
if (requiresDetach && route.isNonBlocking()) {
34-
wrapper = DETACH.then(wrapper);
35-
}
3627

3728
// Non-Blocking? Split pipeline Head+Handler let reactive call After pipeline
3829
Handler pipeline;
@@ -43,7 +34,7 @@ public static Handler build(
4334
pipeline = route.getPipeline();
4435
}
4536
return dispatchHandler(
46-
mode, executor, decorate(initializer, wrapper.then(pipeline)), route.isNonBlocking());
37+
mode, executor, decorate(initializer, DEFAULT.then(pipeline)), route.isNonBlocking());
4738
}
4839

4940
private static boolean isDefaultNonblocking(Executor executor, ExecutionMode mode) {

jooby/src/main/java/io/jooby/internal/RouterImpl.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -592,10 +592,8 @@ public void initialize() {
592592
prependMediaType(route.getConsumes(), route.getFilter(), Route.SUPPORT_MEDIA_TYPE));
593593
route.setFilter(prependMediaType(route.getProduces(), route.getFilter(), Route.ACCEPT));
594594
}
595-
boolean requiresDetach = server.getName().equals("undertow");
596595
Route.Handler pipeline =
597-
Pipeline.build(
598-
requiresDetach, route, forceMode(route, mode), executor, postDispatchInitializer);
596+
Pipeline.build(route, forceMode(route, mode), executor, postDispatchInitializer);
599597
route.setPipeline(pipeline);
600598
/** Final render */
601599
route.setEncoder(encoder);

jooby/src/main/java/io/jooby/internal/handler/ConcurrentHandler.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import edu.umd.cs.findbugs.annotations.NonNull;
1616
import io.jooby.Route;
1717

18-
public class ConcurrentHandler implements Route.Filter {
18+
public class ConcurrentHandler implements Route.Reactive {
1919

2020
@NonNull @Override
2121
public Route.Handler apply(@NonNull Route.Handler next) {
@@ -38,11 +38,11 @@ public Route.Handler apply(@NonNull Route.Handler next) {
3838
after.apply(ctx, value, unwrap((Throwable) x));
3939
}
4040
if (x != null) {
41-
Throwable exception = unwrap((Throwable) x);
41+
Throwable exception = unwrap(x);
4242
ctx.sendError(exception);
4343
} else {
4444
// See https://github.com/jooby-project/jooby/issues/3486
45-
if (!ctx.isResponseStarted() && value != ctx) {
45+
if (!ctx.isResponseStarted() && value != ctx && value != null) {
4646
ctx.render(value);
4747
}
4848
}

jooby/src/main/java/io/jooby/internal/handler/DetachHandler.java

Lines changed: 0 additions & 26 deletions
This file was deleted.

modules/jooby-jetty/src/main/java/io/jooby/internal/jetty/JettyContext.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -370,12 +370,6 @@ public Context dispatch(@NonNull Executor executor, @NonNull Runnable action) {
370370
return this;
371371
}
372372

373-
@NonNull @Override
374-
public Context detach(@NonNull Route.Handler next) throws Exception {
375-
next.apply(this);
376-
return this;
377-
}
378-
379373
@NonNull @Override
380374
public Context upgrade(@NonNull WebSocket.Initializer handler) {
381375
try {

modules/jooby-mutiny/src/main/java/io/jooby/mutiny/Mutiny.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
public class Mutiny {
2424

2525
private static final Route.Filter MUTINY =
26-
new Route.Filter() {
26+
new Route.Reactive() {
2727

2828
private void after(Context ctx, Object value, Throwable failure) {
2929
Route.After after = ctx.getRoute().getAfter();

modules/jooby-netty/src/main/java/io/jooby/internal/netty/NettyContext.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -253,12 +253,6 @@ public Context dispatch(Executor executor, Runnable action) {
253253
return this;
254254
}
255255

256-
@NonNull @Override
257-
public Context detach(@NonNull Route.Handler next) throws Exception {
258-
next.apply(this);
259-
return this;
260-
}
261-
262256
@NonNull @Override
263257
public QueryString query() {
264258
if (query == null) {

0 commit comments

Comments
 (0)