Copyright © 2012, Oracle and/or its affiliates. All rights reserved.1
Yoshio Terada
Java Evangelist
http://yoshio3.com, Tw...
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.2
以下の事項は、弊社の一般的な製品の方向性に関する概要を説明するもので
す。また、情報提供を唯一の目的とす...
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.3
Make the Future Java
(Java の未来を創造)
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.4
 Java EE 7
– HTML 5 とシンプル化にフォーカス
 Java EE 8
– クラウド...
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.5
Java EE 7 へ含まれる予定の JSR 一覧
Connector
1.6
JPA 2.1 JTA ...
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.6
Top Ten Features in Java EE 7
1. WebSocket client/se...
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.7
JSR 356:
JavaTM API for WebSocket
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.8
WebSocket の背景 – Server Push
Polling
Long Polling
Com...
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.9
WebSocket とは
TCP ベース
双方向・全二重通信
RFC 6455
JavaScript A...
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.10
ブラウザの対応状況
http://caniuse.com/websockets
現バージョンの対応状況
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.11
WebSocket の基本概念
コネクションの確立
双方向のメッセージ送信
コネクションの切断
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.12
コネクションの確立
HandShake リクエスト
HandShake レスポンス
クライアント サーバ
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.13
HandShake リクエスト (RFC 6455で定義)
サーバクライアント
GET /mychat...
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.14
HandShake レスポンス (RFC 6455で定義)
サーバクライアント
HTTP/1.1 10...
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.15
コネクションの確立
クライアント サーバ
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.16
WebSocket のライフサイクル
クライアント サーバ
Open Open
Close
Messa...
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.17
WebSocket API
www.w3.org/TR/websockets/
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.18
Java API for WebSocket (JSR-356)
http://jcp.org/en/...
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.19
参照実装
http://java.net/projects/tyrus
最新の GlassFish v...
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.20
アノテーション レベル 内容
@ServerEndpoint クラス WebSocket のエンドポイ...
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.21
WebSocket アプリケーション・ライフサイクル
@ServerEndpoint("/hello"...
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.22
import javax.net.websocket.annotations.*;
@ServerEn...
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.23
Twitter
Singleton
サンプル・アプリケーションの構成 (多対1)
Remote
End...
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.24
@ServerEndpoint(value= "/twitter")
public class Twi...
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.25
@Startup @Singleton
public class TwitterClientSingl...
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.26
public void onStatus(Status status) {
User user = s...
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.27
データ送信コード (ノン・ブロッキング
for (Session peer : peers) {
Fu...
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.28
Java EE 7 Themes
 Batch
 Concurrency
 Simplified...
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.29
Java EE 7 : 2013年 春頃
提供開始予定
テーマ:HTML5 と開発生産性の向上
Jav...
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.30
Java EE 7 より
Web Profileに追加
• JAX-RS
• WebSocket
• ...
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.31
Concurrency Utilities for
EE
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.32
Application Servers
Java SE
Web/EJB コンテナ
EJB JSP
Se...
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.33
Application Servers
Java SE
Web/EJB コンテナ
EJB JSP
Se...
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.34
タスクを実装
A implements Runnable
B implements Callable
...
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.35 Copyright © 2013, Oracle and/or its affiliates. All...
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.36 Copyright © 2013, Oracle and/or its affiliates. All...
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.37
サーバ側の設定例2
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.38 Copyright © 2013, Oracle and/or its affiliates. All...
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.39
非同期タスクのスケジューリング
(ManagedScheduledExecutorService
の利...
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.40 Copyright © 2013, Oracle and/or its affiliates. All...
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.41
タスクを実装
A implements Runnable
B implements Callable
...
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.42
サーバ側の設定例2
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.43 Copyright © 2013, Oracle and/or its affiliates. All...
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.44 Copyright © 2013, Oracle and/or its affiliates. All...
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.45 Copyright © 2013, Oracle and/or its affiliates. All...
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.46
タスクのライフサイクル管理・監視
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.47
タスクのライフサイクル
taskSubmitted Submitted taskStarting
ta...
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.48 Copyright © 2013, Oracle and/or its affiliates. All...
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.49 Copyright © 2013, Oracle and/or its affiliates. All...
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.50
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.51
Upcoming SlideShare
Loading in...5
×

Java EE 7 Detail Okinawa

424

Published on

Published in: Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
424
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
5
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Transcript of "Java EE 7 Detail Okinawa"

  1. 1. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.1 Yoshio Terada Java Evangelist http://yoshio3.com, Twitter : @yoshioterada
  2. 2. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.2 以下の事項は、弊社の一般的な製品の方向性に関する概要を説明するもので す。また、情報提供を唯一の目的とするものであり、いかなる契約にも組み 込むことはできません。以下の事項は、マテリアルやコード、機能を提供す ることをコミットメント(確約)するものではないため、購買決定を行う際 の判断材料になさらないで下さい。オラクル製品に関して記載されている機 能の開発、リリースおよび時期については、弊社の裁量により決定されます 。 Oracleは、米国オラクルコーポレーション及びその子会社、関連会社の米国及びその他の国における登録商 標です。文中の社名、商品名等は各社の商標または登録商標である場合があります。
  3. 3. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.3 Make the Future Java (Java の未来を創造)
  4. 4. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.4  Java EE 7 – HTML 5 とシンプル化にフォーカス  Java EE 8 – クラウド対応とモジュール化対応への 継続的な投資 Java EE の今後 Java EE Hasan Rizvi
  5. 5. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.5 Java EE 7 へ含まれる予定の JSR 一覧 Connector 1.6 JPA 2.1 JTA 1.2 JMS 2.0 Managed Bean 1.0 EJB 3.2 Common Annotations 1.1 Interceptors 1.1 CDI 1.1 Portable Extensions Servlet 3.1 JSP 2.2 JSF 2.2 JAX-RS 2.0 EL 3.0 BeanValidation1.1 Concurrency Utilities for EE (JSR-236) Batch Application (JSR-352) Java API for JSON (JSR-353) Java API for WebSocket (JSR-356) 新規追加 大幅な更新 通常の更新
  6. 6. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.6 Top Ten Features in Java EE 7 1. WebSocket client/server endpoints 2. Batch Applications 3. JSON Processing 4. Concurrency Utilities 5. Simplified JMS API 6. @Transactional and @TransactionScoped 7. JAX-RS Client API 8. Default Resources 9. More annotated POJOs 10. Faces Flow
  7. 7. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.7 JSR 356: JavaTM API for WebSocket
  8. 8. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.8 WebSocket の背景 – Server Push Polling Long Polling Comet/Ajax 複雑・非効率・無駄
  9. 9. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.9 WebSocket とは TCP ベース 双方向・全二重通信 RFC 6455 JavaScript API by W3C
  10. 10. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.10 ブラウザの対応状況 http://caniuse.com/websockets 現バージョンの対応状況
  11. 11. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.11 WebSocket の基本概念 コネクションの確立 双方向のメッセージ送信 コネクションの切断
  12. 12. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.12 コネクションの確立 HandShake リクエスト HandShake レスポンス クライアント サーバ
  13. 13. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.13 HandShake リクエスト (RFC 6455で定義) サーバクライアント GET /mychat HTTP/1.1 Host: server.example.com Upgrade: websocket Connection: Upgrade Sec-WebSocket-Key: x3JJHMbDL1EzLkh9GBhXDw== Sec-WebSocket-Protocol: megachat, chat Sec-WebSocket-Extensions : compress, mux Sec-WebSocket-Version: 13 Origin: http://example.com
  14. 14. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.14 HandShake レスポンス (RFC 6455で定義) サーバクライアント HTTP/1.1 101 Switching Protocols Upgrade: websocket Connection: Upgrade Sec-WebSocket-Accept: HSmrc0sMlYUkAGmm5OPpG2HaGWk= Sec-WebSocket-Protocol: chat Sec-WebSocket-Extensions: compress, mux
  15. 15. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.15 コネクションの確立 クライアント サーバ
  16. 16. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.16 WebSocket のライフサイクル クライアント サーバ Open Open Close MessageMessageMessage MessageMessageMessage Error 接続確立 接続切断
  17. 17. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.17 WebSocket API www.w3.org/TR/websockets/
  18. 18. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.18 Java API for WebSocket (JSR-356) http://jcp.org/en/jsr/detail?id=356 http://java.net/projects/websocket-spec 仕様 ステータス: Early Draft
  19. 19. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.19 参照実装 http://java.net/projects/tyrus 最新の GlassFish v4 開発ビルドにバンドル済
  20. 20. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.20 アノテーション レベル 内容 @ServerEndpoint クラス WebSocket のエンドポイントを示す @OnOpen メソッド 接続確立時に呼び出すメソッドを指定 @OnClose メソッド 接続切断時に呼び出すメソッドを指定 @OnMessage メソッド メッセージを受信した時に呼び出すメソッドを 指定 @PathParam メソッド パラメータ エンドポイントのURI 引数に指定されたパラ メータを取得する際に仕様 @OnError メソッド エラー発生時に呼び出すメソッドを指定 WebSocket アノテーション
  21. 21. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.21 WebSocket アプリケーション・ライフサイクル @ServerEndpoint("/hello") var wsUri = "ws://HOST/foo/hello"; var websocket = new WebSocket(wsUri); @OnOpen websocket.onopen = function(evt) { onOpen(evt) }; websocket.onmessage = function(evt) { onMessage(evt) }; @OnMessage websocket.onerror = function(evt) { onError(evt) }; @OnError websocket.onclose = function(evt) { onClose (evt) }; @OnClose JavaScript WebSocket API
  22. 22. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.22 import javax.net.websocket.annotations.*; @ServerEndpoint("/hello") public class HelloBean { @OnMessage public void sayHello(Session session, String msg) { session.getRemote().sendString(“Hello” + msg); } } HelloWorld アプリケーション (1対1)
  23. 23. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.23 Twitter Singleton サンプル・アプリケーションの構成 (多対1) Remote Endpoint RE RE RE Session Session Session WebSocket Endpoint Twitter4J
  24. 24. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.24 @ServerEndpoint(value= "/twitter") public class TwitterWebSocket { @OnOpen public void initOpen(Session session) { TwitterClientSingleton.peers.add(session); } @OnClose public void closeWebSocket(Session session){ TwitterClientSingleton.peers.remove(session); } } Twitter Streaming アプリ
  25. 25. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.25 @Startup @Singleton public class TwitterClientSingleton extends StatusAdapter { public static Set<Session> peers = null; static { peers = Collections.synchronizedSet(new HashSet()); } ...続く Twitter Streaming アプリ Session Session Session Session クライアントの参照情報を保持 RE RE RE RE ・・・・・・
  26. 26. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.26 public void onStatus(Status status) { User user = status.getUser(); String resStr = "@" +user.getScreenName() + " : " + status.getText() ; try { for (Session peer : peers) { peer.getBasicRemote().sendText(resStr); } } catch (IOException ioe) { ioe.printStackTrace(); } } データ送信コード (ブロッキング) シーケンシャルに配信を実施 (大量のデータで待ち) 全ピア(RE)に対して配信 Session Session Session Session RE RE RE RE
  27. 27. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.27 データ送信コード (ノン・ブロッキング for (Session peer : peers) { Future<Void> futureSend = peer.getAsyncRemote().sendText (resStr); while (!futureSend.isDone()) { // wait here ? } SendResult status = futureSendResult.get(); if (status.isOK()) { // ok } else { // whoops, send failed. }}
  28. 28. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.28 Java EE 7 Themes  Batch  Concurrency  Simplified JMS  More annotated POJOs  Less boilerplate code  Cohesive integrated platform DEVELOPER PRODUCTIVITY  WebSockets  JSON  Servlet 3.1 NIO  REST MEETING ENTERPRISE DEMANDS Java EE 7
  29. 29. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.29 Java EE 7 : 2013年 春頃 提供開始予定 テーマ:HTML5 と開発生産性の向上 Java EE 7 SDK の提供開始
  30. 30. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.30 Java EE 7 より Web Profileに追加 • JAX-RS • WebSocket • JSON-P
  31. 31. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.31 Concurrency Utilities for EE
  32. 32. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.32 Application Servers Java SE Web/EJB コンテナ EJB JSP Servlet Runnable Callable Java EE 関連機能 (JAX-RS,JavaMail, CDI など) Java EE 環境で禁止されていた Thread 生成
  33. 33. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.33 Application Servers Java SE Web/EJB コンテナ EJB JSP Servlet Runnable Callable Java EE とConcurrencyのアーキテクチャ Java EE 関連機能 (JAX-RS,JavaMail, CDI など) ManagedExecutor Service ManagedScheduledExecutorService ContextService ManagedThreadFactory Concurrency Utilities for EE
  34. 34. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.34 タスクを実装 A implements Runnable B implements Callable 非同期タスクを実装 リソース・インジェクショ ン でサーバ管理スレッドを利 用 サーバ側で設定を実施 デフォルト設定も利用可 1 2 EE環境の非同期タスクの実装手順 3
  35. 35. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.35 Copyright © 2013, Oracle and/or its affiliates. All rights reserved.35 public class MyRunnableTask implements Runnable { @Override public void run() { try { Thread.sleep(10000); //何らかの処理 } catch (InterruptedException ex) { logger.log(Level.SEVERE, null, ex); } } } Runnable のタスクを作成1
  36. 36. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.36 Copyright © 2013, Oracle and/or its affiliates. All rights reserved.36 Callable のタスクを作成 ● call() は返り値を持つ事が可能 ● チェック例外のスローが可能 1 public class MyCallableTask implements Callable<String> { @Override public String call() throws Exception { return “Hello World”; } }
  37. 37. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.37 サーバ側の設定例2
  38. 38. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.38 Copyright © 2013, Oracle and/or its affiliates. All rights reserved.38 @Stateless public class MyManagedExecutorService { @Resource(name = "concurrent/DefaultManagedExecutorService") ManagedExecutorService managedExecsvc; public void execExecutorService() { MyRunnableTask task = new MyRunnableTask(); managedExecsvc.submit(task); MyCallableTask singleTask = new MyCallableTask("Foo Bar"); Future<String> singleFuture = managedExecsvc.submit(singleTask);} 非同期タスクを実行する EJB3
  39. 39. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.39 非同期タスクのスケジューリング (ManagedScheduledExecutorService の利用例)
  40. 40. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.40 Copyright © 2013, Oracle and/or its affiliates. All rights reserved.40
  41. 41. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.41 タスクを実装 A implements Runnable B implements Callable 非同期タスクを実装 リソース・インジェクショ ン でサーバ管理スレッドを利 用 サーバ側で設定を実施 デフォルト設定も利用可 1 2 EE環境の非同期タスクの実装手順 3
  42. 42. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.42 サーバ側の設定例2
  43. 43. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.43 Copyright © 2013, Oracle and/or its affiliates. All rights reserved.43 @Stateless public class MyManagedScheduledExecutorService{ @Resource(name = "concurrent/ DefaultManagedScheduledExecutorService") ManagedScheduledExecutorService managedScheduledExecsvc; public void execScheduledExecutorService() { MyRunnableTask task = new MyRunnableTask(); managedScheduledExecsvc.schedule( task, 60L, TimeUnit.SECONDS); } 非同期タスクを実行する EJB3
  44. 44. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.44 Copyright © 2013, Oracle and/or its affiliates. All rights reserved.44 @Stateless public class MyManagedScheduledExecutorService{ @Resource(name = "concurrent/ DefaultManagedScheduledExecutorService") ManagedScheduledExecutorService managedScheduledExecsvc; public void execScheduledExecutorService() { MyRunnableTask task = new MyRunnableTask(); managedScheduledExecsvc.schedule( task, new MyTrigger(new Date(), 10, 1000) } 非同期タスクを実行する EJB3
  45. 45. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.45 Copyright © 2013, Oracle and/or its affiliates. All rights reserved.45 import javax.enterprise.concurrent.Trigger; public class MyTrigger implements Trigger { @Override public Date getNextRunTime(LastExecution le, Date date){ } @Override public boolean skipRun(LastExecution le, Date date) { } }
  46. 46. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.46 タスクのライフサイクル管理・監視
  47. 47. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.47 タスクのライフサイクル taskSubmitted Submitted taskStarting taskAborted Started taskDone Done submit() の実行 submit 成功 キャンセル・中 止 タスクの 実行準備 タスク実行 キャンセル・中 止 タスク実行完了
  48. 48. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.48 Copyright © 2013, Oracle and/or its affiliates. All rights reserved.48 public class MyManagedTaskListener implements ManagedTaskListener { public void taskSubmitted(Future<?> future, ManagedExecutorService mes, Object o) { } public void taskStarting(Future<?> future, ManagedExecutorService mes, Object o) { } public void taskAborted(Future<?> future, ManagedExecutorService mes, Object o, Throwable thrwbl){ } public void taskDone(Future<?> future, ManagedExecutorService mes, Object o, Throwable thrwbl){ } }
  49. 49. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.49 Copyright © 2013, Oracle and/or its affiliates. All rights reserved.49 @Resource(name = "concurrent/ MyManagedExecutorService") ManagedExecutorService manageExecsvc; public void invokeMyTaskListener() { MyRunnableTask task = new MyRunnableTask(); MyManagedTaskListener listener = new MyManagedTaskListener(); Runnable taskWithListener = ManagedExecutors.managedTask(task, listener); manageExecsvc.execute(taskWithListener); }
  50. 50. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.50
  51. 51. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.51
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×