Skip to content

Commit d9b9001

Browse files
committed
support call ExpressHandler directly in iothread
1 parent 8f67e85 commit d9b9001

34 files changed

Lines changed: 252 additions & 96 deletions

pom.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,12 @@
1818
********************************************
1919
* version history
2020
********************************************
21+
0.4.0
22+
- Performance tuning: enable direct io thread processing handler
23+
2124
0.3.1
2225
- ActiveRecord -> AdaptiveRecord
26+
- Performance tuning: enable nonblocking IO
2327
2428
0.3.0
2529
- Catch up update to osgl-mvc 0.6.0: Bind annotation now support specifying multiple Binder implementations
@@ -48,7 +52,7 @@
4852
<groupId>org.actframework</groupId>
4953
<artifactId>act</artifactId>
5054
<packaging>jar</packaging>
51-
<version>0.3.1-SNAPSHOT</version>
55+
<version>0.4.0-SNAPSHOT</version>
5256

5357
<name>ACT Framework</name>
5458
<description>The ACT full stack MVC framework</description>

src/main/java/act/app/ActionContext.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ private ActionContext(App app, H.Request request, H.Response response) {
8585
this.disableCsrf = req().method().safe();
8686
this.sessionKeyUsername = config.sessionKeyUsername();
8787
this.localeResolver = new LocaleResolver(this);
88-
this.saveLocal();
8988
}
9089

9190
public State state() {

src/main/java/act/conf/AppConfig.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ public AppConfig<T> app(App app) {
8888
E.NPE(app);
8989
this.app = app;
9090
AppConfigKey.onApp(app);
91+
// preload some common used configurations
92+
sessionCookieName();
93+
sessionCookiePrefix();
9194
return this;
9295
}
9396

src/main/java/act/handler/DelegateRequestHandler.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ protected DelegateRequestHandler(RequestHandler handler) {
1717
this.realHandler = handler instanceof RequestHandlerBase ? ((RequestHandlerBase) handler).realHandler() : handler;
1818
}
1919

20+
@Override
21+
public boolean express() {
22+
return handler_.express();
23+
}
24+
2025
@Override
2126
public void handle(ActionContext context) {
2227
handler_.handle(context);
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
package act.handler.builtin;
1+
package act.handler;
22

33
/**
44
* This is a tag interface that when a {@link act.handler.RequestHandler} implement this
55
* means the underline network can invoke the handler directly in IO thread instead of worker
66
* thread
77
*/
8-
public interface DirectIO {
8+
public interface ExpressHandler {
99
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package act.handler;
2+
3+
import act.Act;
4+
5+
import java.lang.annotation.ElementType;
6+
import java.lang.annotation.Retention;
7+
import java.lang.annotation.RetentionPolicy;
8+
import java.lang.annotation.Target;
9+
10+
/**
11+
* Mark a class method as non-block method.
12+
*
13+
* When an action handler created from an non-block
14+
* method the handler will be treated as an {@link ExpressHandler}
15+
*/
16+
@Retention(RetentionPolicy.RUNTIME)
17+
@Target(ElementType.METHOD)
18+
public @interface NonBlock {
19+
}

src/main/java/act/handler/OptionsRequestHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import act.handler.builtin.controller.FastRequestHandler;
55
import act.security.CORS;
66

7-
public class OptionsRequestHandler extends FastRequestHandler {
7+
public class OptionsRequestHandler extends FastRequestHandler implements ExpressHandler {
88

99
private CORS.Spec corsSpec;
1010

src/main/java/act/handler/RequestHandler.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,17 @@ public interface RequestHandler extends $.Function<ActionContext, Void>, Destroy
2323
*/
2424
void handle(ActionContext context);
2525

26+
/**
27+
* Indicate the handler logic is fast enough to be put into network layer's io thread and
28+
* does not require to dispatch to worker thread.
29+
*
30+
* Note a handler that implements {@link ExpressHandler} should
31+
* always return `true` for this method
32+
*
33+
* @return `true` if this handler support direct io thread processing
34+
*/
35+
boolean express();
36+
2637
/**
2738
* Indicate if this request handler support partial path lookup.
2839
* Usually this method should return {@code false}. However for

src/main/java/act/handler/RequestHandlerBase.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ public final Void apply(ActionContext context) throws NotAppliedException, $.Bre
1919
return null;
2020
}
2121

22+
@Override
23+
public boolean express() {
24+
return this instanceof ExpressHandler;
25+
}
26+
2227
@Override
2328
public Class<? extends Annotation> scope() {
2429
return ApplicationScoped.class;

src/main/java/act/handler/UnknownHttpMethodProcessor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public abstract class UnknownHttpMethodProcessor implements Serializable {
1414

1515
public abstract Result handle(H.Method method);
1616

17-
private static class NotAllowed extends UnknownHttpMethodProcessor {
17+
private static class NotAllowed extends UnknownHttpMethodProcessor implements ExpressHandler {
1818
@Override
1919
public Result handle(H.Method method) {
2020
return MethodNotAllowed.INSTANCE;
@@ -25,7 +25,7 @@ private Object readResolve() {
2525
}
2626
}
2727

28-
private static class NotImplemented extends UnknownHttpMethodProcessor {
28+
private static class NotImplemented extends UnknownHttpMethodProcessor implements ExpressHandler {
2929
@Override
3030
public Result handle(H.Method method) {
3131
return org.osgl.mvc.result.NotImplemented.INSTANCE;

0 commit comments

Comments
 (0)