• Share
  • Email
  • Embed
  • Like
  • Private Content
Java EE7&Avatar
 

Java EE7&Avatar

on

  • 6,385 views

 

Statistics

Views

Total Views
6,385
Views on SlideShare
1,877
Embed Views
4,508

Actions

Likes
8
Downloads
53
Comments
0

10 Embeds 4,508

http://yoshio3.com 4378
http://cloud.feedly.com 42
https://twitter.com 37
http://act2012bl.wordpress.com 21
http://translate.googleusercontent.com 13
http://yoshio3.com.preview.shareboost.com 11
http://www.feedspot.com 2
http://reader.aol.com 2
http://webcache.googleusercontent.com 1
https://yoshio3.com 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • We are very excited to announce Java Enterprise Edition 7.We're committed to Java EE, not just by leading Java EE 7, but also in the products that Oracledelivers.This platform is a culmination of work by all of us, Oracle, our Java Partners and of course you, the Java communitySo without further ado, I’d like to invite Cameron Purdy, VP of Development, to tell us more about the platform.Congratulations Cameron (hand shake)
  • Important to know where we came fromWe heard from developers that we needed to focus more on them, and not just on new features. Beginning with Java EE 5, Java has focused on driving ease of use and consistency into the platform, and today we have a rich set of features designed to work together, which are expressed primarily as annotated Java Objects.What’s beyond Java EE 7? Well, I’m not telling… You’ll have to stick around for the technical keynote for more details.
  • TRANS TO INFOSYS VIDEO AFTER THIS SLIDEBut why does this matter?18 EE 6-compliant app serversStrategic to almost every major technology vendor, including OracleEE 6 adopted quickly, anticipate EE 7 standard to continue trendEE affects the way the world does business, and that’s why we’re so excitedBut it’s not just software vendors that bet their business on EE, there is an entire ecosystem around it.To hear more from one of our important Ecosystem members, let’s turn over to InfoSys
  • Thanks to Infosys for their Java EE support, so what will Java EE 7 entail? Need speaker notes hereProductivityHtml 5Enterprise demands
  • Need speaker notes here
  • Need speaker notes here
  • There are 3 major themes of Java EE 7:Delivering HTML5 dynamic, scalable applicationsReduce response time with low latency data exchange using WebSocketsSimplify data parsing for portable applications with standard JSON supportDeliver asynchronous, scalable, high performance RESTful Services and Async ServletsIncreasing developer productivity through simplification and new container servicesSimplify application architecture with a cohesive integrated platformIncrease efficiency with reduced boiler-plate code and broader use of annotationsEnhance application portability with standard RESTful web service client supportAnd meeting the additional demands of the enterprise by adding new enterprise technologies.Break down batch jobs into manageable chunks for uninterrupted OLTP performanceEasily define multithreaded concurrent tasks for improved scalabilityDeliver transactional applications with choice and flexibilityWe'll be exploring all of these aspects in more detail in the context of the new Java EE 7 APIs as we continue this presentation.
  • TRANS TO IBM VIDEO AFTER THIS SLIDETo hear more about the Batch JSR and their overall contribution to Java, let’s tune in for a message from IBM.
  • There are 3 major themes of Java EE 7:Delivering HTML5 dynamic, scalable applicationsReduce response time with low latency data exchange using WebSocketsSimplify data parsing for portable applications with standard JSON supportDeliver asynchronous, scalable, high performance RESTful Services and Async ServletsIncreasing developer productivity through simplification and new container servicesSimplify application architecture with a cohesive integrated platformIncrease efficiency with reduced boiler-plate code and broader use of annotationsEnhance application portability with standard RESTful web service client supportAnd meeting the additional demands of the enterprise by adding new enterprise technologies.Break down batch jobs into manageable chunks for uninterrupted OLTP performanceEasily define multithreaded concurrent tasks for improved scalabilityDeliver transactional applications with choice and flexibilityWe'll be exploring all of these aspects in more detail in the context of the new Java EE 7 APIs as we continue this presentation.
  • [licensing details may change before launch, need a final/accurate screen snapshot]Avatar is now available under the open source [MIT?] license! As of right now, you can go to avatar.java.net, download avatar, view code samples and documentation, and begin developing server-side javascript applications using the node programming model with avatar.js. In fact, we’d like for you to get involved with Project Avatar and create some innovative services and share what you’ve done so you can come up on stage for the next JavaOne![If screen snapshot is too busy/ugly, we can simplify to a few centered lines in large font like: Available NOW!avatar.java.net
  • This diagram shows some of the target items for Java EE 8. This is only a thought process at this time and everything is completely subject to discussion with the Java EE Expert Group. Nothing is committed at this time.JSON-B will provide a support for binding POJOs to JSON structure.JSR 107 will provide support for caching.Support for modular Java EE applications will be built upon Java SE modularity.Standards-based PaaS/Cloud will definitely be looked upon.Thin Server Architecture or HTML5++ will be looked upon.State Management, NoSQL, and several other options.
  • The annotation defines that the decorated method be called whenever a new client has connected to this endpoint. The container notifies the method after the connection has been established [WSC-21]. The decorated method can only have optional Session parameter and zero to n String parameters annotated with a @WebSocketPathSegment annotation as parameters. If the Session parameter is present, the implementation must pass in the newly created Session corresponding to the new connection [WSC-22]. If the method throws an error, the implementation must pass this error to the onError method of the endpoint together with the session.The annotation defines that the decorated method be called whenever a new client is about to be disconnected from this endpoint. The container notifies the method before the connection is brought down [WSC-25]. The decorated method can only have optional Session parameter and zero to n String parameters annotated with a @WebSocketPathSegment annotation as parameters. If the Session parameter is present, the implementation must pass in the about-to-be ended Session corresponding to the connection [WSC-26]. If the method throws an error, the implementation must pass this error to the onError method of the endpoint together with the session.The annotation defines that the decorated method be called whenever an error is generated on any of the connections to this endpoint. The decorated method can only have optional Session parameter, mandatory Throwable parameter and zero to n String parameters annotated with a @WebSocketPathSegment annotation as parameters. If the Session parameter is present, the implementation must pass in the Session in which the error occurred to the connection [WSC-XX]. The container must pass the error as the Throwable parameter to this method.
  • The encoders parameter contains a (possibly empty) list of Java classes that are to act as encoder components for this endpoint. These classes must implement some form of the Encoder interface, and have public no-arg constructors and be visible within the classpath of the application that this websocket endpoint is part of. The implementation must attempt to encode application objects of matching parametrized type as the encoder when they are attempted to be sent using the RemoteEndpoint API.The decoders parameter contains a (possibly empty) list of Java classes that are to act as decoder components for this endpoint. These classes must implement some form of the Decoder interface, and have public no-arg constructors and be visible within the classpath of the application that this websocket endpoint is part of. The implementation must attempt to decode web socket messages using the first appropriate decoder in the list and pass the message in decoded object form to the websocket endpoint [WSC-17]. The implementation uses the willDecode() method on the decoder to determine if the Decoder will match the incoming message.
  • The allowed parameters are: Exactly one of any of the following choices if the method is handling text messages: String to receive the whole message Java primitive or class equivalent to receive the whole message converted to that type String and boolean pair to receive the message in parts Reader to receive the whole message as a blocking stream any object parameter for which the endpoint has a text decoder (Decoder.Text or Decoder.TextStream). if the method is handling binary messages: byte[] or ByteBuffer to receive the whole message byte[] and boolean pair, or ByteBuffer and boolean pair to receive the message in partsInputStream to receive the whole message as a blocking stream any object parameter for which the endpoint has a binary decoder (Decoder.Binary or Decoder.BinaryStream). if the method is handling pong messages:PongMessage for handling pong messagesand Zero to n String or Java primitive parameters annotated with the WebSocketPathParam annotation for server endpoints.and an optional Session parameterThe parameters may be listed in any order.The method may have a non-void return type, in which case the web socket runtime must interpret this as a web socket message to return to the peer. The allowed data types for this return type, other than void, are String, ByteBuffer, byte[], any Java primitive or class equivalent, and anything for which there is an encoder. If the method uses a Java primitive as a return value, the implementation must construct the text message to send using the standard Java string representation of the Java primitive. If the method uses a class equivalent of a Java primitive as a return value, the implementation must construct the text message from the Java primitive equivalent as described above. Developers should note that if developer closes the session during the invocation of a method with a return type, the method will complete but the return value will not be delivered to the remote endpoint. The send failure will be passed back into the endpoint's error handling method.
  • A logical websocket endpoint is represented in the Java WebSocket API as an instance of the Endpoint class. Developers may subclass the Endpoint class in order to intercept lifecycle events of the endpoint: those of a peer connecting, a peer disconnecting and an error being raised during the lifetime of the endpoint. The implementation must use at least one instance of the Endpoint class to represent the logical endpoint. Each instance of the Endpoint class may therefore handle connections to the endpoint from multiple peers. Some implementations may wish to use multiple instances of Endpoint to represent a logical endpoint, perhaps one instance per VM in a distributed server setting. The Java WebSocket API models the sequence of interactions between an endpoint and each of its peers using an instance of the Session class. The interactions between a peer and an endpoint begin with an open notification, followed by some number, possibly zero, of web socket messages between the endpoint and peer, followed by a close notification or error terminal to the connection. For each peer that is interacting with an endpoint, there is one Session instance that represents that interaction. The Session instance corresponding to the peer is passed to the Endpoint instance representing the endpoint at the key events in its lifecycle.
  • The diagram above highlights the key concepts that make up the domain language of batch. A Job has one to many steps, which has exactly one ItemReader, ItemProcessor, and ItemWriter. A job needs to be launched (JobOperator), and meta data about the currently running process needs to be stored (JobRepository). A Job is an entity that encapsulates an entire batch process. A Job will be wired together via a Job Specification Language. With JSR 352, a Job is simply a container for Steps. It combines multiple steps that belong logically together in a flow and allows for configuration of properties global to all steps, such as restartability. The job configuration contains:   The simple name of the job   Definition and ordering of Steps   Whether or not the job is restartableA Step is a domain object that encapsulates an independent, sequential phase of a batch job. Therefore, every Job is composed entirely of one or more steps. A Step contains all of the information necessary to define and control the actual batch processing. This is a necessarily vague description because the contents of any given Step are at the discretion of the developer writing it. A Step can be as simple or complex as the developer desires. A simple Step might load data from a file into the database, requiring little or no code. (depending upon the implementations used) A more complex Step may have complicated business rules that are applied as part of the processing. Not committing the transaction after each step as that would be costly from transaction aspect. Typically done after a few seconds or after some specific number of records. Or dynamic checkpoint, e.g. a particular business process triggers check pointing.Operator manages the lifecycle.
  • The diagram above highlights the key concepts that make up the domain language of batch. A Job has one to many steps, which has exactly one ItemReader, ItemProcessor, and ItemWriter. A job needs to be launched (JobOperator), and meta data about the currently running process needs to be stored (JobRepository). A Job is an entity that encapsulates an entire batch process. A Job will be wired together via a Job Specification Language. With JSR 352, a Job is simply a container for Steps. It combines multiple steps that belong logically together in a flow and allows for configuration of properties global to all steps, such as restartability. The job configuration contains:   The simple name of the job   Definition and ordering of Steps   Whether or not the job is restartableA Step is a domain object that encapsulates an independent, sequential phase of a batch job. Therefore, every Job is composed entirely of one or more steps. A Step contains all of the information necessary to define and control the actual batch processing. This is a necessarily vague description because the contents of any given Step are at the discretion of the developer writing it. A Step can be as simple or complex as the developer desires. A simple Step might load data from a file into the database, requiring little or no code. (depending upon the implementations used) A more complex Step may have complicated business rules that are applied as part of the processing. Not committing the transaction after each step as that would be costly from transaction aspect. Typically done after a few seconds or after some specific number of records. Or dynamic checkpoint, e.g. a particular business process triggers check pointing.JobOperator provides an interface to manage all aspects of job processing, including operational commands, such as start, restart, and stop, as well as job repository related commands, such as retrieval of job and step executions. A job repository holds information about jobs currently running and jobs that have run in the past. The JobOperator interface provides access to this repository. The repository contains job instances, job executions, and step executions.
  • The diagram above highlights the key concepts that make up the domain language of batch. A Job has one to many steps, which has exactly one ItemReader, ItemProcessor, and ItemWriter. A job needs to be launched (JobOperator), and meta data about the currently running process needs to be stored (JobRepository). A Job is an entity that encapsulates an entire batch process. A Job will be wired together via a Job Specification Language. With JSR 352, a Job is simply a container for Steps. It combines multiple steps that belong logically together in a flow and allows for configuration of properties global to all steps, such as restartability. The job configuration contains:   The simple name of the job   Definition and ordering of Steps   Whether or not the job is restartableA Step is a domain object that encapsulates an independent, sequential phase of a batch job. Therefore, every Job is composed entirely of one or more steps. A Step contains all of the information necessary to define and control the actual batch processing. This is a necessarily vague description because the contents of any given Step are at the discretion of the developer writing it. A Step can be as simple or complex as the developer desires. A simple Step might load data from a file into the database, requiring little or no code. (depending upon the implementations used) A more complex Step may have complicated business rules that are applied as part of the processing. Not committing the transaction after each step as that would be costly from transaction aspect. Typically done after a few seconds or after some specific number of records. Or dynamic checkpoint, e.g. a particular business process triggers check pointing.JobOperator provides an interface to manage all aspects of job processing, including operational commands, such as start, restart, and stop, as well as job repository related commands, such as retrieval of job and step executions. A job repository holds information about jobs currently running and jobs that have run in the past. The JobOperator interface provides access to this repository. The repository contains job instances, job executions, and step executions.
  • The diagram above highlights the key concepts that make up the domain language of batch. A Job has one to many steps, which has exactly one ItemReader, ItemProcessor, and ItemWriter. A job needs to be launched (JobOperator), and meta data about the currently running process needs to be stored (JobRepository). A Job is an entity that encapsulates an entire batch process. A Job will be wired together via a Job Specification Language. With JSR 352, a Job is simply a container for Steps. It combines multiple steps that belong logically together in a flow and allows for configuration of properties global to all steps, such as restartability. The job configuration contains:   The simple name of the job   Definition and ordering of Steps   Whether or not the job is restartableA Step is a domain object that encapsulates an independent, sequential phase of a batch job. Therefore, every Job is composed entirely of one or more steps. A Step contains all of the information necessary to define and control the actual batch processing. This is a necessarily vague description because the contents of any given Step are at the discretion of the developer writing it. A Step can be as simple or complex as the developer desires. A simple Step might load data from a file into the database, requiring little or no code. (depending upon the implementations used) A more complex Step may have complicated business rules that are applied as part of the processing. Not committing the transaction after each step as that would be costly from transaction aspect. Typically done after a few seconds or after some specific number of records. Or dynamic checkpoint, e.g. a particular business process triggers check pointing.JobOperator provides an interface to manage all aspects of job processing, including operational commands, such as start, restart, and stop, as well as job repository related commands, such as retrieval of job and step executions. A job repository holds information about jobs currently running and jobs that have run in the past. The JobOperator interface provides access to this repository. The repository contains job instances, job executions, and step executions.
  • The diagram above highlights the key concepts that make up the domain language of batch. A Job has one to many steps, which has exactly one ItemReader, ItemProcessor, and ItemWriter. A job needs to be launched (JobOperator), and meta data about the currently running process needs to be stored (JobRepository). A Job is an entity that encapsulates an entire batch process. A Job will be wired together via a Job Specification Language. With JSR 352, a Job is simply a container for Steps. It combines multiple steps that belong logically together in a flow and allows for configuration of properties global to all steps, such as restartability. The job configuration contains:   The simple name of the job   Definition and ordering of Steps   Whether or not the job is restartableA Step is a domain object that encapsulates an independent, sequential phase of a batch job. Therefore, every Job is composed entirely of one or more steps. A Step contains all of the information necessary to define and control the actual batch processing. This is a necessarily vague description because the contents of any given Step are at the discretion of the developer writing it. A Step can be as simple or complex as the developer desires. A simple Step might load data from a file into the database, requiring little or no code. (depending upon the implementations used) A more complex Step may have complicated business rules that are applied as part of the processing. Not committing the transaction after each step as that would be costly from transaction aspect. Typically done after a few seconds or after some specific number of records. Or dynamic checkpoint, e.g. a particular business process triggers check pointing.JobOperator provides an interface to manage all aspects of job processing, including operational commands, such as start, restart, and stop, as well as job repository related commands, such as retrieval of job and step executions. A job repository holds information about jobs currently running and jobs that have run in the past. The JobOperator interface provides access to this repository. The repository contains job instances, job executions, and step executions.
  • A Job is defined using Job Specification Language. For Java EE 7, this is defined using an XML document, called as Job XML.Job XML typically consists of many steps, this contains one simple step. The step is either a chunk or batchlet – this one is chunk. This one is a chunk and has a reader, processor, and writer. The ref attribute refers to CDI resolvable bean name bundled with the archive. The item-count attribute defines the chunk size, i.e. the number of items processed at one time. The reader, processor, and writer work together for a chunk number of items at a time. All of this is done within a transaction, with automatic checkpointing.Now lets take a look how reader, processor, and writer are implemented. This Job XML defines a simple use case of sending regular email statements.Reader implements ItemReader interface. The main method to override there is readItem which reads the item – this could be from any stream or database or JMS queue. For example, you may read Account information using JPA.Processor implements ItemProcessor interface. processItem takes the item just read, applies business processing and returns a new object (possibly different type). This new object is now aggregated with the writer. For example, you may read an Account object and return a Statement object.Writer implements ItemWriter interface. writeItems has a List parameter where all the aggregated items are available and writes it out. In our case, you will use JavaMail to send an email to List.
  • Partitioned: Same step is run in multiple threads, unique parameters identify the data to operateConcurrent: One split will define multiple steps and each step would run in a separate thread
  • Streaming API is much more efficient, no intermediate objects createdObject model API is built on top of Streaming APIForward-only parser, each parser can be configured with multiple features
  • Typesafe mapping
  • Typesafe mapping
  • Typesafe mapping
  • Typesafe mapping
  • The server containers provide runtime support for Java EE application components (such as servlets and Enterprise JavaBeansTM (EJBTM)). They provide a layer between application component code and platform services and resources. All application component code is run on a thread managed by a container and each container typically expects all access to container-supplied objects to occur on the same thread.It is because of this behavior that application components are typically unable to reliably use other Java EE platform services from a thread that is not managed by the container. Java EE Product Providers (see chapter 2.11 of the Java Platform Enterprise Edition Specification) also discourage the use of resources in a non-managed way, because it can potentially undermine the enterprise features that the platform is designed to provide such as availability, security, and reliability and scalability.When used within managed environments, this API is a much better alternative to existing Java SE APIs:- java.util.Timer, java.lang.Thread and the thread pool creation APIs from the Java SE concurrency utilities (JSR-166) in the java.util.concurrent package should never be used within managed environments, as it creates threads outside the purview of the container. . javax.management.timer.Timer is tightly coupled with the JMX framework and does not provide a sufficiently user-friendly or independent API.The Concurrency Utilities for Java EE specification thus provides a clean, simple, independent API by building on JSR-166, making it appropriate for use within any Java EE container.
  • A ManagedExecutorService provides methods for submitting tasks for execution in a managed environment. Implementations of the ManagedExecutorService are provided by a Java™ EE Product Provider. Application Component Providers use the Java Naming and Directory Interface™ (JNDI) to look-up instances of one or more ManagedExecutorService objects using resource environment references.The most common uses for a ManagedExecutorService is to run short-duration asynchronous tasks such as for processing of asynchronous methods in Enterprise JavaBean™ (EJB™) or for processing async tasks for Servlets that supports asynchronous processing. Use a managed ThreadFactory for long-running daemon tasks.
  • A single ManagedExecutorService instance is used to run tasks (in blue) from multiple application components (each denoted in a different color). Each task, when submitted to the ManagedExecutorService automatically retains the context of the submitting component and it becomes a Contextual Task. When the ManagedExecutorService runs the task, the task would be run in the context of the submitting component. ManagedExecutorService instances may be terminated or suspended by the application server when applications or components are stopped or the application server itself is shutting down.Figure 3-1 in the specification.

Java EE7&Avatar Java EE7&Avatar Presentation Transcript

  • Yoshio Terada Java Evangelist http://yoshio3.com, Twitter : @yoshioterada 1 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 以下の事項は、弊社の一般的な製品の方向性に関する概要を説明するもので す。また、情報提供を唯一の目的とするものであり、いかなる契約にも組み 込むことはできません。以下の事項は、マテリアルやコード、機能を提供す ることをコミットメント(確約)するものではないため、購買決定を行う際 の判断材料になさらないで下さい。オラクル製品に関して記載されている機 能の開発、リリースおよび時期については、弊社の裁量により決定されます 。 Oracleは、米国オラクルコーポレーション及びその子会社、関連会社の米国及びその他の国における登録商 標です。文中の社名、商品名等は各社の商標または登録商標である場合があります。 2 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • J2EE から Java EE へ 2005-2006年 Bill Shannon Photo by Sakuraba san 3 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 2009 年 12 月 10 日 Java EE 6 リリース かんたん開発の集大成 4 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • Now Available Java Platform, Enterprise Edition 7 The standard in community-driven enterprise software 5 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • Java EE の歴史 Java EE 7 開発生産性 & HTML5 エンタープライズ プラットフォーム 堅牢性 かんたん開発 軽量化 Web サービス 1998-2004 6 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. 2005-2012 2013 - Future
  • Java EE 7 へ含まれる予定の JSR 一覧 JSP 2.2 JSF 2.2 Portable Extensions JAX-RS 2.0 EL 3.0 Interceptors 1.1 Managed Bean 1.0 Connector 1.6 JPA 2.1 CDI 1.1 EJB 3.2 JTA 1.2 JMS 2.0 新規追加 7 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Bean Validation 1.1 Servlet 3.1 Common Annotations 1.1 Concurrency Utilities for EE (JSR-236) Batch Application (JSR-352) Java API for JSON (JSR-353) Java API for WebSocket (JSR-356) 大幅な更新 通常の更新
  • Java: 幅広い業界への適用 9,000,000 JAVA 開発者 18 社による Java EE 準拠アプリケーション・サーバの提供 8 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 9 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • GlassFish v4 Java EE SDK NetBeans 7.3.1 10 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • Java EE 7 のどの機能に興味がありますか? ブログのアンケート結果より WebSocket テクノロジー バッチ JAX-RS JSON-P 並列処理 11 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • Java EE 7 のテーマ Java EE 7 開発生産性 12 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. HTML5 エンタープライズ ニーズへの対応
  • 各カテゴリに含まれる機能 Java EE 7 JSON 1.0 EJB 3.2 Batch 1.0 CDI 1.1 Concurrency 1.0 JSF 2.2 JTA 1.2 JMS 2.0 Servlet 3.1 Interceptors 1.2 JPA 2.1 Expression Language 3.0 Bean Validation 1.1 WebSocket 1.0 JAX-RS 2 13 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • WebSockets 次世代の HTML 5 対応アプリケーション 次世代 HTML5 対応のアプリケーションの基盤  WebSockets : 低レイテンシ、レスポンスタイムの改善  JSON : シンプルなデータ・フォーマットで移植性の高いアプリケーション  RESTful : 同期・非同期、スケーラブル、高パフォーマンス 14 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 様々なHTML 5 対応 View HTTP/JS 従来 アプリ Model アプリ 次世代 View HTTP/JS View JSON Service 15 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 様々なHTML 5 対応 HTTP/JS View アプリ Model JavaServer Faces 2.2 16 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 様々なHTML 5 対応 WebSocket 1.0 JSON 1.0 JAX-RS 2.0 アプリ 次世代 View HTTP/JS View JSON Service 17 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 開発生産性の向上  簡単なアプリケーション・アーキテクチャ  オールインワンの統合プラットフォーム Java EE 7  冗長的なコード記述の削減による効率化  アノテーション・ベース開発の拡大による 効率化  アプリケーションの移植性の向上 18 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 開発生産性の向上 Java EE 7 Java SE 7 対応  try-with-resource への対応 冗長的なコード排除  冗長的なインスタンス生成の抑制 完全整理されたプラットフォーム  頻繁に利用される JAX-RS の Web Profile 対 応 19 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. JMSContext Connection Session
  • エンタープライズ・ニーズへの対応  バッチ処理 : OLTP のパフォーマンス改善  マルチスレッド並列タスク:スケーラビリティの 改善  JMS の実装方法の改善 20 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • エンタープライズ・ニーズへの対応 Java EE 環境における並列処理実装方法の提供 バッチ・アプリケーションに対する標準化ニーズへの対応 JMS における開発生産性の向上 21 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • DOWNLOAD Java EE 7 SDK oracle.com/javaee GlassFish 4.0 Full Platform or Web Profile glassfish.org 22 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • Project Avatar 23 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • Open Sourcing Project Avatar avatar.java.net Download and try now! Get involved! 24 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 25 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • Project Avatar とは コンセプト  先進的な HTML 5 アプリ構築フレームワーク – WebSocket, Server-Sent Event, RESTful に対応  モジュール化対応 JavaScript フレームワーク  軽量なサーバ・アーキテクチャ (Thin-Server Architecture)  Avatar のメリット – サーバ・サイドJavaScript と Java EE アプリの融合 – Java VM 上で稼働する JavaScrip のスケーラビリテイ・信頼性・運用保守性 26 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • Thin-Server アーキテクチャ (TSA) View HTTP/JS 今まで アプリ サーバ側でマージ アプリ View TSA クライアント側 でマージ 27 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Model HTTP/JS JSON Model View Service
  • Avatar の概念 (クライアント側: View) Avatar (Controller) View (UI Node) HTML 5 JavaScript EL • データ・ バインディング • ナビゲーション • ローカル・ ストレージ Model アクセス方法を提供 • ローカル • RESTful • SSE • WebSocket ブラウザ(JavaScript/DOM) 28 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • Avatar の概念 (サーバ側 : Service) Service アクセス方法を提供 • RESTful • SSE • WebSocket Avatar ルーティング JSON のシリアライズ Data プロバイダ 利用可能なデータソー ス • ファイル • DB(JPA) • インメモリ • JMS Nashorn (JavaVMで稼働するJavaScriptエンジン) 29 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • Avatar のアーキテクチャ Avatar アプリ (HTML 5/JS/CSS) HTTP Avatar 実行環境 UI ブラウザ 30 HTML 5 DOM ローカルストレージ Copyright © 2012, Oracle and/or its affiliates. All rights reserved. HTTP・ SSE・ WebSocket HTTP/ WebSocket View アプリ サービス Avatar アプリ (HTML5/JavaScript) Avatar コンパイラ Nashorn (JavaScript エンジン) Java EE サービス Java EE アプリ App サーバ
  • Avatar のアーキテクチャ Avatar アプリ (HTML 5/JS/CSS) HTTP Avatar 実行環境 HTTP/ WebSocket UI ブラウザ 31 HTML 5 DOM ローカルストレージ Copyright © 2012, Oracle and/or its affiliates. All rights reserved. HTTP/ WebSocket View サービス Avatar アプリ (HTML5/JavaScript) Data ①サービスアプリの作成 Avatar Avatar コンパイラ Nashorn (JavaScript エンジン) Java EE サービス Java EE アプリ App サーバ
  • Avatar アプリの作成 Avatar のプロジェクトの作成 # avatar new [project-name] ※ デフォルトで View のみ生成 32 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • Avatar のアーキテクチャ Avatar アプリ (HTML 5/JS/CSS) HTTP Avatar 実行環境 HTTP/ WebSocket UI ブラウザ 33 HTML 5 DOM ローカルストレージ Copyright © 2012, Oracle and/or its affiliates. All rights reserved. HTTP/ WebSocket View アプリ サービス Avatar アプリ (XML/JavaScript) Avatar コンパイラ Nashorn (JavaScript エンジン) ② Viewとサービスを実装 Java EE サービス Java EE アプリ App サーバ
  • View(クライアント) と Serivce(サーバ) の実装 ディレクトリ構成 Avatar 用 JavaScriptファイル html, xhtml, xml ファイル 34 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • var avatar = require("org/glassfish/avatar"); var message = 'The Server Time is '; var getTime = function(){ var current = new Date(); return{ msg: message, h: current.getHours(), m: current.getMinutes(), s: current.getSeconds() }; }; … 続く 35 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Service (サーバ) の実装
  • … 続き avatar.registerPushService({ url:"data/time"}, function(){ this.$onOpen = this.$onTimeout = function(context){ context.$setTimeout(1000); // return context.$sendMessage(getTime()); }; } ); Server-Sent Event のサーバ・サイドの実装コード Service (サーバ) の実装 36 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • <!DOCTYPE html> View(クライアント) <html><head>…</head> <body> <script data-model="push"> var Time = function(){ this.msg = this.h = this.m = this.s =''; }; </script> <script data-type="Time" data-instance="time" data-url="data/time"></script> <output class="time"> #{time.msg}#{time.h}:#{time.m}:#{time.s} </output> </body></html> 37 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. の実装
  • Avatar のアーキテクチャ Avatar アプリ (HTML 5/JS/CSS) HTTP Avatar 実行環境 HTTP/ WebSocket UI ブラウザ 38 HTML 5 DOM ローカルストレージ Copyright © 2012, Oracle and/or its affiliates. All rights reserved. View アプリ サービス Avatar アプリ (XML/JavaScript) Avatar コンパイラ Nashorn (JavaScript エンジン) ③ Viewとサービスを コンパイル Java EE HTTP/ WebSocket サービス Java EE アプリ App サーバ
  • Avatar のコンパイル Avatar アプリケーションのコンパイル # avatar compile project-name Compiled: project-name 39 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • コンパイル後の ディレクトリ構成 サーバ側の実行ファイル クライアント側の実行ファイル 40 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • Avatar アプリケーションのデプロイ GlassFish にアプリケーションをデプロイ # asadmin deploy project-name Application deployed with name project-name. Command deploy executed successfully. 41 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • Avatar アプリケーションのダウンロード Avatar アプリ (HTML 5/JS/CSS) HTTP Avatar 実行環境 ④ View サービスの UI HTML 5 DOM 「複数ページの一括」 ダウンロード (※プラグインは不要) ブラウザ 42 ローカルストレージ Copyright © 2012, Oracle and/or its affiliates. All rights reserved. HTTP/ WebSocket HTTP/ WebSocket View サービス Avatar アプリ (XML/JavaScript) Data サービス Avatar コンパイラ Nashorn (JavaScript エンジン) Java EE サービス Java EE アプリ App サーバ
  • Avatar サービスの呼び出し Avatar アプリ (HTML 5/JS/CSS) HTTP Avatar 実行環境 HTTP/ WebSocket UI HTML 5 DOM ⑤ WebSocket/Server-Sent Event/ RESTful で Data サービスを利用 ローカルストレー ブラウザ 43 ジ Copyright © 2012, Oracle and/or its affiliates. All rights reserved. HTTP/ WebSocket View サービス Avatar アプリ (XML/JavaScript) アプリ サービス Avatar コンパイラ Nashorn (JavaScript エンジン) Java EE サービス Java EE アプリ App サーバ
  • Java EE サービスの呼び出し Avatar アプリ (HTML 5/JS/CSS) HTTP Avatar 実行環境 HTTP/ WebSocket UI ブラウザ 44 HTML 5 DOM ローカルストレー ジ Copyright © 2012, Oracle and/or its affiliates. All rights reserved. HTTP/ WebSocket View サービス Avatar アプリ (XML/JavaScript) Data サービス Avatar コンパイラ ⑥ サーバ側はJava EE Nashorn (JavaScript エンジン) のサービスも利用可能 Java EE サービス Java EE アプリ App サーバ
  • アプリケーション・サーバ側の リソースも利用可能 Avatar アプリ (HTML 5/JS/CSS) HTTP Avatar 実行環境 HTTP/ WebSocket UI ブラウザ 45 View サービス Avatar アプリ (XML/JavaScript) アプリ サービス Avatar コンパイラ Nashorn (JavaScript エンジン) HTML 5 DOM ⑦ JPA, JMS, NoSQL 等サーバリソースも ローカルストレー 利用可能 ジ Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Java EE サービス Java EE アプリ App サーバ
  • Avatar のアーキテクチャ Avatar アプリ (HTML 5/JS/CSS) HTTP Avatar 実行環境 HTTP/ WebSocket UI HTML 5 DOM ブラウザ ローカルストレー ジ 46 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. View サービス Avatar アプリ (XML/JavaScript) Data サービス Avatar コンパイラ Nashorn (JavaScript エンジン) ⑧ クライアント側は HTML 5, DOM, Java EE ローカルストレージ Java EE アプリ サービス HTTP/ App サーバ WebSocket 等を利用可能
  • 47 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. JDK 8 (b103 移行) Avatar バンドル済 GlassFish v4
  • はじめての Project Avatar http://yoshio3.com/2013/10/10/beginning-of-project-avatar/ 手始めにここから はじめてみてください 48 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • Java EE 8 とその将来 Caching NoSQL JSON-B HTML5++ Modularity Java EE 7 State Management 49 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. PaaS Cloud
  • 50 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • Java EE 7 の新機能 1. WebSocket クライアント・サーバ実装 2. Batch アプリケーション 3. JSON 処理 4. Java EE における並列処理 51 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • Java API for WebSocket Overview – JSR 356  API for WebSocket Client/Endpoints – Annotated (@ServerEndpoint, @ClientEndpoint) – Programmatic (Endpoint)  WebSocket opening handshake negotiation  Lifecycle methods  Packaging and Deployment 52 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • Java API for WebSocket POJO/Annotation-driven import javax.websocket.*; @ServerEndpoint("/hello") public class HelloBean { @OnMessage public String sayHello(String name) { return “Hello “ + name; } } 53 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • Java API for WebSocket WebSocket Annotations Annotation Level Purpose @ServerEndpoint class Turns a POJO into a WebSocket Endpoint @ClientEndpoint class Turns a POJO into a WebSocket Client method Intercepts WebSocket Message events @OnMessage @PathParam method Flags a matched path segment of a URI-template parameter @OnOpen Intercepts WebSocket Open events @OnClose method Intercepts WebSocket Close events @OnError 54 method method Intercepts errors during a conversation Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • Java API for WebSocket @ServerEndpoint Attributes value decoders list of message decoder classnames encoders list of message encoder classnames subprotocols 55 Relative URI or URI template e.g. “/hello” or “/chat/{subscriber-level}” list of the names of the supported subprotocols Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • Java API for WebSocket Custom Payloads @ServerEndpoint( value="/hello", encoders={MyMessage.class}, decoders={MyMessage.class} ) public class MyEndpoint { ... } 56 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • Java API for WebSocket 1.0 Custom Payloads – Text public class MyMessage implements Decoder.Text<MyMessage>, Encoder.Text<MyMessage> { private JsonObject jsonObject; public MyMessage decode(String s) { jsonObject = new JsonReader(new StringReader(s)).readObject(); return this; } public boolean willDecode(String string) { return true; // Only if can process the payload } public String encode(MyMessage myMessage) { return myMessage.jsonObject.toString(); } } 57 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • Java API for WebSocket 1.0 Custom Payloads – Binary public class MyMessage implements Decoder.Binary<MyMessage>, Encoder.Binary<MyMessage> { public MyMessage decode(byte[] bytes) { ... return this; } public boolean willDecode(byte[] bytes) { ... return true; // Only if can process the payload } public byte[] encode(MyMessage myMessage) { ... } } 58 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • Java API for WebSocket 1.0 Canonical Chat Example @ServerEndpoint("/chat”) public class ChatBean { static Set<Session> peers = Collections.synchronizedSet(…); @OnOpen public void onOpen(Session peer) { peers.add(peer); } @OnClose public void onClose(Session peer) { peers.remove(peer); } ... 59 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • Java API for WebSocket 1.0 Chat (contd.) ... @OnMessage public void message(String message, Session client) { for (Session peer : peers) { peer.getBasicRemote().sendObject(message); } } } 60 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • Java API for WebSocket 1.0 URI Template Matching  Level 1 only @ServerEndpoint(“/orders/{order-id}”) public class MyEndpoint { @OnMessage public void processOrder( @PathParam(“order-id”)String orderId) { ... } } 61 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • Java API for WebSocket Which methods can be @OnMessage ?  Exactly one of the following – Text: String, Java primitive or equivalent class, String and boolean, Reader, any type for which there is a decoder – Binary: byte[], ByteBuffer, byte[] and boolean, ByteBuffer and boolean, InptuStream, any type for which there is a decoder – Pong messages: PongMessage  An optional Session parameter  0..n String parameters annotated with @PathParam  Return type: String, byte[], ByteBuffer, Java primitive or class equivalent or any type for which there is a encoder 62 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • Java API for WebSocket Sample Messages  void m(String s);  void m(Float f, @PathParam(“id”)int id);  Product m(Reader reader, Session s);  void m(byte[] b); or void m(ByteBuffer b);  Book m(int i, Session s, @PathParam(“isbn”)String isbn, @PathParam(“store”)String store); 63 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • Java API for WebSocket WebSocket Client @ClientEndpoint public class HelloClient { @OnMessage public void message(String message, Session session) { // process message from server } } WebSocketContainer c = ContainerProvider.getWebSocketContainer(); c.connectToServer(HelloClient.class, “hello”); 64 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • Java API for WebSocket Interface-driven Endpoint public class MyEndpoint extends Endpoint { @Override public void onOpen(Session session) { session.addMessageHandler(new MessageHandler.Text() { public void onMessage(String name) { try { session.getBasicRemote().sendText(“Hello “ + name); } catch (IOException ex) { } } }); } } 65 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • Java API for WebSocket Interface-driven Endpoint Server Packaging ServerEndpointConfiguration config = ServerEndpointConfigurationBuilder .create(MyEndpoint.class, “/foo”) .build(); 66 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • Java API for WebSocket Server and Client Configuration  Server – URI matching algorithm – Subprotocol and extension negotiation – Message encoders and decoders – Origin check – Handshake response  Client – Requested subprotocols and extensions – Message encoders and decoders – Request URI 67 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • Java API for WebSocket Security  Authenticates using Servlet security mechanism during opening handshake – Endpoint mapped by ws:// is protected using security model defined using the corresponding http:// URI  Authorization defined using <security-constraint> – TBD: Add/reuse security annotations  Transport Confidentiality using wss:// – Access allowed over encrypted connection only 68 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • Batch Applications 1.0 Overview – JSR 352  Suited for non-interactive, bulk-oriented and long-running tasks  Batch execution: sequential, parallel, decision-based  Processing styles – Item-oriented: Chunked (primary) – Task-oriented: Batchlet 69 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • Batch Applications 1.0 Concepts  Job: Entire batch process – Put together through a Job Specification Language (XML)  Step: Independent, sequential phase of a job – ItemReader: Retrieval of input for a step, one at a time – ItemProcessor: Business processing of an item – ItemWriter: Output of an item, chunks of items at a time  JobOperator: Manage batch processing  JobRepository: Metadata for jobs 70 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • Batch Applications 1.0 Concepts  JobInstance: Logical Job Run  JobExecution: Single attempt to run a job  StepExecution: Single attempt to run a step 71 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • Batch Applications 1.0 Types of Step  Chunked: Item-oriented processing (Recommended) – Using a reader-processor-writer pattern – Configurable check-pointing and transactions – E.g. sending monthly bank statements  Batchlet: Task-oriented processing – Roll-your-own batch pattern – Invoke once, runs to completion, and exits – E.g., file transfer 72 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • Batch Applications 1.0  Primary processing style – Read and Process one item – Do the above „n‟ times (called „commit interval‟) – Write the „n‟ processed items – Commit the transaction 73 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • Batch Applications 1.0 Job Specification Language  Specifies a job, steps and directs their execution  Implemented in XML – Referred as “Job XML”  Supports inheritance of job, step, flow, and split 74 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • Batch Applications 1.0 Job Specification Language – Simple Job <job id=“myJob”> <step id=“init”> <chunk …/> <next on=“initialized” to=“process”/> <fail on=“initError”/> </step> <step id=“process”> <batchlet …/> <end on=”success”/> <fail on=”*” exit-status=“FAILURE”/> </step> </job> 75 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • Batch Applications 1.0 Chunked Job Specification <step id=”sendStatements”> …implements ItemReader { <chunk item-count=“3”> public Object readItem() { <reader ref=”accountReader”/> // read account using JPA <processor ref=”accountProcessor”/> } <writer ref=”emailWriter”/> </step> …implements ItemProcessor { Public Object processItems(Object account) { // read Account, return Statement } …implements ItemWriter { public void writeItems(List accounts) { // use JavaMail to send email } 76 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • Batch Applications 1.0 Job Specification Language – Batchlet <step id=”transferFile”> <batchlet ref=“MyFileTransfer” /> </step> …implements Batchlet { @Override public void process() { // Transfer file } 77 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • Batch Applications 1.0 Listeners – Intercept Batch Execution Interface JobListener AbstractJobListener StepListener AbstractStepListener ChunkListener AbstractChunkListener ItemRead/Write/ProcessListener AbstractItemRead/Write/ProcessListener SkipRead/Write/ProcessListener AbstractSkipRead/Write/ProcessListener RetryRead/Write/ProcessListener 78 Abstract Classes AbstractRetryRead/Write/ProcessListener Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • Batch Applications 1.0 Job Parallelization  Steps can be run in parallel  Parallelization models – Partitioned  Multiple instances across multiple threads  Each thread runs the same step, unique parameters identify data  E.g., process accounts from 1-100, 101-200, etc. – Concurrent  Steps defined by a split run concurrently across multiple threads  One step per thread 79 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • Java API for JSON Processing 1.0 Overview – JSR 353  API to parse and generate JSON  Streaming API – Low-level, efficient way to parse/generate JSON – Provides pluggability for parsers/generators  Object Model – Simple, easy-to-use high-level API – Implemented on top of Streaming API  Binding JSON to Java objects forthcoming 80 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • Java API for JSON Processing 1.0 Streaming API  Parses JSON in a streaming way from input sources – Similar to StaX‟s XMLStreamReader, a pull parser  Created using – Json.createParser(…) – Json.createParserFactory().createParser(…)  Parser state events – START_ARRAY, END_ARRAY, START_OBJECT, END_OBJECT, … 81 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • Java API for JSON Processing Streaming Parser { "firstName": "John", "lastName": "Smith", "age": 25, "phoneNumber": [ { "type": "home", "number": "212 555-1234" }, { "type": "fax", "number": "646 555-4567" } ] } 82 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • Java API for JSON Processing Streaming Parser { START_OBJECT "firstName": "John", "lastName": "Smith", "age": 25, "phoneNumber": [ { "type": "home", "number": "212 555-1234" }, { "type": "fax", "number": "646 555-4567" } ] } 83 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • Java API for JSON Processing Streaming Parser KEY_NAME { "firstName": "John", "lastName": "Smith", "age": 25, "phoneNumber": [ { "type": "home", "number": "212 555-1234" }, { "type": "fax", "number": "646 555-4567" } ] } 84 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • Java API for JSON Processing Streaming API { VALUE_STRING "firstName": "John", "lastName": "Smith", "age": 25, "phoneNumber": [ { "type": "home", "number": "212 555-1234" }, { "type": "fax", "number": "646 555-4567" } ] } 85 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • Java API for JSON Processing Streaming API VALUE_NUMBER { "firstName": "John", "lastName": "Smith", "age": 25, "phoneNumber": [ { "type": "home", "number": "212 555-1234" }, { "type": "fax", "number": "646 555-4567" } ] } 86 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • Java API for JSON Processing Streaming API { "firstName": "John", "lastName": "Smith", "age": 25, "phoneNumber": [ START_ARRAY { "type": "home", "number": "212 555-1234" }, { "type": "fax", "number": "646 555-4567" } ] } 87 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • Java API for JSON Processing 1.0 Streaming API { "firstName": "John", "lastName": "Smith", "age": 25, "phoneNumber": [ { "type": "home", "number": "212 555-1234" }, { "type": "fax", "number": "646 555-4567" } ] END_ARRAY } 88 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • Java API for JSON Processing 1.0 Streaming API { "firstName": "John", "lastName": "Smith", "age": 25, "phoneNumber": [ { "type": "home", "number": "212 555-1234" }, { "type": "fax", "number": "646 555-4567" } ] } JsonParser p = Json.createParser(…); JsonParser.Event event = p.next(); // START_OBJECT event = p.next(); // KEY_NAME event = p.next(); // VALUE_STRING String name = p.getString(); // "John” 89 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • Java API for JSON Processing 1.0 Streaming API  JsonGenerator – Generates JSON in a streaming way to output sources  Similar to StaX‟s XMLStreamWriter – Created using  Json.createGenerator(…)  Json.createGeneratorFactory().createGenerator(…) – Optionally, configured with features  E.g. for pretty printing 90 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • Java API for JSON Processing Streaming API JsonGenerator jg = Json.createGenerator(…); "phoneNumber": [ { "type": "home", "number": ”408-123-4567” }, { "type": ”work", "number": ”408-987-6543” } ] 91 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. jg. .beginArray("phoneNumber") .beginObject() .add("type", "home") .add("number", "408-123-4567") .endObject() .beginObject() .add("type", ”work") .add("number", "408-987-6543") .endObject() .endArray(); jg.close();
  • Java API for JSON Processing 1.0 Object Model API  JsonObject/JsonArray – JSON object and array structures – JsonString and JsonNumber for string and number values  JsonBuilder – Builds JsonObject and JsonArray  JsonReader – Reads JsonObject and JsonArray from input source  JsonWriter – Writes JsonObject and JsonArray to output source 92 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • Java API for JSON Processing Object API  Reads JsonObject and JsonArray from input source – i/o Reader, InputStream (+ encoding)  Optionally, configured with features  Uses pluggable JsonParser // Reads a JSON object try(JsonReader reader = Json.createReader(io)) { JsonObject obj = reader.readObject(); } 93 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • Java API for JSON Processing Object API  Writes JsonObject and JsonArray to output source – i/o Writer, OutputStream (+ encoding)  Optionally, configured with features. For e.g. pretty printing  Uses pluggable JsonGenerator // Writes a JSON object try(JsonWriter writer = Json.createWriter(io)) { writer.writeObject(obj); } 94 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • Java API for JSON Processing Configuration  Configuration is a set of parser/generator features – Pretty Printing, Single-Quoted strings  Supports extensibility (custom features)  Can be used in streaming & object-model API // Writes a JSON object prettily JsonConfiguration config = new JsonConfiguration().withPrettyPrinting(); try(JsonWriter writer = Json.createWriter(io, config)) { writer.writeObject(obj); } 95 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • Concurrency Utilities for Java EE Overview – JSR 236  Provide concurrency capabilities to Java EE application components – Without compromising container integrity  Support simple (common) and advanced concurrency patterns  Provide consistency between Java SE and Java EE concurrency programming model – Extend the Concurrency Utilities API (JSR 166y)  java.util.concurrent package  Largely by providing a managed version of java.util.concurrent.ExecutorService 96 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • Concurrency Utilities for Java EE ManagedExecutorService  Managed version of java.util.concurrent.ExecutorService – Lookup using JNDI  Java EE components create task classes – Implement java.lang.Runnable or java.util.concurrent.Callable  Submitted using submit or invoke methods  Multiple (configurable) executors are permitted 97 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • Concurrency Utilities for Java EE Defining ManagedExecutorService using JNDI  Recommended to bind in java:comp/env/concurrent subcontext <resource-env-ref> <resource-env-ref-name> concurrent/BatchExecutor </resource-env-ref-name> <resource-env-ref-type> javax.enterprise.concurrent.ManagedExecutorService </resource-env-ref-type> </resource-env-ref> 98 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • Concurrency Utilities for Java EE Submit Tasks to ManagedExecutorService using JNDI public class TestServlet extends HTTPServlet { @Resource(name=“concurrent/BatchExecutor”) ManagedExecutorService executor; Future future = executor.submit(new MyTask()); class MyTask implements Runnable { public void run() { . . . // task logic } } } 99 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • Concurrency Utilities for Java EE Submitting multiple tasks class MyTask implements Callable<Long> { public Long call() { . . .} } class MyTask2 implements Callable<Account> { } ArrayList<Callable> tasks = new ArrayList<>(); tasks.add(new MyTask()); tasks.add(new MyTask2()); List<Future<Object>> res = executor.invokeAll(tasks); 100 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • Concurrency Utilities for Java EE ManagedExecutorService Configuration  ThreadFactory: Reference to ManagedThreadFactory  Thread Use: Short vs long-running tasks, pooled vs daemon  Hung Task Threshold: Time before task is considered hung  PoolInfo – Core Size: Minimum number of threads – Maximum Size: Maximum number of threads (unbounded) – Keep Alive: TTL for idle threads if > core size – Work Queue Capacity: Inbound buffer size (unbounded) 101 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • Concurrency Utilities for Java EE ManagedExecutorService Configuration  Reject Policy: Policy if a task is rejected by executor – Abort: Throw an exception when rejected – Retry and Abort: Automatically submit to another instance and abort if it fails  Run Location: Distributable or Local  Contextual Callback: Boolean indicating whether container context propagated to threads or not 102 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • Concurrency Utilities for Java EE  Server-Managed Thread Pool Executor Component Relship 103 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • Concurrency Utilities for Java EE ManagedScheduledExecutorService  Adds delay and periodic task running capabilities provided to ManagedExecutorService  Accessible via javax.enterprise.concurrent.ManagedScheduledExecutorService JNDI reference  Tasks submitted using submit, invokeXXX or scheduleXXX methods 104 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • Concurrency Utilities for Java EE ManagedScheduledExecutorService Sample public class TestServlet extends HTTPServlet { @Resource(name=“concurrent/LoggerExecutor”) ManagedScheduledExecutorService executor; Future future = executor.schedule( new MyTask(), 5, TimeUnit.SECONDS); 105 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • Concurrency Utilities for Java EE  ContextService 106 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • Concurrency Utilities for Java EE ManagedThreadFactory  Provides a method for creating threads for execution in a managed environment  Lookup using JNDI <resource-env-ref> <resource-env-ref-name> concurrent/LoggerThreadFactory </resource-env-ref-name> <resource-env-ref-type> javax.enterprise.concurrent.ManagedThreadFactory </resource-env-ref-type> </resource-env-ref> 107 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • Concurrency Utilities for Java EE 1.0 ManagedThreadFactory Sample @Resource(“concurrent/LoggerThreadFactory”) ManagedThreadFactory threadFactory; LoggerTask task = new LoggerTask(); Thread thread = threadFactory.newThread(task); LoggerTask implements Runnable { public void run() { . . . } } 108 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 109 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.