SlideShare une entreprise Scribd logo
1  sur  54
Télécharger pour lire hors ligne
TM
Enterprise JavaBeans
(EJBTM) 3.1
Kenneth Saks
Senior Staff Engineer
SUN Microsystems
Agenda
•   Background
•   Proposed Functionality
•   Summary
•   Q&A




                             2
EJB 3.0 Specification (JSR 220)
• Features
  > Simplified EJB API
  > Java Platform Persistence API
• Focus on ease-of-use
  > Annotations
  > Intelligent defaults
  > Fewer classes needed
• Very well received within the community
  > But... more work is needed


                                            3
EJB 3.1 Specification
• Goals
  > Continued focus on ease-of-use
  > New features
• JSR (Java Specification Request) 318
  > Launched in August 2007
     – Java Persistence API will evolve separately ( JSR 317 )
  > Early Draft February 2008
  > Public Draft October 2008
• Caveat – APIs still subject to change

                                                                 4
Agenda
•   Introduction
•   Proposed Functionality
•   Summary
•   Q&A




                             5
Ease of Use Improvements

•   Optional Local Business Interfaces
•   Simplified Packaging
•   EJB “Lite”
•   Portable Global JNDI Names
•   Simplified Unit Testing




                                         6
Session Bean with
Local Business Interface
   HelloBean Client    <<interface>
                      com.acme.Hello

  @EJB                String sayHello()
  private Hello h;

  ...

  h.sayHello();       com.acme.HelloBean


                       public String
                       sayHello()
                       { ... }


                                           7
Optional Local Business Interfaces

• Sometimes local business interface isn't needed
• Better to completely remove interface from
  developer's view than to generate it
• Result : “no-interface” view
  > Just a bean class
  > public bean class methods exposed to client
  > Same behavior and client programming model
    as Local view
     – Client acquires an EJB component reference instead
       of calling new()

                                                     8
Session Bean with “No-interface”
View
 @Stateless
 public class HelloBean {

     public String sayHello(String msg) {
         return “Hello “ + msg;
     }

 }




                                            9
No-interface View Client
 @EJB HelloBean h;

 ...

 h.sayHello(“bob”);




                           10
Web/EJB Application in
    TM
Java EE Platform 5
           foo.ear                          foo.ear

                                    lib/foo_common.jar
  foo_web.war
  WEB-INF/web.xml                   com/acme/Foo.class
  WEB-INF/classes/
   com/acme/FooServlet.class        foo_web.war
  WEB-INF/classes
   com/acme/Foo.class          OR   WEB-INF/web.xml
                                    WEB-INF/classes/
                                     com/acme/FooServlet.class
  foo_ejb.jar
 com/acme/FooBean.class             foo_ejb.jar
 com/acme/Foo.class
                                    com/acme/FooBean.class


                                                                 11
Web/EJB Application in
    TM
Java EE Platform 6
                 foo.war

         WEB-INF/classes/
          com/acme/FooServlet.class

         WEB-INF/classes/
          com/acme/FooBean.class




                                      12
Simplified Packaging

• Goal is to remove an artificial packaging restriction
  > Not to create a new flavor of EJB component
• EJB component behavior is independent of
  packaging
  > One exception : module-level vs. component-level
    environment
• No new restrictions placed on .war
  > Deploy .war stand-alone OR within an .ear



                                                       13
EJB “Lite”

• Small subset of EJB 3.1 API for use in Web Profile
• Broaden the availability of EJB technology
  > Without losing portability
• Same exact Lite application can be deployed to Web
  Profile and Full Profile
  > Thanks to simplified .war packaging
• Open issue : whether Web Profile will require EJB
  Lite


                                                  14
“Lite” vs. Full Functionality
Lite                       Full = Lite + the following:
• Local Session Beans      • Message Driven Beans
• Annotations / ejb-       • EJB Web Service
  jar.xml                    Endpoints
• CMT / BMT                • RMI-IIOP
• Declarative Security       Interoperability
• Interceptors             • 2.x / 3.x Remote view
                           • 2.x Local view
• (Also requires JPA 2.0   • Timer Service
  API / JTA 1.1 API )      • CMP / BMP               15
Session Bean Exposing a Remote
View
 @Stateless
 @Remote(Hello.class)
 public class HelloBean implements Hello {

     public String sayHello(String msg) {
         return “Hello “ + msg;
     }

 }




                                            16
Remote Clients
 // Remote client in a Java EE container
 @EJB Hello hello;


 // Remote client in a Java SE environment
 Hello hello = (Hello)
   new InitialContext().lookup(???);


 Question : How does the caller find the
 target EJB component?



                                           17
Problems with “Global” JNDI Names

• Not portable
  > Global JNDI namespace is not defined in Java EE
    platform specification
  > Vendor-specific configuration needed for each
    deployment
• No standard syntax
  > Can names contain : “.”, “_”, “/” ?
• Not clear which resources have them
  > Local interfaces?


                                                      18
Portable Global JNDI Names
 “java:global[/<app-name>]/<module-
 name>/<bean-name>”

 // Client in a Java EE container
 @EJB(mappedName=
      ”java:global/hello/HelloBean”)
 Hello hello;


 // Client in a Java SE environment
 Hello hello = (Hello) new InitialContext()
     lookup(“java:global/hello/HelloBean”);

                                         19
EJB Component Testing

• It's too hard to test EJB components,
  especially the Local view
  > Forced to go through Remote facade or Web tier
  > Separate JVM™ instances needed for server and client
• Support for running in Java SE exists, but...
  > Not present in all implementations
  > No standard API for bootstrapping, component discovery,
    shutdown etc.



                                                       20
