<Insert Picture Here>Whats New in Enterprise JavaBean Technology ?Sanjeeb SahooSr. Staff Engineer, Sun, an Oracle Company
The following/preceding is intended to outline ourgeneral product direction. It is intended forinformation purposes only, ...
Agenda• Introduction               <Insert Picture Here>• Ease of Use Improvements• New Functionality                     ...
EJB 3.0 Specification• Goal  • Ease of use  • Developer productivity• JSR (Java Specification Request) 220   • Final Speci...
EJB 3.0 Specification• Metadata via Java annotations  • Only annotations  • Only XML DD  • Both• Sensible defaults• POJO f...
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 GreetingBean {    public String greet(String msg) {        retu...
No-interface View Client@EJB GreetingBean h;...h.greet(“bob”);                           9
Session Bean“Interface” View@Statelesspublic class HelloBean implements GreetingBean {    public String greet(String msg) ...
Interface View Client@EJB(beanName=”HelloBean”) GreetingBean h;h.greet(“bob”);@EJB(beanName=”HowdyBean”) GreetingBean h2;h...
JavaTM EE Platform 5 Packaging        foo.ear                         foo.earfoo_web.war                      lib/foo_comm...
Simplified Packaging               foo.war        WEB-INF/classes/com/acme/         FooServlet.class         FooBean.class...
EJB 3.1 “Lite”                 14
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 “H...
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 =      EJBConta...
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@Asynchronouspublic class SimpleAsyncEJB {    public Future<Integer> addNum...
References• oracle.com/javaee• glassfish.org• oracle.com/goto/glassfish• blogs.sun.com/theaquarium• youtube.com/GlassFishV...
Upcoming SlideShare
Loading in...5
×

What's New in Enterprise JavaBean Technology ?

1,019

Published on

Presentation made at JavaONE, Hyderabad, on 11th May 2011.

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
1,019
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
47
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

What's New in Enterprise JavaBean Technology ?

  1. 1. <Insert Picture Here>Whats New in Enterprise JavaBean Technology ?Sanjeeb SahooSr. Staff Engineer, Sun, an Oracle Company
  2. 2. The following/preceding is intended to outline ourgeneral product direction. It is intended forinformation purposes only, and may not beincorporated into any contract. It is not acommitment to deliver any material, code, orfunctionality, and should not be relied upon inmaking purchasing decisions.The development, release, and timing of anyfeatures or functionality described for Oracle’sproducts remains at the sole discretion of Oracle. 2
  3. 3. Agenda• Introduction <Insert Picture Here>• Ease of Use Improvements• New Functionality 3
  4. 4. EJB 3.0 Specification• Goal • Ease of use • Developer productivity• JSR (Java Specification Request) 220 • Final Specification – 2006 4
  5. 5. EJB 3.0 Specification• Metadata via Java annotations • Only annotations • Only XML DD • Both• Sensible defaults• POJO friendly• Simplification of bean types• No home interface• Interceptors• Entity Beans replaced by JPA 5
  6. 6. EJB 3.1 Specification• Goals • Continued focus on ease-of-use • New features• JSR (Java Specification Request) 318 • Final Specification – December 2009 6
  7. 7. Ease of Use Improvements• Optional Local Business Interfaces• Simplified Packaging• EJB 3.1 “Lite” API• Portable Global JNDI Names• Simple Component Testing 7
  8. 8. Session BeanWith “No-interface” View@Statelesspublic class GreetingBean { public String greet(String msg) { return “Hello “ + msg; }} 8
  9. 9. No-interface View Client@EJB GreetingBean h;...h.greet(“bob”); 9
  10. 10. Session Bean“Interface” View@Statelesspublic class HelloBean implements GreetingBean { public String greet(String msg) { return “Hello “ + msg; }}@Statelesspublic class HowdyBean implements GreetingBean { public String greet(String msg) { return “Howdy “ + msg; }} 10
  11. 11. Interface View Client@EJB(beanName=”HelloBean”) GreetingBean h;h.greet(“bob”);@EJB(beanName=”HowdyBean”) GreetingBean h2;h2.greet(“sam”); 11
  12. 12. JavaTM EE Platform 5 Packaging foo.ear foo.earfoo_web.war lib/foo_common.jar com/acme/Foo.classWEB-INF/web.xmlWEB-INF/classes/ com/acme/FooServlet.class foo_web.war com/acme/Foo.class O WEB-INF/web.xml WEB-INF/classes/foo_ejb.jar R com/acme/FooServlet.classcom/acme/FooBean.class foo_ejb.jarcom/acme/Foo.class com/acme/FooBean.class 12
  13. 13. Simplified Packaging foo.war WEB-INF/classes/com/acme/ FooServlet.class FooBean.class 13
  14. 14. EJB 3.1 “Lite” 14
  15. 15. 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> 15
  16. 16. 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 16
  17. 17. 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) { … } 17
  18. 18. 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(); 18
  19. 19. Test Client Execution% java -classpath bankClient.jar : bank.jar : javaee.jar : <vendor_rt>.jar com.acme.BankTester 19
  20. 20. New Features• Singletons• Startup / Shutdown callbacks• Automatic timer creation • Cron-like syntax• Asynchronous session bean invocations 20
  21. 21. Singleton@Singletonpublic class SharedBean { private SharedData shared; @PostConstruct private void init() { shared = ...; } public int getXYZ() { return shared.xyz; } 21
  22. 22. 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 22
  23. 23. Startup / Shutdown Callbacks@Singleton@Startuppublic class StartupBean { @PostConstruct private void onStartup() { … } @PreDestroy private void onShutdown() { … }} 23
  24. 24. 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”) 24
  25. 25. 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() { ... }} 25
  26. 26. 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 26
  27. 27. Asynchronous Session BeansCode Sample@Stateless@Asynchronouspublic 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 27
  28. 28. References• oracle.com/javaee• glassfish.org• oracle.com/goto/glassfish• blogs.sun.com/theaquarium• youtube.com/GlassFishVideos• Follow @glassfish 28
  1. A particular slide catching your eye?

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

×