Introduction to Jetty Jetty  の紹介
Jetty History Jetty  の歴史 founded by Greg Wilkins in 1995   1995 年に Greg Wilkins が設立 one of first Java applications   最初の Java のアプリケーションの 1 つ constant set of core developers   恒久的にコアな開発者の対応 Version Home Java HTTP Servlet JSP Status 8.x Eclipse/Codehaus 1.6 HTTP/1.1 RFC2616 3.0 2.2 Experimental 7.x Eclipse/Codehaus 1.5 HTTP/1.1 RFC2616 2.5 2.1 Stabilising 6.x Codehaus 1.4-1.5 HTTP/1.1 RFC2616 2.5 2.0/2.1 Stable 5.x Sourceforge 1.2-1.5 HTTP/1.1 RFC2616 2.4 2.0 Mature 4.x Sourceforge 1.2 HTTP/1.1 RFC2616 2.3 1.2 Ancient 3.x Sourceforge 1.2 HTTP/1.1 RFC2616 2.2 1.1 Fossilised 2.x Mortbay 1.1 HTTP/1.0 RFC1945 2.1 1.0 Legendary 1.x Mortbay 1.0 HTTP/1.0 RFC1945 Mythical
What is Jetty Jetty  とは何か ? HTTP server & servlet container   HTTP サーバーとサーブレットのコンテナー Application server (High tide distribution)   アプリケーションサーバー(大量に分布) Cometd server   Cometd サーバー OSGi web service   OSGi 準拠の Web サービス Async HTTP service (client and server)   非同期 HTTP サービス(クライアントとサーバー)
Jetty is a NOT a Application Server Jetty  はアプリケーションサーバーではありません JVM Application Application Server
Jetty is Component (s) Jetty  はコンポーネントです JVM Application Jetty://
Jetty can power Application Server Jetty  はアプリケーションサーバー のみ として も 稼働できます JVM Application Jetty:// Application Container
Jetty Inside Jetty  内部 Millions of installations   何百万人がインストール Powering hundreds of thousands of websites   数十万の Web サイトで提供 From  constrained environments:   制限がある環境から: Mobile phones (i-jetty), set top boxes To middleware:   ミドルウェアまで: Applications: GWT, ActiveMQ, Nexus Application Servers: Jetty-Hightide, Geronimo, Jonas, Jboss, SybaseEA OSGi Infrastructures: Eclipse Equinox, Apache Felix, PAX Cloud: Intalio|Cloud, Google AppEngine, Gigaspaces To massively parallel environments:  大量の並列環境まで: Hadoop (holds record for sorting terrabyte of data) Jetty is such a good component it‘s generally invisible   Jetty は一般的に目に見えない良いコンポーネントです。
Jetty Powered
Jetty Powered
Features 特徴 “ It just works!”   稼働します! Feature  特徴 Benefit  利点 Compostable   コンポスト可能 Modular design   モジュール設計 Embeddable   埋込可能 Small footprint   小さなフットプリント Customizable   カスタマイズ可能 Extend or replace defaults   デフォルトの拡張・置換 JavaEE Optional modules   オプションモジュール Specifications   仕様 HTTP and Servlet compliance   HTTP とサーブレットのコンプライアンス Scalable   拡張可能 nio & asynchronous servlets   NIO (ノンブロッキング  I/O )と非同期サーブレット Cometd Java reference implementation   Java のリファレンスを実装 Libraries   ライブラリー Client, server, utility, testing Tool support   ツールサポート Maven, ant, eclipse integration Innovative   革新的 We like new use-cases :)   新規ユースケースを希望
Small footprint 小さなフットプリント Jetty client/server on phones   携帯電話上での Jetty  クライアント・サーバー i-jetty Google Android  me-jetty J2ME CLDC
Feature: scalability 特徴:拡張性 Cloud   クラウド Used in hadoop cluster that holds record for sorting a TB   ソートしたテラバイトのデータを保持する Hadoop のクラスタリングで使用 Footprint   フットプリント As important in cloud as in mobile   モバイル・クラウドで同様に重要 Asynchronous  非同期 Not limited by thread pool   スレッドプールに制限なし Modularity   モジュール方式 Use only the bits you need   必要最小限のみ使用 Replace/Customize parts   一部分を置換 / カスタマイズ化
Feature: asynchronous servlets 特徴:非同期サーブレット Long poll (aka comet, hanging GET)   長期ポーリング(別名: Comet 、 Get 制御) Threadless wait   スレッドレスで待機が可能 Jetty native Continuations also Servlet Specification 3.0   Jetty のネイティブな延長が、サーブレット 3.0 の仕様 resume suspend servlet GET Response
Feature: Modularity 特徴:モジュール
Feature: Embedding 特徴:埋め込み choose your jetty modules   Jetty のモジュールを選択 call jetty api   Jetty の API を呼出 jetty-all.jar for convenience   便利な jetty-all.jar Server server = new Server(8080); ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); context.setContextPath("/"); server.setHandler(context); context.addServlet(new ServletHolder(new HelloServlet()),"/*"); server.start(); server.join(); java -cp servlet.jar:jetty-all.jar MyApplication
Feature: Flexibility 特徴:柔軟性 Stand-alone Jetty:   スタンドアローン版の Jetty : java -jar start.jar [config files] Jetty Runner:   Jetty 起動: java -jar jetty-runner.jar mycoolapp.war Embedded Jetty   埋め込んだ Jetty Server jettyServer = new Server(); Connector connector = new SelectChannelConnector(); connector.setPort(8080); jettyServer.setConnectors (new Connector[]{connector}); jettyServer.start(); Jetty maven plugin:   Jetty の Maven プラグイン mvn jetty:[run|run-war|run-exploded] OSGi Start your container, drop in jetty bundles   コンテナー開始、 Jetty のバンドルを取込
Feature: JavaEE Modules 特徴: Java EE  モジュール Use as needed   必要な時に使用 JNDI resources   JNDI リソース DataSources, JMS etc   データソース、 JMS 等 JAAS ( JavaTM Authentication and Authorization Service ) various LoginModule implementations   様々なログインモジュール実装 XA transactions   分散トランザクション Pluggable   プラグイン Annotations   アノテーション Jetty Hightide distribution   Jetty が大量の分布 Atomikos, Derby, options pre-enabled   オプションとして事前対応
Libraries and Utilities ライブラリーとユーティリティー HTTP async client   HTTP 非同期クライアント Built on core Jetty   コアな Jetty 上に構築 Cometd java client   Cometd の Java クライアント Uses HTTP async client   HTTP 非同期クライアントを使用 Simple servlet unit testing   簡単なサーブレットのユニットテスト Useful handlers (eg MovedContextHandler)   有益なハンドラー Useful servlets (eg ProxyServlet)   有益なサーブレット Useful filters (eg QosFilter)   有益なフィルター
Jetty Demos Jetty  デモ Deploying Web Applications   Web アプリケーションをデプロイ Maven Jetty Plug-in   Maven の Jetty プラグイン Embedding Jetty   埋め込んだ Jetty start.jar   start.jar を呼出
Why Asynchronous? 何故、非同期であるのか ?
Why Async HTTP/Servlets? 何故、非同期 HTTP/ サーブレットであるのか ? For Async IO ???   非同期の I/O とは‽ To avoid blocking while:   ブロッキングを回避: reading request   リクエストを読込 writing response   レスポンスを書込 Requests mostly small   リクエストはほとんど小さい Single packet – no blocking   小さいパケットーブロッキングなし Multiple packets hard to handle in application   マルチのパケットはアプリケーションでの制御は困難 Partial XML elements or UTF-8 characters???   部分的な XML の要素、または UTF-8 の文字コード ??? Responses can be large   レスポンスは大きい But difficult to handle in the application   アプリケーションでの制御は困難 What do do if application does a partial write? Loop and try again! アプリケーションが部分的な書込でよいか、再度試して下さい! Async Jetty is NOT about async IO!   非同期の Jetty は非同期の I/O ではありません
HTTP Servlets frequently wait for:   HTTP サーブレットが頻繁に待機: Resources (eg JDBC connection)   リソース(例) JDBC 接続) Events (eg Chat)   イベント(例)チャット) Responses (eg webservices)   レスポンス(例) Web サービス) HTTP Clients wait for   HTTP クライアントが以下を待機 Connections   接続 Responses   レスポンス Why Async HTTP/Servlets? 何故、非同期 HTTP/ サーブレットであるのか ?
Async REST WS Demo 非同期 REST Web サービスのデモ
Waiting for WS Responses Web サービスのレスポンスの待機 Blocking WS Asynchronous WS Web サービスをブロック    非同期の Web サービス
Asynchronous WS –  Async client! 非同期の Web サービス – 非同期のクライアント! Webapp doGet doGet startAsync WS call dispatch Server
Waiting for Resources. eg JDBC リソースへの待機 例) JDBC Slow resource may cause thread starvation:   リソース不足はスレッドの停止を引き起こすかもしれません: 1000 request / sec   1 秒間に 1000 リクエスト 500 threads in server pool   サーバーに 500 スレッド 10% requests use JDBC connection (25 in pool)   10% のリクエストが JDBC 接続を使用 If DB becomes blocked:   データベースがブロックされた場合: 5 seconds to consume ALL 500 threads!   5 秒間で全ての 500 スレッドを消費 If DB becomes slow (500ms):   データベースが遅くなった場合: 10 seconds to consume ALL 500 threads!   10 秒間で全ての 500 スレッドを消費 The 90% of non DB requests blocked by 10% !!!   データベースへの接続がないリクエストの 90% が 10% でブロック
QoSFilter   サンプルソースコード try  { if (request.getDispatcherType()!=DispatcherType.ASYNC) { accepted= _passes.tryAcquire (_waitMs,TimeUnit.MILLISECONDS); if (!accepted){ request.startAsync() ; int priority = getPriority(request); _queue[priority].add(request); return; } } else { _passes.acquire(); accepted=true; } if(accepted) chain.doFilter(request,response); } finally  { if (accepted) { for (int p=_queue.length;p-->0;) { ServletRequest req=_queue[p].poll(); if (req!=null) { req.getAsyncContext.dispatch() ; break; } } _passes.release(); } }
Waiting for Events イベントへの待機 Ajax Comet aka Ajax Push, Long Polling, Forever Frame New class of web-2.0 applications   Web2.0 対応アプリケーションの新規クラス Ajax Chat (hello world of comet)   Ajax チャット( Comet のハローワールド) Live stock prices   生で株価 Gaming   ゲーム Collaborative editing   コラボレーションして編集 Social Networking   ソーシャルネットワーキング
Why Async Servlets? 何故、非同期のサーブレットであるのか ? Because there are REAL use-cases:  現実的なユースケースは以下の通りです: Waiting for resources   リソースの待機 Waiting for events   イベントの待機 Waiting for responses   レスポンスの待機 Jetty provides:   Jetty は以下を提供します: Async HTTP Server   非同期の HTTP サーバー   can suspend/resume requests   リクエストの停止 / 再開 Async HTTP Client    非同期の HTTP クライアント callbacks on status, headers and content   ステータス、ヘッダーと内容をコールバック
Introduction to Cometd Cometd  の紹介に続きます