Example: No-interface Stateless
Session Bean
 @Stateless
 public class BankBean {

     @PersistenceContext EntityManager accountDB;

     public String createAccount(AccountDetails d) {
       ...
     }

     public void removeAccount(String accountID) {
       ...
     }

 }

                                                     21
Example: Embeddable API
 public class BankTester {

   public static void main(String[] args) {

       EJBContainer container =
          EJBContainer.createEJBContainer();

       // Acquire EJB component reference
       BankBean bank = (BankBean)container.getContext().
          lookup(“java:global/bank/BankBean”);

       testBank(bank);
       ...
       container.close();
   }

                                                   22
Example : Embeddable API (cont.)
 % java -classpath bankClient.jar :
                   bank.jar :
                   javaee.jar :
                   <vendor_rt>.jar

                   com.acme.BankTester




                                         23
Embeddable API

• Execute enterprise beans in a Java SE environment
• “Single application” model
• Same EJB component behavior / lifecycle as
  server-side
  > CMT, injection, threading guarantees, etc.
• Only EJB “Lite” functionality required to be available




                                                     24
New Features

•   Singletons
•   Application startup / shutdown callbacks
•   Calendar-based timer expressions
•   Automatic timer creation
•   Simple Asynchrony




                                               25
Singletons

• New session bean component type
  > One singleton bean instance per application per JVM
  > Provides easy sharing of state within application
  > Designed for instance-level concurrent access
• Lots in common with stateless / stateful beans
  >   Client views (No-interface , Local, Remote, Web Service)
  >   CMT / BMT
  >   Container services: timer service, injection, etc.
  >   Method authorization


                                                           26
Simple Singleton
 @Singleton
 public class SharedBean {

     private SharedData shared;

     @PostConstruct private void init() {
       shared = ...;
     }

     public int getXYZ() {
       return shared.xyz;
     }

 }


                                            27
Singleton Client
 @Stateless
 public class FooBean {

     @EJB
     private SharedBean shared;

     public void foo() {
       int xyz = shared.getXYZ();
       ...
     }

 }




                                    28
Singleton Concurrency Options

• Single threaded (default)
  > Container serializes concurrent requests
• Container Managed Concurrency
  > Concurrency via method-level locking metadata
     – Read lock (Shared): allow any number of concurrent accesses
     – Write lock (Exclusive) : ensure single-threaded access
  > Container blocks invocations until they can proceed
     – ...or until app-specified timeout is reached

• Bean Managed Concurrency
  > Like Java Servlet API threading model
                                                               29
Read-Only Singleton with Container
Managed Concurrency
 @Singleton
 public class SharedBean {

     private SharedData shared;

     @Lock(READ)
     public int getXYZ() {
       return shared.xyz;
     }

     ...
 }



                                  30
Read-Mostly Singleton with Container
Managed Concurrency
 @Singleton
 @Lock(READ)
 public class SharedBean {

   private SharedData shared;

   public int getXYZ() {
     return shared.xyz;
   }

   @Lock(WRITE)
   public void update(...) {
     // update shared data
     ...
   }
                                 31
Concurrent Access Timeouts
@Singleton
public class SharedBean {

  private SharedData shared;

  @Lock(READ)
  @AccessTimeout(1000)
  public int getXYZ() {
    return shared.xyz;
  }

  @Lock(WRITE)
  public void update(...) {
    // update shared data
  }
                               32
Read-Mostly Singleton with Bean
Managed Concurrency
 @Singleton
 @ConcurrencyManagement(BEAN)
 public class SharedBean {

   private SharedData shared;

   synchronized public int getXYZ() {
     return shared.xyz;
   }

   synchronized public void update(...) {
     // update shared data
     ...
   }


                                            33
Startup / Shutdown Callbacks
 @Singleton
 @Startup
 public class StartupBean {

   @PostConstruct
   private void onStartup() {
     ...
   }

   @PreDestroy
   private void onShutdown() {
     ...
   }



                                 34
Timer Service Features
• Calendar-based timeout expressions
• Automatic timer creation
• Non-persistent timers




                                       35
Calendar Based Timeouts
• “Cron”-like semantics with improved syntax
• Usable with automatic or programmatic timers
• Named attributes
  > second, minute, hour ( default = “0” )
  > dayOfMonth, month, dayOfWeek, year (default = “*”)




                                                         36
Calendar Based Timeouts
// The last Thursday in November at 2 p.m.
(hour=”14”, dayOfMonth=”Last Thu”, month=”Nov”)

// Every weekday morning at 3:15 a.m.
(minute=”15”, hour=”3”, dayOfWeek=”Mon-Fri”)

// Every five minutes
(minute=”*/5”, hour=”*”)
                                                  37
Expression Attribute Syntax
•   Single value : minute = “30”
•   List : month = “Jan, Jul, Dec”
•   Range : dayOfWeek = “Mon-Fri”
•   Wildcard : hour = “*”
•   Increment : minute = “*/10”




                                     38
Automatic Timer Creation
• Container creates timer automatically upon
  deployment
• Logically equivalent to one createTimer() invocation
• Each automatic timer can have its own timeout
  callback method




                                                   39
Automatic Timer Creation
 @Stateless
 public class BankBean {

     @PersistenceContext EntityManager accountDB;
     @Resource javax.mail.Session mailSession;

     // Callback the 1st of each month at 8 a.m.

     @Schedule(hour=”8”, dayOfMonth=”1”)
     void sendMonthlyBankStatements() {
       ...
     }

 }




                                                    40
Non-persistent Timers
•   Timers without persistent delivery guarantee
•   Only live for duration JVM instance
•   Good fit for Singleton cache updates
•   Better performance for fine-grained timeouts




                                                   41
Non-Persistent Timer Example
 @Singleton public class CacheBean {

     private Cache cache;

     @Schedule(minute=”*/5”,hour=”*”,persistent=false)
     private void updateCache() { ... }

     ...

 }




                                                   42
Simple Asynchrony
• Different styles
  > Local concurrency
     – E.g : break large piece of work into independent tasks
  > Async RPC
• Too difficult with existing APIs
  > JMS API – complex API / lots of configuration
  > Threads – not well integrated with component model
• Approach : integrate asynchronous support directly
  into session bean components

                                                                43
Simple Local Concurrent
Computation
 @Stateless public class DocBean {

     @Resource SessionContext ctx;

     public void processDocument(Document document) {
       DocBean me = ctx.getBusinessObject(DocBean.class);
       me.doAnalysisA(document);
       me.doAnalysisB(document);
     }

     @Asynchronous public void doAnalysisA(Document d) {...}

     @Asynchronous public void doAnalysisB(Document d) {...}

 }


                                                            44
Asynchronous Operation Results --
Client
 @EJB Processor processor;

 Task task = new Task(...);

 Future<int> computeTask = processor.compute(task);

 ...

 int result = computeTask.get();




                                                 45
@Asynchronous on Bean Class
 @Stateless
 public class ProcessorBean implements Processor {

     @PersistenceContext EntityManager db;

     @Asynchronous
     public Future<int> compute(Task t) {

         // perform computation
         int result = ...;

         return new javax.ejb.AsyncResult<int>(result);
     }

 }



                                                          46
@Asynchronous on Interface

 public interface Processor {

     @Asynchronous
     public Future<int> compute(Task t);

 }




                                           47
@Asynchronous on Interface
 @Stateless
 @Local(Processor.class)
 public class ProcessorBean {

     @PersistenceContext EntityManager db;

     public int compute(Task t) {

         // perform computation
         int result = ...;

         return result;
     }

 }



                                             48
Async Behavior
• Transactions
  > No transaction propagation from caller to callee
• Method authorization
  > Works the same as for synchronous invocations
• Exceptions
  > Exception thrown from target invocation available via
    Future<V>.get()
• SessionContext.isCancelled() allows bean to check
  for cancellation during processing

                                                            49
Agenda
•   Introduction
•   Proposed Functionality
•   Summary
•   Q&A




                             50
Summary
• EJB 3.1 Specification (JSR 318)
• Part of Java EETM Platform 6
• Goals
  > Ease-of-use
  > New Features




                                    51
For More Information
• JSR 318 Home : http://jcp.org/en/jsr/detail?id=318
  > Send comments to jsr-318-comments@jcp.org
• Blog : http://blogs.sun.com/kensaks/
• Reference Implementation : GlassFish project V3
  > http://glassfish.dev.java.net
  > ejb@glassfish.dev.java.net




                                                    52
Agenda
•   Introduction
•   Proposed Functionality
•   Summary
•   Q&A




                             53
TM
Enterprise JavaBeans
(EJBTM) 3.1
Kenneth Saks
Senior Staff Engineer
SUN Microsystems

Contenu connexe

Tendances

J2EE - Practical Overview
J2EE - Practical OverviewJ2EE - Practical Overview
J2EE - Practical OverviewSvetlin Nakov
 
Sun Java EE 6 Overview
Sun Java EE 6 OverviewSun Java EE 6 Overview
Sun Java EE 6 Overviewsbobde
 
JSF 2 and beyond: Keeping progress coming
JSF 2 and beyond: Keeping progress comingJSF 2 and beyond: Keeping progress coming
JSF 2 and beyond: Keeping progress comingAndy Schwartz
 
Component Framework Primer for JSF Users
Component Framework Primer for JSF UsersComponent Framework Primer for JSF Users
Component Framework Primer for JSF UsersAndy Schwartz
 
New Features of Java7 SE
New Features of Java7 SENew Features of Java7 SE
New Features of Java7 SEdogangoko
 
Servlet and jsp interview questions
Servlet and jsp interview questionsServlet and jsp interview questions
Servlet and jsp interview questionsSujata Regoti
 
Introduction to JSP
Introduction to JSPIntroduction to JSP
Introduction to JSPFulvio Corno
 
Java EE 7 - Into the Cloud
Java EE 7 - Into the CloudJava EE 7 - Into the Cloud
Java EE 7 - Into the CloudMarkus Eisele
 
JAVA SERVER PAGES
JAVA SERVER PAGESJAVA SERVER PAGES
JAVA SERVER PAGESKalpana T
 
Lecture 6 Web Sockets
Lecture 6   Web SocketsLecture 6   Web Sockets
Lecture 6 Web SocketsFahad Golra
 
Java EE 6 Component Model Explained
Java EE 6 Component Model Explained Java EE 6 Component Model Explained
Java EE 6 Component Model Explained Shreedhar Ganapathy
 
Java EE 6 workshop at Dallas Tech Fest 2011
Java EE 6 workshop at Dallas Tech Fest 2011Java EE 6 workshop at Dallas Tech Fest 2011
Java EE 6 workshop at Dallas Tech Fest 2011Arun Gupta
 
JSF Component Behaviors
JSF Component BehaviorsJSF Component Behaviors
JSF Component BehaviorsAndy Schwartz
 

Tendances (20)

J2EE - Practical Overview
J2EE - Practical OverviewJ2EE - Practical Overview
J2EE - Practical Overview
 
Enterprise JavaBeans(EJB)
Enterprise JavaBeans(EJB)Enterprise JavaBeans(EJB)
Enterprise JavaBeans(EJB)
 
Sun Java EE 6 Overview
Sun Java EE 6 OverviewSun Java EE 6 Overview
Sun Java EE 6 Overview
 
JSF 2 and beyond: Keeping progress coming
JSF 2 and beyond: Keeping progress comingJSF 2 and beyond: Keeping progress coming
JSF 2 and beyond: Keeping progress coming
 
Component Framework Primer for JSF Users
Component Framework Primer for JSF UsersComponent Framework Primer for JSF Users
Component Framework Primer for JSF Users
 
New Features of Java7 SE
New Features of Java7 SENew Features of Java7 SE
New Features of Java7 SE
 
Servlet and jsp interview questions
Servlet and jsp interview questionsServlet and jsp interview questions
Servlet and jsp interview questions
 
Introduction to JSP
Introduction to JSPIntroduction to JSP
Introduction to JSP
 
Java EE 7 - Into the Cloud
Java EE 7 - Into the CloudJava EE 7 - Into the Cloud
Java EE 7 - Into the Cloud
 
Whats New In Java Ee 6
Whats New In Java Ee 6Whats New In Java Ee 6
Whats New In Java Ee 6
 
Jsp
JspJsp
Jsp
 
JSP Directives
JSP DirectivesJSP Directives
JSP Directives
 
Java 7 workshop
Java 7 workshopJava 7 workshop
Java 7 workshop
 
JAVA SERVER PAGES
JAVA SERVER PAGESJAVA SERVER PAGES
JAVA SERVER PAGES
 
Lecture 6 Web Sockets
Lecture 6   Web SocketsLecture 6   Web Sockets
Lecture 6 Web Sockets
 
Jsf presentation
Jsf presentationJsf presentation
Jsf presentation
 
Java EE 6 Component Model Explained
Java EE 6 Component Model Explained Java EE 6 Component Model Explained
Java EE 6 Component Model Explained
 
JSP
JSPJSP
JSP
 
Java EE 6 workshop at Dallas Tech Fest 2011
Java EE 6 workshop at Dallas Tech Fest 2011Java EE 6 workshop at Dallas Tech Fest 2011
Java EE 6 workshop at Dallas Tech Fest 2011
 
JSF Component Behaviors
JSF Component BehaviorsJSF Component Behaviors
JSF Component Behaviors
 

En vedette

Lightweight J2EE development using Spring
Lightweight J2EE development using SpringLightweight J2EE development using Spring
Lightweight J2EE development using Springspringbyexample
 
jVoiD - the enterprise ecommerce Java by Schogini
jVoiD - the enterprise ecommerce Java by SchoginijVoiD - the enterprise ecommerce Java by Schogini
jVoiD - the enterprise ecommerce Java by SchoginiSchogini Systems Pvt Ltd
 
Developing real-time data pipelines with Spring and Kafka
Developing real-time data pipelines with Spring and KafkaDeveloping real-time data pipelines with Spring and Kafka
Developing real-time data pipelines with Spring and Kafkamarius_bogoevici
 
Java EE and Spring Side-by-Side
Java EE and Spring Side-by-SideJava EE and Spring Side-by-Side
Java EE and Spring Side-by-SideReza Rahman
 
Lightweight J2EE development with Spring (special for UADEV)
Lightweight J2EE development with Spring (special for UADEV)Lightweight J2EE development with Spring (special for UADEV)
Lightweight J2EE development with Spring (special for UADEV)springbyexample
 
Fun with EJB 3.1 and Open EJB
Fun with EJB 3.1 and Open EJBFun with EJB 3.1 and Open EJB
Fun with EJB 3.1 and Open EJBArun Gupta
 

En vedette (8)

Lightweight J2EE development using Spring
Lightweight J2EE development using SpringLightweight J2EE development using Spring
Lightweight J2EE development using Spring
 
jVoiD - the enterprise ecommerce Java by Schogini
jVoiD - the enterprise ecommerce Java by SchoginijVoiD - the enterprise ecommerce Java by Schogini
jVoiD - the enterprise ecommerce Java by Schogini
 
EJB 3.1 by Bert Ertman
EJB 3.1 by Bert ErtmanEJB 3.1 by Bert Ertman
EJB 3.1 by Bert Ertman
 
Developing real-time data pipelines with Spring and Kafka
Developing real-time data pipelines with Spring and KafkaDeveloping real-time data pipelines with Spring and Kafka
Developing real-time data pipelines with Spring and Kafka
 
Tu1 1 5l
Tu1 1 5lTu1 1 5l
Tu1 1 5l
 
Java EE and Spring Side-by-Side
Java EE and Spring Side-by-SideJava EE and Spring Side-by-Side
Java EE and Spring Side-by-Side
 
Lightweight J2EE development with Spring (special for UADEV)
Lightweight J2EE development with Spring (special for UADEV)Lightweight J2EE development with Spring (special for UADEV)
Lightweight J2EE development with Spring (special for UADEV)
 
Fun with EJB 3.1 and Open EJB
Fun with EJB 3.1 and Open EJBFun with EJB 3.1 and Open EJB
Fun with EJB 3.1 and Open EJB
 

Similaire à Ejb3 1 Overview Glassfish Webinar 100208

What's New in Enterprise JavaBean Technology ?
What's New in Enterprise JavaBean Technology ?What's New in Enterprise JavaBean Technology ?
What's New in Enterprise JavaBean Technology ?Sanjeeb Sahoo
 
S314168 - What's New in Enterprise Java Bean Technology @ JavaOne Brazil 2010
S314168 - What's New in Enterprise Java Bean Technology @ JavaOne Brazil 2010S314168 - What's New in Enterprise Java Bean Technology @ JavaOne Brazil 2010
S314168 - What's New in Enterprise Java Bean Technology @ JavaOne Brazil 2010Arun Gupta
 
Skillwise EJB3.0 training
Skillwise EJB3.0 trainingSkillwise EJB3.0 training
Skillwise EJB3.0 trainingSkillwise Group
 
Java Enterprise Edition 6 Overview
Java Enterprise Edition 6 OverviewJava Enterprise Edition 6 Overview
Java Enterprise Edition 6 OverviewEugene Bogaart
 
EJB et WS (Montreal JUG - 12 mai 2011)
EJB et WS (Montreal JUG - 12 mai 2011)EJB et WS (Montreal JUG - 12 mai 2011)
EJB et WS (Montreal JUG - 12 mai 2011)Montreal JUG
 
JEE Course - EJB
JEE Course - EJBJEE Course - EJB
JEE Course - EJBodedns
 
Real world java_ee_patterns
Real world java_ee_patternsReal world java_ee_patterns
Real world java_ee_patternsAlassane Diallo
 
Enterprise Java Beans( E)
Enterprise  Java  Beans( E)Enterprise  Java  Beans( E)
Enterprise Java Beans( E)vikram singh
 
Enterprise java beans(ejb)
Enterprise java beans(ejb)Enterprise java beans(ejb)
Enterprise java beans(ejb)vikram singh
 
Enterprise java beans(ejb) update 2
Enterprise java beans(ejb) update 2Enterprise java beans(ejb) update 2
Enterprise java beans(ejb) update 2vikram singh
 
Javascript as a target language - GWT KickOff - Part 2/2
Javascript as a target language - GWT KickOff - Part 2/2Javascript as a target language - GWT KickOff - Part 2/2
Javascript as a target language - GWT KickOff - Part 2/2JooinK
 
EJB 3.2 - Java EE 7 - Java One Hyderabad 2012
EJB 3.2 - Java EE 7 - Java One Hyderabad 2012EJB 3.2 - Java EE 7 - Java One Hyderabad 2012
EJB 3.2 - Java EE 7 - Java One Hyderabad 2012Jagadish Prasath
 

Similaire à Ejb3 1 Overview Glassfish Webinar 100208 (20)

EJB 3.1 and GlassFish v3 Prelude
EJB 3.1 and GlassFish v3 PreludeEJB 3.1 and GlassFish v3 Prelude
EJB 3.1 and GlassFish v3 Prelude
 
What's New in Enterprise JavaBean Technology ?
What's New in Enterprise JavaBean Technology ?What's New in Enterprise JavaBean Technology ?
What's New in Enterprise JavaBean Technology ?
 
J2 Ee Overview
J2 Ee OverviewJ2 Ee Overview
J2 Ee Overview
 
S314168 - What's New in Enterprise Java Bean Technology @ JavaOne Brazil 2010
S314168 - What's New in Enterprise Java Bean Technology @ JavaOne Brazil 2010S314168 - What's New in Enterprise Java Bean Technology @ JavaOne Brazil 2010
S314168 - What's New in Enterprise Java Bean Technology @ JavaOne Brazil 2010
 
Skillwise EJB3.0 training
Skillwise EJB3.0 trainingSkillwise EJB3.0 training
Skillwise EJB3.0 training
 
Java Enterprise Edition 6 Overview
Java Enterprise Edition 6 OverviewJava Enterprise Edition 6 Overview
Java Enterprise Edition 6 Overview
 
GlassFish v3 : En Route Java EE 6
GlassFish v3 : En Route Java EE 6GlassFish v3 : En Route Java EE 6
GlassFish v3 : En Route Java EE 6
 
Seam Glassfish Perspective
Seam Glassfish PerspectiveSeam Glassfish Perspective
Seam Glassfish Perspective
 
Java EE 6 Aquarium Paris
Java EE 6 Aquarium ParisJava EE 6 Aquarium Paris
Java EE 6 Aquarium Paris
 
Introduction To Web Beans
Introduction To Web BeansIntroduction To Web Beans
Introduction To Web Beans
 
EJB et WS (Montreal JUG - 12 mai 2011)
EJB et WS (Montreal JUG - 12 mai 2011)EJB et WS (Montreal JUG - 12 mai 2011)
EJB et WS (Montreal JUG - 12 mai 2011)
 
JEE Course - EJB
JEE Course - EJBJEE Course - EJB
JEE Course - EJB
 
Java EE 6
Java EE 6Java EE 6
Java EE 6
 
JBoss AS7 OSDC 2011
JBoss AS7 OSDC 2011JBoss AS7 OSDC 2011
JBoss AS7 OSDC 2011
 
Real world java_ee_patterns
Real world java_ee_patternsReal world java_ee_patterns
Real world java_ee_patterns
 
Enterprise Java Beans( E)
Enterprise  Java  Beans( E)Enterprise  Java  Beans( E)
Enterprise Java Beans( E)
 
Enterprise java beans(ejb)
Enterprise java beans(ejb)Enterprise java beans(ejb)
Enterprise java beans(ejb)
 
Enterprise java beans(ejb) update 2
Enterprise java beans(ejb) update 2Enterprise java beans(ejb) update 2
Enterprise java beans(ejb) update 2
 
Javascript as a target language - GWT KickOff - Part 2/2
Javascript as a target language - GWT KickOff - Part 2/2Javascript as a target language - GWT KickOff - Part 2/2
Javascript as a target language - GWT KickOff - Part 2/2
 
EJB 3.2 - Java EE 7 - Java One Hyderabad 2012
EJB 3.2 - Java EE 7 - Java One Hyderabad 2012EJB 3.2 - Java EE 7 - Java One Hyderabad 2012
EJB 3.2 - Java EE 7 - Java One Hyderabad 2012
 

Plus de Eduardo Pelegri-Llopart

Pelegri Desarrollando en una nueva era de software
Pelegri   Desarrollando en una nueva era de software Pelegri   Desarrollando en una nueva era de software
Pelegri Desarrollando en una nueva era de software Eduardo Pelegri-Llopart
 
Market trends in IT - exchange cala - October 2015
Market trends in IT - exchange cala - October 2015Market trends in IT - exchange cala - October 2015
Market trends in IT - exchange cala - October 2015Eduardo Pelegri-Llopart
 
The impact of IOT - exchange cala - 2015
The impact of IOT - exchange cala - 2015The impact of IOT - exchange cala - 2015
The impact of IOT - exchange cala - 2015Eduardo Pelegri-Llopart
 
What is IoT and how Modulus and Pacific can Help - Featuring Node.js and Roll...
What is IoT and how Modulus and Pacific can Help - Featuring Node.js and Roll...What is IoT and how Modulus and Pacific can Help - Featuring Node.js and Roll...
What is IoT and how Modulus and Pacific can Help - Featuring Node.js and Roll...Eduardo Pelegri-Llopart
 
What is the Internet of Things and How it Impacts You
What is the Internet of Things and How it Impacts YouWhat is the Internet of Things and How it Impacts You
What is the Internet of Things and How it Impacts YouEduardo Pelegri-Llopart
 
Ehcache Architecture, Features And Usage Patterns
Ehcache Architecture, Features And Usage PatternsEhcache Architecture, Features And Usage Patterns
Ehcache Architecture, Features And Usage PatternsEduardo Pelegri-Llopart
 

Plus de Eduardo Pelegri-Llopart (20)

Juggling at freenome
Juggling   at freenomeJuggling   at freenome
Juggling at freenome
 
Csumb capstone-fall2016
Csumb capstone-fall2016Csumb capstone-fall2016
Csumb capstone-fall2016
 
Digital activitymanagement
Digital activitymanagementDigital activitymanagement
Digital activitymanagement
 
Progress next iot_pelegri
Progress next iot_pelegriProgress next iot_pelegri
Progress next iot_pelegri
 
Pelegri Desarrollando en una nueva era de software
Pelegri   Desarrollando en una nueva era de software Pelegri   Desarrollando en una nueva era de software
Pelegri Desarrollando en una nueva era de software
 
Market trends in IT - exchange cala - October 2015
Market trends in IT - exchange cala - October 2015Market trends in IT - exchange cala - October 2015
Market trends in IT - exchange cala - October 2015
 
The impact of IOT - exchange cala - 2015
The impact of IOT - exchange cala - 2015The impact of IOT - exchange cala - 2015
The impact of IOT - exchange cala - 2015
 
IOT - Presentation to PEP @ Progress
IOT - Presentation to PEP @ ProgressIOT - Presentation to PEP @ Progress
IOT - Presentation to PEP @ Progress
 
Node.js as an IOT Bridge
Node.js as an IOT BridgeNode.js as an IOT Bridge
Node.js as an IOT Bridge
 
What is IoT and how Modulus and Pacific can Help - Featuring Node.js and Roll...
What is IoT and how Modulus and Pacific can Help - Featuring Node.js and Roll...What is IoT and how Modulus and Pacific can Help - Featuring Node.js and Roll...
What is IoT and how Modulus and Pacific can Help - Featuring Node.js and Roll...
 
What is the Internet of Things and How it Impacts You
What is the Internet of Things and How it Impacts YouWhat is the Internet of Things and How it Impacts You
What is the Internet of Things and How it Impacts You
 
Community Update 25 Mar2010 - English
Community Update 25 Mar2010 - EnglishCommunity Update 25 Mar2010 - English
Community Update 25 Mar2010 - English
 
GlassFish Community Update 25 Mar2010
GlassFish Community Update 25 Mar2010GlassFish Community Update 25 Mar2010
GlassFish Community Update 25 Mar2010
 
Glass Fish Portfolio C1 West V3.Mini
Glass Fish Portfolio C1 West V3.MiniGlass Fish Portfolio C1 West V3.Mini
Glass Fish Portfolio C1 West V3.Mini
 
Virtual Box Aquarium May09
Virtual Box Aquarium May09Virtual Box Aquarium May09
Virtual Box Aquarium May09
 
Ehcache Architecture, Features And Usage Patterns
Ehcache Architecture, Features And Usage PatternsEhcache Architecture, Features And Usage Patterns
Ehcache Architecture, Features And Usage Patterns
 
OpenDS Primer Aquarium
OpenDS Primer AquariumOpenDS Primer Aquarium
OpenDS Primer Aquarium
 
Fuji Overview
Fuji OverviewFuji Overview
Fuji Overview
 
Nuxeo 5.2 Glassfish
Nuxeo 5.2 GlassfishNuxeo 5.2 Glassfish
Nuxeo 5.2 Glassfish
 
OpenSSO Deployments
OpenSSO DeploymentsOpenSSO Deployments
OpenSSO Deployments
 

Dernier

How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 

Dernier (20)

How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 

Ejb3 1 Overview Glassfish Webinar 100208

  • 1. TM Enterprise JavaBeans (EJBTM) 3.1 Kenneth Saks Senior Staff Engineer SUN Microsystems
  • 2. Agenda • Background • Proposed Functionality • Summary • Q&A 2
  • 3. EJB 3.0 Specification (JSR 220) • Features > Simplified EJB API > Java Platform Persistence API • Focus on ease-of-use > Annotations > Intelligent defaults > Fewer classes needed • Very well received within the community > But... more work is needed 3
  • 4. EJB 3.1 Specification • Goals > Continued focus on ease-of-use > New features • JSR (Java Specification Request) 318 > Launched in August 2007 – Java Persistence API will evolve separately ( JSR 317 ) > Early Draft February 2008 > Public Draft October 2008 • Caveat – APIs still subject to change 4
  • 5. Agenda • Introduction • Proposed Functionality • Summary • Q&A 5
  • 6. Ease of Use Improvements • Optional Local Business Interfaces • Simplified Packaging • EJB “Lite” • Portable Global JNDI Names • Simplified Unit Testing 6
  • 7. Session Bean with Local Business Interface HelloBean Client <<interface> com.acme.Hello @EJB String sayHello() private Hello h; ... h.sayHello(); com.acme.HelloBean public String sayHello() { ... } 7
  • 8. Optional Local Business Interfaces • Sometimes local business interface isn't needed • Better to completely remove interface from developer's view than to generate it • Result : “no-interface” view > Just a bean class > public bean class methods exposed to client > Same behavior and client programming model as Local view – Client acquires an EJB component reference instead of calling new() 8
  • 9. Session Bean with “No-interface” View @Stateless public class HelloBean { public String sayHello(String msg) { return “Hello “ + msg; } } 9
  • 10. No-interface View Client @EJB HelloBean h; ... h.sayHello(“bob”); 10
  • 11. Web/EJB Application in TM Java EE Platform 5 foo.ear foo.ear lib/foo_common.jar foo_web.war WEB-INF/web.xml com/acme/Foo.class WEB-INF/classes/ com/acme/FooServlet.class foo_web.war WEB-INF/classes com/acme/Foo.class OR WEB-INF/web.xml WEB-INF/classes/ com/acme/FooServlet.class foo_ejb.jar com/acme/FooBean.class foo_ejb.jar com/acme/Foo.class com/acme/FooBean.class 11
  • 12. Web/EJB Application in TM Java EE Platform 6 foo.war WEB-INF/classes/ com/acme/FooServlet.class WEB-INF/classes/ com/acme/FooBean.class 12
  • 13. Simplified Packaging • Goal is to remove an artificial packaging restriction > Not to create a new flavor of EJB component • EJB component behavior is independent of packaging > One exception : module-level vs. component-level environment • No new restrictions placed on .war > Deploy .war stand-alone OR within an .ear 13
  • 14. EJB “Lite” • Small subset of EJB 3.1 API for use in Web Profile • Broaden the availability of EJB technology > Without losing portability • Same exact Lite application can be deployed to Web Profile and Full Profile > Thanks to simplified .war packaging • Open issue : whether Web Profile will require EJB Lite 14
  • 15. “Lite” vs. Full Functionality Lite Full = Lite + the following: • Local Session Beans • Message Driven Beans • Annotations / ejb- • EJB Web Service jar.xml Endpoints • CMT / BMT • RMI-IIOP • Declarative Security Interoperability • Interceptors • 2.x / 3.x Remote view • 2.x Local view • (Also requires JPA 2.0 • Timer Service API / JTA 1.1 API ) • CMP / BMP 15
  • 16. Session Bean Exposing a Remote View @Stateless @Remote(Hello.class) public class HelloBean implements Hello { public String sayHello(String msg) { return “Hello “ + msg; } } 16
  • 17. Remote Clients // Remote client in a Java EE container @EJB Hello hello; // Remote client in a Java SE environment Hello hello = (Hello) new InitialContext().lookup(???); Question : How does the caller find the target EJB component? 17
  • 18. Problems with “Global” JNDI Names • Not portable > Global JNDI namespace is not defined in Java EE platform specification > Vendor-specific configuration needed for each deployment • No standard syntax > Can names contain : “.”, “_”, “/” ? • Not clear which resources have them > Local interfaces? 18
  • 19. Portable Global JNDI Names “java:global[/<app-name>]/<module- name>/<bean-name>” // Client in a Java EE container @EJB(mappedName= ”java:global/hello/HelloBean”) Hello hello; // Client in a Java SE environment Hello hello = (Hello) new InitialContext() lookup(“java:global/hello/HelloBean”); 19
  • 20. EJB Component Testing • It's too hard to test EJB components, especially the Local view > Forced to go through Remote facade or Web tier > Separate JVM™ instances needed for server and client • Support for running in Java SE exists, but... > Not present in all implementations > No standard API for bootstrapping, component discovery, shutdown etc. 20
  • 21. Example: No-interface Stateless Session Bean @Stateless public class BankBean { @PersistenceContext EntityManager accountDB; public String createAccount(AccountDetails d) { ... } public void removeAccount(String accountID) { ... } } 21
  • 22. Example: Embeddable API public class BankTester { public static void main(String[] args) { EJBContainer container = EJBContainer.createEJBContainer(); // Acquire EJB component reference BankBean bank = (BankBean)container.getContext(). lookup(“java:global/bank/BankBean”); testBank(bank); ... container.close(); } 22
  • 23. Example : Embeddable API (cont.) % java -classpath bankClient.jar : bank.jar : javaee.jar : <vendor_rt>.jar com.acme.BankTester 23
  • 24. Embeddable API • Execute enterprise beans in a Java SE environment • “Single application” model • Same EJB component behavior / lifecycle as server-side > CMT, injection, threading guarantees, etc. • Only EJB “Lite” functionality required to be available 24
  • 25. New Features • Singletons • Application startup / shutdown callbacks • Calendar-based timer expressions • Automatic timer creation • Simple Asynchrony 25
  • 26. Singletons • New session bean component type > One singleton bean instance per application per JVM > Provides easy sharing of state within application > Designed for instance-level concurrent access • Lots in common with stateless / stateful beans > Client views (No-interface , Local, Remote, Web Service) > CMT / BMT > Container services: timer service, injection, etc. > Method authorization 26
  • 27. Simple Singleton @Singleton public class SharedBean { private SharedData shared; @PostConstruct private void init() { shared = ...; } public int getXYZ() { return shared.xyz; } } 27
  • 28. Singleton Client @Stateless public class FooBean { @EJB private SharedBean shared; public void foo() { int xyz = shared.getXYZ(); ... } } 28
  • 29. Singleton Concurrency Options • Single threaded (default) > Container serializes concurrent requests • Container Managed Concurrency > Concurrency via method-level locking metadata – Read lock (Shared): allow any number of concurrent accesses – Write lock (Exclusive) : ensure single-threaded access > Container blocks invocations until they can proceed – ...or until app-specified timeout is reached • Bean Managed Concurrency > Like Java Servlet API threading model 29
  • 30. Read-Only Singleton with Container Managed Concurrency @Singleton public class SharedBean { private SharedData shared; @Lock(READ) public int getXYZ() { return shared.xyz; } ... } 30
  • 31. Read-Mostly Singleton with Container Managed Concurrency @Singleton @Lock(READ) public class SharedBean { private SharedData shared; public int getXYZ() { return shared.xyz; } @Lock(WRITE) public void update(...) { // update shared data ... } 31
  • 32. Concurrent Access Timeouts @Singleton public class SharedBean { private SharedData shared; @Lock(READ) @AccessTimeout(1000) public int getXYZ() { return shared.xyz; } @Lock(WRITE) public void update(...) { // update shared data } 32
  • 33. Read-Mostly Singleton with Bean Managed Concurrency @Singleton @ConcurrencyManagement(BEAN) public class SharedBean { private SharedData shared; synchronized public int getXYZ() { return shared.xyz; } synchronized public void update(...) { // update shared data ... } 33
  • 34. Startup / Shutdown Callbacks @Singleton @Startup public class StartupBean { @PostConstruct private void onStartup() { ... } @PreDestroy private void onShutdown() { ... } 34
  • 35. Timer Service Features • Calendar-based timeout expressions • Automatic timer creation • Non-persistent timers 35
  • 36. Calendar Based Timeouts • “Cron”-like semantics with improved syntax • Usable with automatic or programmatic timers • Named attributes > second, minute, hour ( default = “0” ) > dayOfMonth, month, dayOfWeek, year (default = “*”) 36
  • 37. Calendar Based Timeouts // The last Thursday in November at 2 p.m. (hour=”14”, dayOfMonth=”Last Thu”, month=”Nov”) // Every weekday morning at 3:15 a.m. (minute=”15”, hour=”3”, dayOfWeek=”Mon-Fri”) // Every five minutes (minute=”*/5”, hour=”*”) 37
  • 38. Expression Attribute Syntax • Single value : minute = “30” • List : month = “Jan, Jul, Dec” • Range : dayOfWeek = “Mon-Fri” • Wildcard : hour = “*” • Increment : minute = “*/10” 38
  • 39. Automatic Timer Creation • Container creates timer automatically upon deployment • Logically equivalent to one createTimer() invocation • Each automatic timer can have its own timeout callback method 39
  • 40. Automatic Timer Creation @Stateless public class BankBean { @PersistenceContext EntityManager accountDB; @Resource javax.mail.Session mailSession; // Callback the 1st of each month at 8 a.m. @Schedule(hour=”8”, dayOfMonth=”1”) void sendMonthlyBankStatements() { ... } } 40
  • 41. Non-persistent Timers • Timers without persistent delivery guarantee • Only live for duration JVM instance • Good fit for Singleton cache updates • Better performance for fine-grained timeouts 41
  • 42. Non-Persistent Timer Example @Singleton public class CacheBean { private Cache cache; @Schedule(minute=”*/5”,hour=”*”,persistent=false) private void updateCache() { ... } ... } 42
  • 43. Simple Asynchrony • Different styles > Local concurrency – E.g : break large piece of work into independent tasks > Async RPC • Too difficult with existing APIs > JMS API – complex API / lots of configuration > Threads – not well integrated with component model • Approach : integrate asynchronous support directly into session bean components 43
  • 44. Simple Local Concurrent Computation @Stateless public class DocBean { @Resource SessionContext ctx; public void processDocument(Document document) { DocBean me = ctx.getBusinessObject(DocBean.class); me.doAnalysisA(document); me.doAnalysisB(document); } @Asynchronous public void doAnalysisA(Document d) {...} @Asynchronous public void doAnalysisB(Document d) {...} } 44
  • 45. Asynchronous Operation Results -- Client @EJB Processor processor; Task task = new Task(...); Future<int> computeTask = processor.compute(task); ... int result = computeTask.get(); 45
  • 46. @Asynchronous on Bean Class @Stateless public class ProcessorBean implements Processor { @PersistenceContext EntityManager db; @Asynchronous public Future<int> compute(Task t) { // perform computation int result = ...; return new javax.ejb.AsyncResult<int>(result); } } 46
  • 47. @Asynchronous on Interface public interface Processor { @Asynchronous public Future<int> compute(Task t); } 47
  • 48. @Asynchronous on Interface @Stateless @Local(Processor.class) public class ProcessorBean { @PersistenceContext EntityManager db; public int compute(Task t) { // perform computation int result = ...; return result; } } 48
  • 49. Async Behavior • Transactions > No transaction propagation from caller to callee • Method authorization > Works the same as for synchronous invocations • Exceptions > Exception thrown from target invocation available via Future<V>.get() • SessionContext.isCancelled() allows bean to check for cancellation during processing 49
  • 50. Agenda • Introduction • Proposed Functionality • Summary • Q&A 50
  • 51. Summary • EJB 3.1 Specification (JSR 318) • Part of Java EETM Platform 6 • Goals > Ease-of-use > New Features 51
  • 52. For More Information • JSR 318 Home : http://jcp.org/en/jsr/detail?id=318 > Send comments to jsr-318-comments@jcp.org • Blog : http://blogs.sun.com/kensaks/ • Reference Implementation : GlassFish project V3 > http://glassfish.dev.java.net > ejb@glassfish.dev.java.net 52
  • 53. Agenda • Introduction • Proposed Functionality • Summary • Q&A 53
  • 54. TM Enterprise JavaBeans (EJBTM) 3.1 Kenneth Saks Senior Staff Engineer SUN Microsystems