-
Notifications
You must be signed in to change notification settings - Fork 0
/
jersey-sse-ozark.html
322 lines (233 loc) · 5.09 KB
/
jersey-sse-ozark.html
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
<!DOCTYPE html>
<html>
<head>
<title>Java EE 8を先取る</title>
<meta charset="utf-8">
<style>
@import url(https://fonts.googleapis.com/css?family=Ubuntu+Mono:400,700,400italic);
@font-face {
font-family: 'mplus';
src: url('assets/mplus-1c-regular.ttf');
}
h1, h2, h3, h4, h5, h6 {
font-family: 'mplus';
}
p, li {
font-family: 'mplus';
font-size: 1.2em;
}
strong {
text-decoration: underline;
}
li p, li li {
font-size: 1em;
}
code.remark-inline-code {
font-family: 'Ubuntu Mono';
}
code.remark-code {
font-family: 'Ubuntu Mono';
font-size: 1.2em;
}
table {
border-right: thin solid silver;
border-bottom: thin solid silver;
}
th, td {
border-left: thin solid silver;
border-top: thin solid silver;
}
</style>
</head>
<body>
<textarea id="source">
class: center, middle
# Java EE 8を先取る
---
class: center, middle
## Java EE 8新機能
---
## Server-Sent Events (SSE)
* サーバー→クライアントの通知
* HTTPプロトコルで実現
---
## MVC 1.0
* アクションベースのMVC
* JAX-RS拡張として提供
---
## その他
* [JSON Binding](https://www.jcp.org/en/jsr/detail?id=367)
* HTTP/2サポート
* CDIの強化
* [Java EE Management API 2.0](https://www.jcp.org/en/jsr/detail?id=373)
* [Java EE Security API](https://www.jcp.org/en/jsr/detail?id=375)
---
### Java EE 8のリリーススケジュール
[JSR 366](https://www.jcp.org/en/jsr/detail?id=366)より引用
* Q4 2015 Early Draft
* Q1 2016 Public Review
* Q3 2016 Proposed Final Draft
* H1 2017 Final Release
---
class: center, middle
## そんなに待てない!!!
---
class: center, middle
### そこで……
---
class: center, middle
## Jersey SSE Support
JerseyによるServer-Sent Eventsのサポート
![](./assets/jersey_logo.png)
---
class: center, middle
## Ozark
MVC 1.0の参照実装
![](./assets/ozark_logo.jpg)
---
class: center, middle
## ですよ!!!
---
class: center, middle
### もうちょい詳しく
---
## Jersey SSE Support
* JerseyはJAX-RSの参照実装
* Jersey SSE SupportはJerseyでSSEするための拡張
* dependenciesに一行足すだけで使える(Gradle)
---
## 例:Jersey SSE
```java
@RequestScoped
@Path("sse")
public class SimpleSSESample {
@Resource
private ManagedExecutorService executor;
@GET
@Produces(SseFeature.SERVER_SENT_EVENTS)
public EventOutput sendEvents() {
EventOutput out = new EventOutput();
executor.submit(new Task(out));
return out;
}
}
```
---
## 例:Jersey SSE
```java
class Task implements Callable<Void> {
private final EventOutput out;
public Task(EventOutput out) { this.out = out; }
public Void call() throws Exception {
try {
for (int i = 0; i < 10; i++) {
TimeUnit.SECONDS.sleep(1);
OutboundEvent event =
new OutboundEvent.Builder()
.name("message")
.data("Hello " + i).build();
out.write(event);
}
return null;
} finally { out.close(); }
}
}
```
---
## 例:Jersey SSE
クライアント側のコード(JavaScript)
```javascript
var es = new EventSource('/sample/app/sse');
es.addEventListener('message', function(event) {
console.log(event.data);
});
```
---
## 例:Jersey SSE
実行結果
```
Hello 0
Hello 1
Hello 2
Hello 3
Hello 4
Hello 5
Hello 6
Hello 7
Hello 8
Hello 9
```
※1秒毎に表示される
---
## 例:Jersey SSE
build.gradleの記述例
```groovy
dependencies {
compile 'org.glassfish.jersey.media:jersey-media-sse:2.22'
}
```
---
## Ozark
* JSR 371 MVC 1.0の参照実装
* Jerseyをベースに作られている
* JSP、Thymeleaf、mustacheなどのテンプレートに対応
* dependenciesに一行足すだけで使える(Gradle)
---
## 例:Ozark
```java
@RequestScoped
@Path("hello")
public class HelloController {
@Inject
private Models models;
@Controller
@GET
public String sayHello(@QueryParam("name") String name) {
models.put("name", name);
return "hello.jsp";
}
}
```
---
## 例:Ozark
```jsp
<%@ page contentType="text/html; charset=UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<title>Hello</title>
</head>
<body>
<p>Hello, ${name}!</p>
</body>
</html>
```
---
## 例:Ozark
build.gradleの記述例
```groovy
dependencies {
compile 'org.glassfish.ozark:ozark:1.0.0-m02'
}
```
---
## サンプル作ってみました
https://github.com/backpaper0/jersey-sse-ozark-sample
![](./assets/jersey-sse-ozark-sample-screenshot.png)
---
## まとめ
* Java EE 8の新機能の一部は今からでも試せる
* 素振りをしておくとスムーズに導入できる
* もしくは、導入しないという判断もしやすい
---
## この資料について
* Author: [@backpaper0](https://github.com/backpaper0)
* License: [The MIT License](https://opensource.org/licenses/MIT)
</textarea>
<script src="assets/remark.min.js">
</script>
<script>
var slideshow = remark.create();
</script>
</body>
</html>