<Insert Picture Here>Whats New in Enterprise JavaBean TechnologyArun Gupta, Java EE & GlassFish Guyblogs.sun.com/arungupta...
Beijing 2010December 13–16, 2010                       2
The following is intended to outline our generalproduct direction. It is intended for informationpurposes only, and may no...
Agenda• Introduction               <Insert Picture Here>• Ease of Use Improvements• New Functionality                     ...
EJB 3.1 Specification• Goals   – Continued focus on ease-of-use   – New features• JSR (Java Specification Request) 318   –...
Ease of Use Improvements• Optional Local Business Interfaces• Simplified Packaging• EJB 3.1 “Lite” API• Portable Global JN...
Session BeanWith “No-interface” View@Statelesspublic class HelloBean {    public String sayHello(String msg) {        retu...
No-interface View Client@EJB HelloBean h;...h.sayHello(“bob”);                           8
TMJava             EE Platform 5 Packaging          foo.ear                          foo.ear                              ...
Simplified Packaging                foo.war        WEB-INF/classes/com/acme/         FooServlet.class         FooBean.clas...
EJB 3.1 “Lite”                 11
Portable EJB JNDI NamesEach session bean gets the following entries :• Globally unique namejava:global[/<app-name>]/<modul...
Session Bean@Statelesspublic class HelloBean implements Hello {    public String sayHello(String msg) {        return “Hel...
Simple Testing : Session Bean@Stateless@Local(Bank.class)public class BankBean implements Bank { @PersistenceContext Entit...
Embeddable APIpublic class BankTester { public static void main(String[] args) {   EJBContainer container =      EJBContai...
Test Client Execution% java -classpath bankClient.jar :                  bank.jar :                  javaee.jar :         ...
New Features• Singletons• Startup / Shutdown callbacks• Automatic timer creation  – Cron-like syntax• Asynchronous session...
Singleton@Singletonpublic class SharedBean { private SharedData shared; @PostConstruct private void init() {     shared = ...
Singleton Concurrency Options• Single threaded (default)   – For consistency with all existing bean types• Container Manag...
Startup / Shutdown Callbacks@Singleton@Startuppublic class StartupBean {    @PostConstruct    private void onStartup() { …...
Timers• Automatically created EJB Timers• Calendar-based Timers – cron like semantics – Every Mon & Wed midnight   @Schedu...
Automatic Timer Creation@Statelesspublic class BankBean {    @PersistenceContext EntityManager accountDB;    @Resource jav...
Asynchronous Session Beans• Control returns to the client before the container      dispatches invocation to a bean instan...
Asynchronous Session BeansCode Sample @Stateless @Asynchronous public class SimpleAsyncEJB {     public Future<Integer> ad...
References• glassfish.org• blogs.sun.com/theaquarium• youtube.com/user/GlassFishVideos• facebook.com/glassfish• Follow @gl...
<Insert Picture Here>Whats New in Enterprise JavaBean TechnologyArun Gupta, Java EE & GlassFish Guyblogs.sun.com/arungupta...
Upcoming SlideShare
Loading in …5
×

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

2,053
-1

Published on

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

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

  • Be the first to like this

No Downloads
Views
Total Views
2,053
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
68
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

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

  1. 1. <Insert Picture Here>Whats New in Enterprise JavaBean TechnologyArun Gupta, Java EE & GlassFish Guyblogs.sun.com/arungupta, @arungupta
  2. 2. Beijing 2010December 13–16, 2010 2
  3. 3. The following is intended to outline our generalproduct direction. It is intended for informationpurposes only, and may not be incorporated into anycontract. It is not a commitment to deliver anymaterial, code, or functionality, and should not berelied upon in making purchasing decisions.The development, release, and timing of anyfeatures or functionality described for Oracle’sproducts remains at the sole discretion of Oracle. 3
  4. 4. Agenda• Introduction <Insert Picture Here>• Ease of Use Improvements• New Functionality 4
  5. 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. 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. 7. Session BeanWith “No-interface” View@Statelesspublic class HelloBean { public String sayHello(String msg) { return “Hello “ + msg; }} 7
  8. 8. No-interface View Client@EJB HelloBean h;...h.sayHello(“bob”); 8
  9. 9. TMJava EE Platform 5 Packaging foo.ear foo.ear lib/foo_common.jarfoo_web.warWEB-INF/web.xml com/acme/Foo.classWEB-INF/classes/ com/acme/FooServlet.class foo_web.warWEB-INF/classes OR WEB-INF/web.xml com/acme/Foo.class WEB-INF/classes/foo_ejb.jar com/acme/FooServlet.classcom/acme/FooBean.class foo_ejb.jarcom/acme/Foo.class com/acme/FooBean.class 9
  10. 10. Simplified Packaging foo.war WEB-INF/classes/com/acme/ FooServlet.class FooBean.class 10
  11. 11. EJB 3.1 “Lite” 11
  12. 12. Portable EJB JNDI NamesEach session bean gets the following entries :• Globally unique namejava:global[/<app-name>]/<module-name>/<ejb-name>• Unique name within same applicationjava:app/<module-name>/<ejb-name>• Unique name within defining modulejava:module/<ejb-name> 12
  13. 13. Session Bean@Statelesspublic class HelloBean implements Hello { public String sayHello(String msg) { return “Hello “ + msg; }}If deployed as hello.jar, JNDI entries are:java:global/hello/HelloBeanjava:app/hello/HelloBeanjava:module/HelloBean 13
  14. 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. 15. Embeddable APIpublic 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. 16. Test Client Execution% java -classpath bankClient.jar : bank.jar : javaee.jar : <vendor_rt>.jar com.acme.BankTester 16
  17. 17. New Features• Singletons• Startup / Shutdown callbacks• Automatic timer creation – Cron-like syntax• Asynchronous session bean invocations 17
  18. 18. Singleton@Singletonpublic class SharedBean { private SharedData shared; @PostConstruct private void init() { shared = ...; } public int getXYZ() { return shared.xyz; } 18
  19. 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. 20. Startup / Shutdown Callbacks@Singleton@Startuppublic class StartupBean { @PostConstruct private void onStartup() { … } @PreDestroy private void onShutdown() { … }} 20
  21. 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. 22. Automatic Timer Creation@Statelesspublic 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. 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. 24. Asynchronous Session BeansCode 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. 25. References• glassfish.org• blogs.sun.com/theaquarium• youtube.com/user/GlassFishVideos• facebook.com/glassfish• Follow @glassfish 25
  26. 26. <Insert Picture Here>Whats New in Enterprise JavaBean TechnologyArun Gupta, Java EE & GlassFish Guyblogs.sun.com/arungupta, @arungupta
  1. A particular slide catching your eye?

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

×