You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: md/app.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -70,7 +70,7 @@ public class MyModule implements Jooby.Module {
70
70
}
71
71
```
72
72
73
-
The `onStart` callbacks are part of bootstrap and executed before server is ready. The `onStarted` callbacks are executed when server is ready.
73
+
The `onStart` callbacks are part of bootstrap and executed before the server is ready. The `onStarted` callbacks are executed when the server is ready.
74
74
75
75
Modules are covered later all you need to know now is that you can start/stop module as you usually do from your application.
76
76
@@ -95,7 +95,7 @@ Callback order is preserved:
95
95
}
96
96
```
97
97
98
-
Order is useful for service dependencies, like `ServiceB` should be started after `ServiceA`.
98
+
Order is useful for service dependencies, for example if `ServiceB` should be started after `ServiceA`.
99
99
100
100
### service registry
101
101
@@ -117,7 +117,7 @@ You have access to the the service registry from start/stop events:
Copy file name to clipboardExpand all lines: md/asset-processor.md
+16-15Lines changed: 16 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,10 +1,10 @@
1
1
# asset processor
2
2
3
-
Checks, validate and/or modify asset contents. An [AssetProcessor]({{defdocs}}/assets/AssetProcessor.html) is usually provided as a separated dependency.
3
+
Checks, validates and/or modifies asset contents. An [AssetProcessor]({{defdocs}}/assets/AssetProcessor.html) is usually provided as a separate dependency.
4
4
5
-
## how to use it?
5
+
## usage
6
6
7
-
First thing to do is to add the dependency:
7
+
Start by adding the dependency to your ```pom.xml```:
8
8
9
9
```xml
10
10
<dependency>
@@ -14,9 +14,10 @@ First thing to do is to add the dependency:
14
14
</dependency>
15
15
```
16
16
17
-
Did you see the **provided** scope? We just need the processor for development, because assets are processed at runtime. In ```prod```, assets are processed at built-time via Maven/Gradle plugin, so we don't need this library/dependency. This also, helps to keep our dependencies and the jar size small.
17
+
Notice the **provided** scope. The processor is only required for development, since the assets are processed at runtime in this case. In ```prod```, assets are processed at build-time via the Maven or Gradle plugins, so the dependency is not needed there. This also helps to keep the number of dependencies and the jar size smaller.
18
+
19
+
After the dependency is declared, all that's needed is to add the processor to the pipeline:
18
20
19
-
Now we have the dependency all we have to do is to add it to our pipeline:
20
21
21
22
```text
22
23
assets {
@@ -28,7 +29,7 @@ assets {
28
29
29
30
## configuration
30
31
31
-
It is possible to configure or set options too:
32
+
It's possible to configure or set options as well:
32
33
33
34
```text
34
35
assets {
@@ -42,7 +43,7 @@ assets {
42
43
}
43
44
```
44
45
45
-
Previous example, set a```foo``` property to ```bar```! Options can be set per environment too:
46
+
The previous example sets the```foo``` property to ```bar```. Options can be set per environment as well:
46
47
47
48
```text
48
49
assets {
@@ -62,11 +63,11 @@ assets {
62
63
}
63
64
```
64
65
65
-
Here, in ```dev```processor has two properties: ```foo:foo``` and ```bar:bar```, while in ```dist``` the processor only has```foo:bar```
66
+
In this example, the processor will have two properties in the ```dev```environment: ```foo:foo``` and ```bar:bar```, while in ```dist``` the processor will only have```foo:bar```
66
67
67
68
## binding
68
69
69
-
The ```my-processor``` will be resolved it to: ```org.jooby.assets.MyProcessor``` class. The processor name is converted to ```MyProcessor```, it converts the hyphenated name to upper camel and by default processors are defined in the ```org.jooby.assets``` package.
70
+
The ```my-processor```token will be resolved to the: ```org.jooby.assets.MyProcessor``` class. The processor name is converted to ```MyProcessor``` by converting the hyphenated name to upper camel case and by placing it in the ```org.jooby.assets``` package (a default for processors).
70
71
71
72
A custom binding is provided via the ```class``` property:
72
73
@@ -86,9 +87,9 @@ assets {
86
87
87
88
Contributes new or dynamically generated content to a ```fileset```. Content generated by an aggregator might be processed by an {@link AssetProcessor}.
88
89
89
-
## how to use it?
90
+
## usage
90
91
91
-
First thing to do is to add the dependency:
92
+
Start by adding the dependency to your ```pom.xml```:
92
93
93
94
```xml
94
95
<dependency>
@@ -99,9 +100,9 @@ First thing to do is to add the dependency:
99
100
100
101
```
101
102
102
-
Did you see the **provided** scope? We just need the aggregator for development, because assets are processed at runtime. In ```prod```, assets are processed at built-time via Maven/Gradle plugin, so we don't need it. This also, helps to keep our dependencies and the jar size small.
103
+
Notice the **provided** scope. The aggregator is only required for development, since the assets are processed at runtime in this case. In ```prod```, assets are processed at build-time via the Maven or Gradle plugins, so the dependency is not needed there. This also helps to keep the number of dependencies and the jar size smaller.
103
104
104
-
Now we have the dependency all we have to do is to add the ```svg-sprites``` aggregator to a fileset:
105
+
After the dependency is declared, all that's needed is to add the ```svg-sprites``` aggregator to a fileset:
105
106
106
107
```
107
108
assets {
@@ -124,7 +125,7 @@ assets {
124
125
}
125
126
```
126
127
127
-
Here for example, the ```svg-sprites``` aggregator contributes the ```css/sprite.css``` file to the ```home``` fileset. The fileset then looks like:
128
+
In this example, the ```svg-sprites``` aggregator contributes the ```css/sprite.css``` file to the ```home``` fileset. The fileset then looks like:
128
129
129
130
```
130
131
assets {
@@ -138,7 +139,7 @@ assets {
138
139
}
139
140
```
140
141
141
-
It replaces the aggregator name with one or more files from [AssetAggregator.fileset]({{defdocs}}/assets/AssetAggregator.html#fileset--) method.
142
+
It replaces the aggregator name with one or more files from the [AssetAggregator.fileset]({{defdocs}}/assets/AssetAggregator.html#fileset--) method.
Copy file name to clipboardExpand all lines: md/async.md
+30-30Lines changed: 30 additions & 30 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,14 +1,14 @@
1
1
# thread model
2
2
3
-
You can see {{jooby}} as an `event loop server` thanks to the supported web servers: {{netty_server}}, {{jetty_server}} and {{undertow_server}}. Being {{netty_server}} the default web server.
3
+
You can see {{jooby}} as an `event loop server` thanks to the supported web servers: {{netty_server}}, {{jetty_server}} and {{undertow_server}}. The default web server is {{netty_server}}.
4
4
5
5
{{jooby}} isn't a traditional `thread server` where a HTTP request is bound to a thread.
6
6
7
7
In {{jooby}} all the HTTP IO operations are performed in async & non blocking fashion. HTTP IO operations run in an IO thread (a.k.a event loop) while the application logic (your code) **always run in a worker thread**.
8
8
9
9
## worker threads
10
10
11
-
The **worker thread** pool is provided by the web server: {{netty_server}}, {{jetty_server}} and {{undertow_server}}. To simplify application programming you can **block a worker thread**, for example you can safely run a **jdbc** query in a **worker thread**:
11
+
The **worker thread** pool is provided by one of the supported web servers: {{netty_server}}, {{jetty_server}} or {{undertow_server}}. To simplify application programming you can **block a worker thread**, for example you can safely run a **jdbc** query in a **worker thread**:
12
12
13
13
```java
14
14
{
@@ -22,11 +22,11 @@ The **worker thread** pool is provided by the web server: {{netty_server}}, {{je
22
22
}
23
23
```
24
24
25
-
Here the web server can accept as many connection it can (as its on non blocking) while the worker thread might blocks.
25
+
The web server can accept as many connections it can (as its on non blocking) while the worker thread might block.
26
26
27
-
Default worker thread pool is `20/100`. The correct/right size depends on your**business** and **work load** your application is suppose to handle. We suggest you to start with default setup and see how it goes, later you can reduce or increase the thread pool.
27
+
The default worker thread pool is `20/100`. The optimal size depends on the**business** and **work load** your application is supposed to handle. It's recommended to start with the default setup and then tune the size of the thread pool if the need arises.
28
28
29
-
In {{jooby}} we favor simplicity over complexity that is why your **code**can block, still there are more advanced setup that allow you to build async and reactive applications.
29
+
{{jooby}} favors simplicity over complexity hence allowing your **code**to block. However, it also provides you with more advanced options that will allow you to build async and reactive applications.
30
30
31
31
## deferred
32
32
@@ -54,7 +54,7 @@ MVC API:
54
54
}
55
55
```
56
56
57
-
Previousexamples are just `syntax sugar` for:
57
+
The previous examples are just `syntactic sugar` for:
58
58
59
59
```
60
60
returnnewDeferred(deferred -> {
@@ -66,7 +66,7 @@ Previous examples are just `syntax sugar` for:
66
66
});
67
67
```
68
68
69
-
There is more `syntax sugar` if you add the [AsyncMapper]({{defdocs}}/AsyncMapper.html) to your application:
69
+
You can get more `syntactic sugar` if you add the [AsyncMapper]({{defdocs}}/AsyncMapper.html) to your application:
70
70
71
71
ScriptAPI:
72
72
@@ -95,9 +95,9 @@ MVC API:
95
95
}
96
96
```
97
97
98
-
The [AsyncMapper]({{defdocs}}/AsyncMapper.html) convert `java.util.concurrent.Callable` and `java.util.concurrent.CompletableFuture` objects to {{deferred}} objects.
98
+
The [AsyncMapper]({{defdocs}}/AsyncMapper.html) converts `java.util.concurrent.Callable` and `java.util.concurrent.CompletableFuture` objects to {{deferred}} objects.
99
99
100
-
Another important thing to notice is that the deferred run in the **caller thread** (i.e. worker thread), so by default there is **no context switch**involve while running a {{deferred}} result:
100
+
Another important thing to notice is that the deferred will run in the **caller thread** (i.e. worker thread), so by default there is **no context switch**involved in obtaining a {{deferred}} result:
101
101
102
102
```java
103
103
{
@@ -111,15 +111,15 @@ Another important thing to notice is that the deferred run in the **caller threa
111
111
}
112
112
```
113
113
114
-
You might first see this as a bad thing, but is actually a good decision, because:
114
+
This might not seem optimal at first, but there are some benefits to this:
115
115
116
-
*Itis supereasy to setup a default executor (we will see how soon)
116
+
*Itmakes it very easy to set up a default executor (this will be explained shortly)
117
117
118
-
*Providesbetter integration with async & reactive libraries. A `direct` executor avoid the need of switching to a new thread and then probably dispatch (again) to a different thread provided by a library.
118
+
*It provides better integration with async & reactive libraries. A `direct` executor avoids the need of switching to a new thread and then probably dispatch (again) to a different thread provided by a library.
119
119
120
120
## executor
121
121
122
-
Aswe said before, the default executor run in the caller thread (a.k.a direct executor).Let's see how to override the default executor:
122
+
Aspreviously mentioned, the default executor runs in the caller thread (a.k.a direct executor).Let's see how to override the default executor:
123
123
124
124
```java
125
125
{
@@ -131,7 +131,7 @@ As we said before, the default executor run in the caller thread (a.k.a direct e
131
131
}
132
132
```
133
133
134
-
Done! Now all our {{deferred}} result run in a `ForkJoinPool`. It also possible to specify an alternative executor:
134
+
Done! Now all our {{deferred}} results run in a `ForkJoinPool`. It's also possible to specify an alternative executor:
Worth mention the [executor(ExecutorService)]({{defdocs}}/Jooby.html#executor-java.util.concurrent.ExecutorService-) methods automatically `shutdown` at application shutdown time.
178
+
It's worth mentioning that the [executor(ExecutorService)]({{defdocs}}/Jooby.html#executor-java.util.concurrent.ExecutorService-) methods automatically `shutdown` at application shutdown time.
179
179
180
180
## promise
181
181
@@ -216,17 +216,17 @@ MVC API:
216
216
}
217
217
```
218
218
219
-
The **"promise"** version of {{deferred}} object is a key concept for integrating with external libraries.
219
+
The **"promise"** version of the {{deferred}} object is a key concept for integrating with external libraries.
220
220
221
221
## advanced configuration
222
222
223
-
Suppose you want to build a truly async application and after a **deep analysis** of your business you realize your application need to:
223
+
Suppose you want to build a truly async application and after a **deep analysis** of your business demands you realize your application needs to:
224
224
225
225
* Access a database
226
226
* Call a remote service
227
227
* Make a CPU intensive computation
228
228
229
-
These are the 3 points where your application is suppose to block and wait for a result.
229
+
These are the 3 points where your application is supposed to block and wait for a result.
230
230
231
231
Let's start by reducing the **worker thread pool** to the number of **available processors**:
Withthis change, you need to be careful and**don't run blocking code** on routes anymore. Otherwise performance will be affected.
238
+
Withthis change, you need to be careful to**avoid any blocking code** on routes, otherwise performance will suffer.
239
239
240
240
Let's create a custom thread pool for each blocking access:
241
241
@@ -247,11 +247,11 @@ Let's create a custom thread pool for each blocking access:
247
247
}
248
248
```
249
249
250
-
For `database` access, we use a `cached` executor that will grow without a limit but free and release thread that are idle after `60s`.
250
+
For `database` access, we use a `cached` executor which will grow without a limit but free and release threads that are idle after `60s`.
251
251
252
-
For `remote` service, we use a `fixed` executor of `32` thread. The number here: `32` is just a random number for the purpose of the example.
252
+
For `remote` service, we use a `fixed` executor of `32` threads. The number `32` is just a random number for the purpose of the example.
253
253
254
-
For `intensive` computation, we use a `single` thread executor. Computation is too expensive and we want **one and only one** running at any time.
254
+
For `intensive` computations, we use a `single` thread executor. Computation is too expensive and we want **one and only one** running at any time.
255
255
256
256
```java
257
257
{
@@ -277,7 +277,7 @@ For `intensive` computation, we use a `single` thread executor. Computation is t
277
277
}
278
278
```
279
279
280
-
Here is the same example with [rx java](https://github.com/ReactiveX/RxJava):
280
+
Here's the same example with [rx java](https://github.com/ReactiveX/RxJava):
281
281
282
282
```java
283
283
{
@@ -314,14 +314,14 @@ Here is the same example with [rx java](https://github.com/ReactiveX/RxJava):
314
314
}
315
315
```
316
316
317
-
Main difference are:
317
+
The main differences are:
318
318
319
-
*we keep the default executor:`direct`.So we don't create a new thread and avoid context switching.
320
-
* we use {{deferred}} object as `promise` and integrate with [rx java](https://github.com/ReactiveX/RxJava).
321
-
* different thread pool semantic is done via [rx schedulers](http://reactivex.io/documentation/scheduler.html).
319
+
* the default executor is kept `direct`. No new thread is created and context switching is avoided.
320
+
* the {{deferred}} object is used as a `promise` and integrate with [rx java](https://github.com/ReactiveX/RxJava).
321
+
* different thread pool semantics is achieved with the help of [rx schedulers](http://reactivex.io/documentation/scheduler.html).
322
322
323
-
This is just one more example to demonstrate the value of the {{deferred}} object, because we provide an [rxjava](/doc/rxjava) module which takes care of binding {{deferred}} object into `Observables`.
323
+
This is just another example to demonstrate the value of the {{deferred}} object, since a [rxjava](/doc/rxjava) module is provided which takes care of binding the {{deferred}} object into `Observables`.
324
324
325
-
That's all about {{deferred}} object, it allows you to build async and reactive applications and at the same time:**keep it simple** (Jooby design goal).
325
+
That sums up everything about the {{deferred}} object. It allows you to build async and reactive applications and at the same time: **keep it simple** (a Jooby design goal).
326
326
327
-
Also, we invite you to checkout the available [async/reactive modules](/doc/async).
327
+
You're also invited to check out the available [async/reactive modules](/doc/async).
0 commit comments