SlideShare ist ein Scribd-Unternehmen logo
1 von 26
Downloaden Sie, um offline zu lesen
<Insert Picture Here>




What's New in Enterprise JavaBean Technology
Arun Gupta, Java EE & GlassFish Guy
blogs.sun.com/arungupta, @arungupta
Beijing 2010
December 13–16, 2010




                       2
The following is intended to outline our general
product direction. It is intended for information
purposes only, and may not be incorporated into any
contract. It is not a commitment to deliver any
material, code, or functionality, and should not be
relied upon in making purchasing decisions.
The development, release, and timing of any
features or functionality described for Oracle’s
products remains at the sole discretion of Oracle.




                                                      3
Agenda


• Introduction               <Insert Picture Here>


• Ease of Use Improvements
• New Functionality




                                                4
EJB 3.1 Specification

• Goals
   – Continued focus on ease-of-use
   – New features
• JSR (Java Specification Request) 318
   – Expert Group Formed – August 2007
   – Public Draft – October 2008
   – Proposed Final Draft – March 2009
   – Final Specification – December 2009




                                           5
Ease of Use Improvements

• Optional Local Business Interfaces
• Simplified Packaging
• EJB 3.1 “Lite” API
• Portable Global JNDI Names
• Simple Component Testing




                                       6
Session Bean
With “No-interface” View




@Stateless
public class HelloBean {

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




                                           7
No-interface View Client


@EJB HelloBean h;

...

h.sayHello(“bob”);




                           8
TM
Java             EE Platform 5 Packaging


          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              OR   WEB-INF/web.xml
 com/acme/Foo.class               WEB-INF/classes/
foo_ejb.jar                        com/acme/FooServlet.class

com/acme/FooBean.class            foo_ejb.jar
com/acme/Foo.class                com/acme/FooBean.class




                                                               9
Simplified Packaging



                foo.war
        WEB-INF/classes/com/acme/
         FooServlet.class
         FooBean.class




                                    10
EJB 3.1 “Lite”




                 11
Portable EJB JNDI Names

Each session bean gets the following entries :

• Globally unique name
java:global[/<app-name>]/<module-name>/<ejb-
name>

• Unique name within same application
java:app/<module-name>/<ejb-name>

• Unique name within defining module
java:module/<ejb-name>


                                                 12
Session Bean

@Stateless
public class HelloBean implements Hello {
    public String sayHello(String msg) {
        return “Hello “ + msg;
    }
}


If deployed as hello.jar, JNDI entries are:

java:global/hello/HelloBean
java:app/hello/HelloBean
java:module/HelloBean


                                              13
Simple Testing : Session Bean

@Stateless
@Local(Bank.class)
public class BankBean implements Bank {


 @PersistenceContext EntityManager accountDB;


 public String createAccount(AcctDetails d)
  { … }


 public void removeAccount(String acctID)
  { … }