Jetty Introduction

  • 1.
    Introduction to JettyJetty の紹介
  • 2.
    Jetty History Jetty の歴史 founded by Greg Wilkins in 1995   1995 年に Greg Wilkins が設立 one of first Java applications   最初の Java のアプリケーションの 1 つ constant set of core developers   恒久的にコアな開発者の対応 Version Home Java HTTP Servlet JSP Status 8.x Eclipse/Codehaus 1.6 HTTP/1.1 RFC2616 3.0 2.2 Experimental 7.x Eclipse/Codehaus 1.5 HTTP/1.1 RFC2616 2.5 2.1 Stabilising 6.x Codehaus 1.4-1.5 HTTP/1.1 RFC2616 2.5 2.0/2.1 Stable 5.x Sourceforge 1.2-1.5 HTTP/1.1 RFC2616 2.4 2.0 Mature 4.x Sourceforge 1.2 HTTP/1.1 RFC2616 2.3 1.2 Ancient 3.x Sourceforge 1.2 HTTP/1.1 RFC2616 2.2 1.1 Fossilised 2.x Mortbay 1.1 HTTP/1.0 RFC1945 2.1 1.0 Legendary 1.x Mortbay 1.0 HTTP/1.0 RFC1945 Mythical
  • 3.
    What is JettyJetty とは何か ? HTTP server & servlet container   HTTP サーバーとサーブレットのコンテナー Application server (High tide distribution)   アプリケーションサーバー(大量に分布) Cometd server   Cometd サーバー OSGi web service   OSGi 準拠の Web サービス Async HTTP service (client and server)   非同期 HTTP サービス(クライアントとサーバー)
  • 4.
    Jetty is aNOT a Application Server Jetty はアプリケーションサーバーではありません JVM Application Application Server
  • 5.
    Jetty is Component(s) Jetty はコンポーネントです JVM Application Jetty://
  • 6.
    Jetty can powerApplication Server Jetty はアプリケーションサーバー のみ として も 稼働できます JVM Application Jetty:// Application Container
  • 7.
    Jetty Inside Jetty 内部 Millions of installations   何百万人がインストール Powering hundreds of thousands of websites   数十万の Web サイトで提供 From constrained environments:   制限がある環境から: Mobile phones (i-jetty), set top boxes To middleware:   ミドルウェアまで: Applications: GWT, ActiveMQ, Nexus Application Servers: Jetty-Hightide, Geronimo, Jonas, Jboss, SybaseEA OSGi Infrastructures: Eclipse Equinox, Apache Felix, PAX Cloud: Intalio|Cloud, Google AppEngine, Gigaspaces To massively parallel environments:  大量の並列環境まで: Hadoop (holds record for sorting terrabyte of data) Jetty is such a good component it‘s generally invisible   Jetty は一般的に目に見えない良いコンポーネントです。
  • 8.
  • 9.
  • 10.
    Features 特徴 “It just works!”   稼働します! Feature  特徴 Benefit  利点 Compostable   コンポスト可能 Modular design   モジュール設計 Embeddable   埋込可能 Small footprint   小さなフットプリント Customizable   カスタマイズ可能 Extend or replace defaults   デフォルトの拡張・置換 JavaEE Optional modules   オプションモジュール Specifications   仕様 HTTP and Servlet compliance   HTTP とサーブレットのコンプライアンス Scalable   拡張可能 nio & asynchronous servlets   NIO (ノンブロッキング I/O )と非同期サーブレット Cometd Java reference implementation   Java のリファレンスを実装 Libraries   ライブラリー Client, server, utility, testing Tool support   ツールサポート Maven, ant, eclipse integration Innovative   革新的 We like new use-cases :)   新規ユースケースを希望
  • 11.
    Small footprint 小さなフットプリントJetty client/server on phones   携帯電話上での Jetty クライアント・サーバー i-jetty Google Android me-jetty J2ME CLDC
  • 12.
    Feature: scalability 特徴:拡張性Cloud   クラウド Used in hadoop cluster that holds record for sorting a TB   ソートしたテラバイトのデータを保持する Hadoop のクラスタリングで使用 Footprint   フットプリント As important in cloud as in mobile   モバイル・クラウドで同様に重要 Asynchronous  非同期 Not limited by thread pool   スレッドプールに制限なし Modularity   モジュール方式 Use only the bits you need   必要最小限のみ使用 Replace/Customize parts   一部分を置換 / カスタマイズ化
  • 13.
    Feature: asynchronous servlets特徴:非同期サーブレット Long poll (aka comet, hanging GET)   長期ポーリング(別名: Comet 、 Get 制御) Threadless wait   スレッドレスで待機が可能 Jetty native Continuations also Servlet Specification 3.0   Jetty のネイティブな延長が、サーブレット 3.0 の仕様 resume suspend servlet GET Response
  • 14.
  • 15.
    Feature: Embedding 特徴:埋め込みchoose your jetty modules   Jetty のモジュールを選択 call jetty api   Jetty の API を呼出 jetty-all.jar for convenience   便利な jetty-all.jar Server server = new Server(8080); ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); context.setContextPath("/"); server.setHandler(context); context.addServlet(new ServletHolder(new HelloServlet()),"/*"); server.start(); server.join(); java -cp servlet.jar:jetty-all.jar MyApplication
  • 16.
    Feature: Flexibility 特徴:柔軟性Stand-alone Jetty:   スタンドアローン版の Jetty : java -jar start.jar [config files] Jetty Runner:   Jetty 起動: java -jar jetty-runner.jar mycoolapp.war Embedded Jetty   埋め込んだ Jetty Server jettyServer = new Server(); Connector connector = new SelectChannelConnector(); connector.setPort(8080); jettyServer.setConnectors (new Connector[]{connector}); jettyServer.start(); Jetty maven plugin:   Jetty の Maven プラグイン mvn jetty:[run|run-war|run-exploded] OSGi Start your container, drop in jetty bundles   コンテナー開始、 Jetty のバンドルを取込
  • 17.
    Feature: JavaEE Modules特徴: Java EE モジュール Use as needed   必要な時に使用 JNDI resources   JNDI リソース DataSources, JMS etc   データソース、 JMS 等 JAAS ( JavaTM Authentication and Authorization Service ) various LoginModule implementations   様々なログインモジュール実装 XA transactions   分散トランザクション Pluggable   プラグイン Annotations   アノテーション Jetty Hightide distribution   Jetty が大量の分布 Atomikos, Derby, options pre-enabled   オプションとして事前対応
  • 18.
    Libraries and Utilitiesライブラリーとユーティリティー HTTP async client   HTTP 非同期クライアント Built on core Jetty   コアな Jetty 上に構築 Cometd java client   Cometd の Java クライアント Uses HTTP async client   HTTP 非同期クライアントを使用 Simple servlet unit testing   簡単なサーブレットのユニットテスト Useful handlers (eg MovedContextHandler)   有益なハンドラー Useful servlets (eg ProxyServlet)   有益なサーブレット Useful filters (eg QosFilter)   有益なフィルター
  • 19.
    Jetty Demos Jetty デモ Deploying Web Applications   Web アプリケーションをデプロイ Maven Jetty Plug-in   Maven の Jetty プラグイン Embedding Jetty   埋め込んだ Jetty start.jar   start.jar を呼出
  • 20.
  • 21.
    Why Async HTTP/Servlets?何故、非同期 HTTP/ サーブレットであるのか ? For Async IO ???   非同期の I/O とは‽ To avoid blocking while:   ブロッキングを回避: reading request   リクエストを読込 writing response   レスポンスを書込 Requests mostly small   リクエストはほとんど小さい Single packet – no blocking   小さいパケットーブロッキングなし Multiple packets hard to handle in application   マルチのパケットはアプリケーションでの制御は困難 Partial XML elements or UTF-8 characters???   部分的な XML の要素、または UTF-8 の文字コード ??? Responses can be large   レスポンスは大きい But difficult to handle in the application   アプリケーションでの制御は困難 What do do if application does a partial write? Loop and try again! アプリケーションが部分的な書込でよいか、再度試して下さい! Async Jetty is NOT about async IO!   非同期の Jetty は非同期の I/O ではありません
  • 22.
    HTTP Servlets frequentlywait for:   HTTP サーブレットが頻繁に待機: Resources (eg JDBC connection)   リソース(例) JDBC 接続) Events (eg Chat)   イベント(例)チャット) Responses (eg webservices)   レスポンス(例) Web サービス) HTTP Clients wait for   HTTP クライアントが以下を待機 Connections   接続 Responses   レスポンス Why Async HTTP/Servlets? 何故、非同期 HTTP/ サーブレットであるのか ?
  • 23.
    Async REST WSDemo 非同期 REST Web サービスのデモ
  • 24.
    Waiting for WSResponses Web サービスのレスポンスの待機 Blocking WS Asynchronous WS Web サービスをブロック    非同期の Web サービス
  • 25.
    Asynchronous WS – Async client! 非同期の Web サービス – 非同期のクライアント! Webapp doGet doGet startAsync WS call dispatch Server
  • 26.
    Waiting for Resources.eg JDBC リソースへの待機 例) JDBC Slow resource may cause thread starvation:   リソース不足はスレッドの停止を引き起こすかもしれません: 1000 request / sec   1 秒間に 1000 リクエスト 500 threads in server pool   サーバーに 500 スレッド 10% requests use JDBC connection (25 in pool)   10% のリクエストが JDBC 接続を使用 If DB becomes blocked:   データベースがブロックされた場合: 5 seconds to consume ALL 500 threads!   5 秒間で全ての 500 スレッドを消費 If DB becomes slow (500ms):   データベースが遅くなった場合: 10 seconds to consume ALL 500 threads!   10 秒間で全ての 500 スレッドを消費 The 90% of non DB requests blocked by 10% !!!   データベースへの接続がないリクエストの 90% が 10% でブロック
  • 27.
    QoSFilter   サンプルソースコードtry { if (request.getDispatcherType()!=DispatcherType.ASYNC) { accepted= _passes.tryAcquire (_waitMs,TimeUnit.MILLISECONDS); if (!accepted){ request.startAsync() ; int priority = getPriority(request); _queue[priority].add(request); return; } } else { _passes.acquire(); accepted=true; } if(accepted) chain.doFilter(request,response); } finally { if (accepted) { for (int p=_queue.length;p-->0;) { ServletRequest req=_queue[p].poll(); if (req!=null) { req.getAsyncContext.dispatch() ; break; } } _passes.release(); } }
  • 28.
    Waiting for Eventsイベントへの待機 Ajax Comet aka Ajax Push, Long Polling, Forever Frame New class of web-2.0 applications   Web2.0 対応アプリケーションの新規クラス Ajax Chat (hello world of comet)   Ajax チャット( Comet のハローワールド) Live stock prices   生で株価 Gaming   ゲーム Collaborative editing   コラボレーションして編集 Social Networking   ソーシャルネットワーキング
  • 29.
    Why Async Servlets?何故、非同期のサーブレットであるのか ? Because there are REAL use-cases:  現実的なユースケースは以下の通りです: Waiting for resources   リソースの待機 Waiting for events   イベントの待機 Waiting for responses   レスポンスの待機 Jetty provides:   Jetty は以下を提供します: Async HTTP Server   非同期の HTTP サーバー can suspend/resume requests   リクエストの停止 / 再開 Async HTTP Client   非同期の HTTP クライアント callbacks on status, headers and content   ステータス、ヘッダーと内容をコールバック
  • 30.
    Introduction to CometdCometd の紹介に続きます

Editor's Notes

  • #8 + written 1997 for programming contest + provides an http server like Apache but in Java + also a servlet server like Tomcat but both combined + philosophy is to be small as possible and easily embeddable, not monolithic standalone but can also be run standalone. Mission is to do the servlet spec implementation in the best possible way. + few jar dependencies as possible: just + many previous versions, now rewritten for Jetty6 taking advantage of NIO, non-blocking IO and support for Continuations + other j2ee services like <resource-ref> and UserTransactions, JAAS etc developed as optional add-ons, generally referred to as JettyPlus + jetty is the webcontainer in a number of J2EE app servers, mostly currently using jetty5, moving on to jetty6. A bit of Jboss history, still available from mortbay servers. + the Jetty “hall of fame” page, as well as numerous cds, books etc