forked from jooby-project/jooby
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExecutionMode.java
More file actions
88 lines (85 loc) · 1.91 KB
/
ExecutionMode.java
File metadata and controls
88 lines (85 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/**
* Jooby https://jooby.io
* Apache License Version 2.0 https://jooby.io/LICENSE.txt
* Copyright 2014 Edgar Espina
*/
package io.jooby;
/**
* Execution mode.
*
* @author edgar
*/
public enum ExecutionMode {
/**
* Execute route handler in the event loop thread (non-blocking). Handler must never block.
*
* Examples:
* <pre>{@code
* {
* mode(EVENT_LOOP);
*
* get("/non-blocking", ctx -> "I'm running on event-loop thread (no blocking allowed)");
*
* // Dispatch to worker thread, blocking routes
* dispatch(() -> {
*
* get("/blocking", ctx -> {
* // remote call: service, database, etc..
* return "Safe to block";
* });
* });
* }
* }</pre>
*/
EVENT_LOOP,
/**
* Execute handler in a worker/io thread (blocking). Handler is allowed to block.
*
* Examples:
* <pre>{@code
* {
*
* mode(WORKER);
*
* get("/worker", ctx -> {
* // remote call: another service, database, etc..
* return "Safe to block";
* });
* }
*
* }</pre>
*/
WORKER,
/**
* Default execution mode.
*
* Automatically choose between {@link ExecutionMode#EVENT_LOOP} and {@link ExecutionMode#WORKER}.
*
* If route handler returns a `reactive` type, then Jooby run the route handler in the event-loop
* thread. Otherwise, run the handler in the worker thread.
*
* A reactive type is one of:
*
* - {@link java.util.concurrent.CompletableFuture}.
* - A reactive stream Publisher
* - Rx types: Observable, Flowable, Single, Maybe, etc..
* - Reactor types: Flux and Mono.
*
* Examples:
* <pre>{@code
* {
*
* get("/non-blocking", ctx -> {
* return CompletableFuture.supplyAsync(() -> {
* return "I'm non-blocking";
* });
* });
*
* get("/blocking", ctx -> {
* return "I'm blocking";
* });
* }
* }</pre>
*/
DEFAULT
}