                                                14
Embeddable API

public class BankTester {
 public static void main(String[] args) {


   EJBContainer container =
      EJBContainer.createEJBContainer();


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


   testAccountCreation(bank);
    container.close();



                                                15
Test Client Execution


% java -classpath bankClient.jar :
                  bank.jar :
                  javaee.jar :
                  <vendor_rt>.jar


                  com.acme.BankTester




                                        16
New Features

• Singletons
• Startup / Shutdown callbacks
• Automatic timer creation
  – Cron-like syntax
• Asynchronous session bean invocations




                                          17
Singleton

@Singleton
public class SharedBean {


 private SharedData shared;


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


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


                              18
Singleton Concurrency Options

• Single threaded (default)
   – For consistency with all existing bean types
• Container Managed Concurrency
   – Control access via method-level locking metadata
• Bean Managed Concurrency
   – All concurrent invocations have access to bean instance




                                                               19
Startup / Shutdown Callbacks

@Singleton
@Startup
public class StartupBean {


    @PostConstruct
    private void onStartup() { … }


    @PreDestroy
    private void onShutdown() { … }


}



                                      20
Timers

• Automatically created EJB Timers
• Calendar-based Timers – cron like semantics
 – Every Mon & Wed midnight
   @Schedule(dayOfWeek=”Mon,Wed”)
 – 2pm on Last Thur of Nov of every year
   (hour=”14”, dayOfMonth=”Last Thu”,
   month=”Nov”)
 – Every 5 minutes of every hour
   (minute=”*/5”, hour=”*”)
 – Every 10 seconds starting at 30
   (second=”30/10”)
 – Every 14th minute within the hour, for the hours 1 and 2 am
   (minute=”*/14”, hour=”1,2”)
                                                            21
Automatic Timer Creation

@Stateless
public class BankBean {


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


    // Callback the last day of each month at 8 a.m.


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


                                                       22
Asynchronous Session Beans

• Control returns to the client before the container
      dispatches invocation to a bean instance
•   @Asynchronous – method or class
•   Return type – void or Future<V>
•   “Fire and and Forget” or async results via
      Future<V>
•   Best effort delivery – persistent delivery
      guarantees are not required by spec
•   Transaction context does not propagate
    – REQUIRED → REQUIRED_NEW
• Security principal propagates
                                                       23
Asynchronous Session Beans
Code Sample
 @Stateless
 @Asynchronous
 public class SimpleAsyncEJB {
     public Future<Integer> addNumbers(int n1, int n2) {
         Integer result;

             result = n1 + n2;
             try {
                 // simulate JPA queries + reading file system
                 Thread.currentThread().sleep(2000);
             } catch (InterruptedException ex) {
                 ex.printStackTrace();
             }

             return new AsyncResult(result);
       }
 }

http://blogs.sun.com/arungupta/entry/totd_137_asynchronous_ejb_a


                                                                   24
References


• glassfish.org
• blogs.sun.com/theaquarium
• youtube.com/user/GlassFishVideos
• facebook.com/glassfish
• Follow @glassfish




                                     25
<Insert Picture Here>




What's New in Enterprise JavaBean Technology
Arun Gupta, Java EE & GlassFish Guy
blogs.sun.com/arungupta, @arungupta

Weitere ähnliche Inhalte

Was ist angesagt?

Introduction to OSGi (Tokyo JUG)
Introduction to OSGi (Tokyo JUG)Introduction to OSGi (Tokyo JUG)
Introduction to OSGi (Tokyo JUG)
njbartlett
 
Apache DeltaSpike
Apache DeltaSpikeApache DeltaSpike
Apache DeltaSpike
os890
 

Was ist angesagt? (20)

50 features of Java EE 7 in 50 minutes at Geecon 2014
50 features of Java EE 7 in 50 minutes at Geecon 201450 features of Java EE 7 in 50 minutes at Geecon 2014
50 features of Java EE 7 in 50 minutes at Geecon 2014
 
Using Java from Ruby with JRuby IRB
Using Java from Ruby with JRuby IRBUsing Java from Ruby with JRuby IRB
Using Java from Ruby with JRuby IRB
 
Introduction to OSGi (Tokyo JUG)
Introduction to OSGi (Tokyo JUG)Introduction to OSGi (Tokyo JUG)
Introduction to OSGi (Tokyo JUG)
 
Web application development using Play Framework (with Java)
Web application development using Play Framework (with Java)Web application development using Play Framework (with Java)
Web application development using Play Framework (with Java)
 
OpenWebBeans and DeltaSpike at ApacheCon
OpenWebBeans and DeltaSpike at ApacheConOpenWebBeans and DeltaSpike at ApacheCon
OpenWebBeans and DeltaSpike at ApacheCon
 
50 features of Java EE 7 in 50 minutes at JavaZone 2014
50 features of Java EE 7 in 50 minutes at JavaZone 201450 features of Java EE 7 in 50 minutes at JavaZone 2014
50 features of Java EE 7 in 50 minutes at JavaZone 2014
 
Java Servlet
Java Servlet Java Servlet
Java Servlet
 
Java ain't scary - introducing Java to PL/SQL Developers
Java ain't scary - introducing Java to PL/SQL DevelopersJava ain't scary - introducing Java to PL/SQL Developers
Java ain't scary - introducing Java to PL/SQL Developers
 
Groovy Ecosystem - JFokus 2011 - Guillaume Laforge
Groovy Ecosystem - JFokus 2011 - Guillaume LaforgeGroovy Ecosystem - JFokus 2011 - Guillaume Laforge
Groovy Ecosystem - JFokus 2011 - Guillaume Laforge
 
Make JSF more type-safe with CDI and MyFaces CODI
Make JSF more type-safe with CDI and MyFaces CODIMake JSF more type-safe with CDI and MyFaces CODI
Make JSF more type-safe with CDI and MyFaces CODI
 
Play framework productivity formula
Play framework   productivity formula Play framework   productivity formula
Play framework productivity formula
 
Threads v3
Threads v3Threads v3
Threads v3
 
JEE Programming - 01 Introduction
JEE Programming - 01 IntroductionJEE Programming - 01 Introduction
JEE Programming - 01 Introduction
 
Java Servlets & JSP
Java Servlets & JSPJava Servlets & JSP
Java Servlets & JSP
 
Intsllation & 1st program nodejs
Intsllation & 1st program nodejsIntsllation & 1st program nodejs
Intsllation & 1st program nodejs
 
How to cuddle your EJBs, Carlo de Wolf
How to cuddle your EJBs, Carlo de WolfHow to cuddle your EJBs, Carlo de Wolf
How to cuddle your EJBs, Carlo de Wolf
 
Apache DeltaSpike
Apache DeltaSpikeApache DeltaSpike
Apache DeltaSpike
 
Play Framework and Activator
Play Framework and ActivatorPlay Framework and Activator
Play Framework and Activator
 
Java EE 7 - Into the Cloud
Java EE 7 - Into the CloudJava EE 7 - Into the Cloud
Java EE 7 - Into the Cloud
 
Java7 - Top 10 Features
Java7 - Top 10 FeaturesJava7 - Top 10 Features
Java7 - Top 10 Features
 

Ähnlich wie S314168 - What's New in Enterprise Java Bean Technology @ JavaOne Brazil 2010

J2EE - Practical Overview
J2EE - Practical OverviewJ2EE - Practical Overview
J2EE - Practical Overview
Svetlin Nakov
 

Ähnlich wie S314168 - What's New in Enterprise Java Bean Technology @ JavaOne Brazil 2010 (20)

What to expect from Java 9
What to expect from Java 9What to expect from Java 9
What to expect from Java 9
 
Introduction to EJB
Introduction to EJBIntroduction to EJB
Introduction to EJB
 
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)
 
Ejb3 1 Overview Glassfish Webinar 100208
Ejb3 1 Overview Glassfish Webinar 100208Ejb3 1 Overview Glassfish Webinar 100208
Ejb3 1 Overview Glassfish Webinar 100208
 
New Features Of JDK 7
New Features Of JDK 7New Features Of JDK 7
New Features Of JDK 7
 
JUnit5 and TestContainers
JUnit5 and TestContainersJUnit5 and TestContainers
JUnit5 and TestContainers
 
Java Course 14: Beans, Applets, GUI
Java Course 14: Beans, Applets, GUIJava Course 14: Beans, Applets, GUI
Java Course 14: Beans, Applets, GUI
 
J2 Ee Overview
J2 Ee OverviewJ2 Ee Overview
J2 Ee Overview
 
Java 7 Whats New(), Whats Next() from Oredev
Java 7 Whats New(), Whats Next() from OredevJava 7 Whats New(), Whats Next() from Oredev
Java 7 Whats New(), Whats Next() from Oredev
 
Java Future S Ritter
Java Future S RitterJava Future S Ritter
Java Future S Ritter
 
Back to the future with Java 7 (Geekout June/2011)
Back to the future with Java 7 (Geekout June/2011)Back to the future with Java 7 (Geekout June/2011)
Back to the future with Java 7 (Geekout June/2011)
 
Skillwise EJB3.0 training
Skillwise EJB3.0 trainingSkillwise EJB3.0 training
Skillwise EJB3.0 training
 
Level Up Your Integration Testing With Testcontainers
Level Up Your Integration Testing With TestcontainersLevel Up Your Integration Testing With Testcontainers
Level Up Your Integration Testing With Testcontainers
 
Lecture 8 Enterprise Java Beans (EJB)
Lecture 8  Enterprise Java Beans (EJB)Lecture 8  Enterprise Java Beans (EJB)
Lecture 8 Enterprise Java Beans (EJB)
 
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
 
J2EE - Practical Overview
J2EE - Practical OverviewJ2EE - Practical Overview
J2EE - Practical Overview
 
Java EE web project introduction
Java EE web project introductionJava EE web project introduction
Java EE web project introduction
 
Micronaut Deep Dive - Devnexus 2019
Micronaut Deep Dive - Devnexus 2019Micronaut Deep Dive - Devnexus 2019
Micronaut Deep Dive - Devnexus 2019
 
What is Java Technology (An introduction with comparision of .net coding)
What is Java Technology (An introduction with comparision of .net coding)What is Java Technology (An introduction with comparision of .net coding)
What is Java Technology (An introduction with comparision of .net coding)
 
The Java EE 6 platform
The Java EE 6 platformThe Java EE 6 platform
The Java EE 6 platform
 

Mehr von Arun Gupta

Mehr von Arun Gupta (20)

5 Skills To Force Multiply Technical Talents.pdf
5 Skills To Force Multiply Technical Talents.pdf5 Skills To Force Multiply Technical Talents.pdf
5 Skills To Force Multiply Technical Talents.pdf
 
Machine Learning using Kubernetes - AI Conclave 2019
Machine Learning using Kubernetes - AI Conclave 2019Machine Learning using Kubernetes - AI Conclave 2019
Machine Learning using Kubernetes - AI Conclave 2019
 
Machine Learning using Kubeflow and Kubernetes
Machine Learning using Kubeflow and KubernetesMachine Learning using Kubeflow and Kubernetes
Machine Learning using Kubeflow and Kubernetes
 
Secure and Fast microVM for Serverless Computing using Firecracker
Secure and Fast microVM for Serverless Computing using FirecrackerSecure and Fast microVM for Serverless Computing using Firecracker
Secure and Fast microVM for Serverless Computing using Firecracker
 
Building Java in the Open - j.Day at OSCON 2019
Building Java in the Open - j.Day at OSCON 2019Building Java in the Open - j.Day at OSCON 2019
Building Java in the Open - j.Day at OSCON 2019
 
Why Amazon Cares about Open Source
Why Amazon Cares about Open SourceWhy Amazon Cares about Open Source
Why Amazon Cares about Open Source
 
Machine learning using Kubernetes
Machine learning using KubernetesMachine learning using Kubernetes
Machine learning using Kubernetes
 
Building Cloud Native Applications
Building Cloud Native ApplicationsBuilding Cloud Native Applications
Building Cloud Native Applications
 
Chaos Engineering with Kubernetes
Chaos Engineering with KubernetesChaos Engineering with Kubernetes
Chaos Engineering with Kubernetes
 
How to be a mentor to bring more girls to STEAM
How to be a mentor to bring more girls to STEAMHow to be a mentor to bring more girls to STEAM
How to be a mentor to bring more girls to STEAM
 
Java in a World of Containers - DockerCon 2018
Java in a World of Containers - DockerCon 2018Java in a World of Containers - DockerCon 2018
Java in a World of Containers - DockerCon 2018
 
The Serverless Tidal Wave - SwampUP 2018 Keynote
The Serverless Tidal Wave - SwampUP 2018 KeynoteThe Serverless Tidal Wave - SwampUP 2018 Keynote
The Serverless Tidal Wave - SwampUP 2018 Keynote
 
Introduction to Amazon EKS - KubeCon 2018
Introduction to Amazon EKS - KubeCon 2018Introduction to Amazon EKS - KubeCon 2018
Introduction to Amazon EKS - KubeCon 2018
 
Mastering Kubernetes on AWS - Tel Aviv Summit
Mastering Kubernetes on AWS - Tel Aviv SummitMastering Kubernetes on AWS - Tel Aviv Summit
Mastering Kubernetes on AWS - Tel Aviv Summit
 
Top 10 Technology Trends Changing Developer's Landscape
Top 10 Technology Trends Changing Developer's LandscapeTop 10 Technology Trends Changing Developer's Landscape
Top 10 Technology Trends Changing Developer's Landscape
 
Container Landscape in 2017
Container Landscape in 2017Container Landscape in 2017
Container Landscape in 2017
 
Java EE and NoSQL using JBoss EAP 7 and OpenShift
Java EE and NoSQL using JBoss EAP 7 and OpenShiftJava EE and NoSQL using JBoss EAP 7 and OpenShift
Java EE and NoSQL using JBoss EAP 7 and OpenShift
 
Docker, Kubernetes, and Mesos recipes for Java developers
Docker, Kubernetes, and Mesos recipes for Java developersDocker, Kubernetes, and Mesos recipes for Java developers
Docker, Kubernetes, and Mesos recipes for Java developers
 
Thanks Managers!
Thanks Managers!Thanks Managers!
Thanks Managers!
 
Migrate your traditional VM-based Clusters to Containers
Migrate your traditional VM-based Clusters to ContainersMigrate your traditional VM-based Clusters to Containers
Migrate your traditional VM-based Clusters to Containers
 

Kürzlich hochgeladen

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Kürzlich hochgeladen (20)

04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
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
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
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
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
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...
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
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 future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 

S314168 - What's New in Enterprise Java Bean Technology @ JavaOne Brazil 2010

  • 1. <Insert Picture Here> What's New in Enterprise JavaBean Technology Arun Gupta, Java EE & GlassFish Guy blogs.sun.com/arungupta, @arungupta
  • 3. The following is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. The development, release, and timing of any features or functionality described for Oracle’s products remains at the sole discretion of Oracle. 3
  • 4. Agenda • Introduction <Insert Picture Here> • Ease of Use Improvements • New Functionality 4
  • 5. EJB 3.1 Specification • Goals – Continued focus on ease-of-use – New features • JSR (Java Specification Request) 318 – Expert Group Formed – August 2007 – Public Draft – October 2008 – Proposed Final Draft – March 2009 – Final Specification – December 2009 5
  • 6. Ease of Use Improvements • Optional Local Business Interfaces • Simplified Packaging • EJB 3.1 “Lite” API • Portable Global JNDI Names • Simple Component Testing 6
  • 7. Session Bean With “No-interface” View @Stateless public class HelloBean { public String sayHello(String msg) { return “Hello “ + msg; } } 7
  • 8. No-interface View Client @EJB HelloBean h; ... h.sayHello(“bob”); 8
  • 9. TM Java EE Platform 5 Packaging 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 OR WEB-INF/web.xml com/acme/Foo.class WEB-INF/classes/ foo_ejb.jar com/acme/FooServlet.class com/acme/FooBean.class foo_ejb.jar com/acme/Foo.class com/acme/FooBean.class 9
  • 10. Simplified Packaging foo.war WEB-INF/classes/com/acme/ FooServlet.class FooBean.class 10
  • 12. Portable EJB JNDI Names Each session bean gets the following entries : • Globally unique name java:global[/<app-name>]/<module-name>/<ejb- name> • Unique name within same application java:app/<module-name>/<ejb-name> • Unique name within defining module java:module/<ejb-name> 12
  • 13. Session Bean @Stateless public class HelloBean implements Hello { public String sayHello(String msg) { return “Hello “ + msg; } } If deployed as hello.jar, JNDI entries are: java:global/hello/HelloBean java:app/hello/HelloBean java:module/HelloBean 13
  • 14. Simple Testing : Session Bean @Stateless @Local(Bank.class) public class BankBean implements Bank { @PersistenceContext EntityManager accountDB; public String createAccount(AcctDetails d) { … } public void removeAccount(String acctID) { … } 14
  • 15. Embeddable API public class BankTester { public static void main(String[] args) { EJBContainer container = EJBContainer.createEJBContainer(); // Acquire Local EJB reference Bank bank = (Bank) container.getContext(). lookup(“java:global/bank/BankBean”); testAccountCreation(bank); container.close(); 15
  • 16. Test Client Execution % java -classpath bankClient.jar : bank.jar : javaee.jar : <vendor_rt>.jar com.acme.BankTester 16
  • 17. New Features • Singletons • Startup / Shutdown callbacks • Automatic timer creation – Cron-like syntax • Asynchronous session bean invocations 17
  • 18. Singleton @Singleton public class SharedBean { private SharedData shared; @PostConstruct private void init() { shared = ...; } public int getXYZ() { return shared.xyz; } 18
  • 19. Singleton Concurrency Options • Single threaded (default) – For consistency with all existing bean types • Container Managed Concurrency – Control access via method-level locking metadata • Bean Managed Concurrency – All concurrent invocations have access to bean instance 19
  • 20. Startup / Shutdown Callbacks @Singleton @Startup public class StartupBean { @PostConstruct private void onStartup() { … } @PreDestroy private void onShutdown() { … } } 20
  • 21. Timers • Automatically created EJB Timers • Calendar-based Timers – cron like semantics – Every Mon & Wed midnight @Schedule(dayOfWeek=”Mon,Wed”) – 2pm on Last Thur of Nov of every year (hour=”14”, dayOfMonth=”Last Thu”, month=”Nov”) – Every 5 minutes of every hour (minute=”*/5”, hour=”*”) – Every 10 seconds starting at 30 (second=”30/10”) – Every 14th minute within the hour, for the hours 1 and 2 am (minute=”*/14”, hour=”1,2”) 21
  • 22. Automatic Timer Creation @Stateless public class BankBean { @PersistenceContext EntityManager accountDB; @Resource javax.mail.Session mailSession; // Callback the last day of each month at 8 a.m. @Schedule(hour=”8”, dayOfMonth=”Last”) void sendMonthlyBankStatements() { ... } } 22
  • 23. Asynchronous Session Beans • Control returns to the client before the container dispatches invocation to a bean instance • @Asynchronous – method or class • Return type – void or Future<V> • “Fire and and Forget” or async results via Future<V> • Best effort delivery – persistent delivery guarantees are not required by spec • Transaction context does not propagate – REQUIRED → REQUIRED_NEW • Security principal propagates 23
  • 24. Asynchronous Session Beans Code Sample @Stateless @Asynchronous public class SimpleAsyncEJB { public Future<Integer> addNumbers(int n1, int n2) { Integer result; result = n1 + n2; try { // simulate JPA queries + reading file system Thread.currentThread().sleep(2000); } catch (InterruptedException ex) { ex.printStackTrace(); } return new AsyncResult(result); } } http://blogs.sun.com/arungupta/entry/totd_137_asynchronous_ejb_a 24
  • 25. References • glassfish.org • blogs.sun.com/theaquarium • youtube.com/user/GlassFishVideos • facebook.com/glassfish • Follow @glassfish 25
  • 26. <Insert Picture Here> What's New in Enterprise JavaBean Technology Arun Gupta, Java EE & GlassFish Guy blogs.sun.com/arungupta, @arungupta