Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

2015 JavaOne EJB/CDI Alignment

29,342 views

Published on

The days of EJB’s being the center of the Java EE universe are coming to an end. CDI is increasingly becoming the de facto component framework, due to its flexibility and lack of legacy. Starting in Java EE 7 and continuing in 8, the Java EE platform is migrating to enable all of EJB’s best features to be usable in the CDI world. In this session, you’ll learn implementation-level details on how they relate to each other, where we are in the EJB/CDI alignment story, what trade-offs you might need to make, and what you have to gain from making the transition. You will walk out with runnable examples and vendor-level insights. This is the perfect session for heavy EJB users looking to keep up with Java EE’s transition to CDI.

Published in: Technology

2015 JavaOne EJB/CDI Alignment

  1. 1. JavaOne @dblevins @tomitribe#EJBCDI EJB/CDI Alignment (What Does It Mean?) David Blevins Tomitribe Jean-Louis Monteiro Tomitribe
  2. 2. JavaOne @dblevins @tomitribe#EJBCDI CDI - EJB Alignment (understand the conversation)
  3. 3. JavaOne @dblevins @tomitribe#EJBCDI CDI History In Brief
  4. 4. JavaOne @dblevins @tomitribe#EJBCDI CDI Influences • Dependency Injection • Definite Spring influence • Strong Google Guice syntax • Originally called “WebBeans” • Grew from Seam • Glued JSF and EJB together
  5. 5. JavaOne @dblevins @tomitribe#EJBCDI CDI Behind the Scenes • Achieved through sneaky interceptor trick • Caused major delay to the Java EE 6 delivery • Almost didn’t make it • Criticized for going too far • Stepped on EE toes (spec overlap) • Stepped on SE toes (too “enterprisey”)
  6. 6. JavaOne @dblevins @tomitribe#EJBCDI CDI Rifts • Creation of @ManagedBean spec at EE level • Fuzzy aim at unifying EE component models • Effort to not lose ground in EE • Too ambiguous • Creation of @Inject spec at SE level • Fuzzy aim at being simpler version of the standard • Effort to not lose ground in SE • Too simple, no spec
  7. 7. JavaOne @dblevins @tomitribe#EJBCDI EJB Shortcomings • Legacy • Reputation • Fully loaded by default • Every method starts a transaction • Throwing an exception destroys the instance • Instances are non-concurrent
  8. 8. JavaOne @dblevins @tomitribe#EJBCDI CDI Takeover • EJB adopts CDI (Java EE 6) • JSF adopts CDI (Java EE 7) • MVC adopts CDI (Java EE 8) • JAX-RS considers CDI (Java EE 8) • CDI moves to SE (Java EE 8)
  9. 9. JavaOne @dblevins @tomitribe#EJBCDI Result for EJB? • Java EE 7 • Focus on realignment: @Transactional • Java EE 8 • First spec round with no new EJB JSR • Realignment stalled • Awkward relationship
  10. 10. JavaOne @dblevins @tomitribe#EJBCDI CDI from an EJB perspective
  11. 11. JavaOne @dblevins @tomitribe#EJBCDI Proxy (Fake) Proxy (Fake) Interceptors Decorators Instance (Real) Security Transaction Interceptors Decorators Instance (Real) 1. Resolution 2. Services 3. Invocation (Pool) 1. Resolution 2. Services 3. Invocation (Context/Scope) CDI 1.0 EJB 3.1
  12. 12. JavaOne @dblevins @tomitribe#EJBCDI Proxy (Fake) Proxy (Fake) Security Transaction Interceptors Decorators Instance (Real) 1. Resolution 2. Services 3. Invocation (Pool) 1. Resolution 2. Services 3. Invocation (Context/Scope) CDI 1.1 EJB 3.2 Transaction Interceptors Decorators Instance (Real)
  13. 13. JavaOne @dblevins @tomitribe#EJBCDI Lifecycle Lineup • @Singleton • same as CDI @ApplicationScoped • @Stateful • applies to any CDI Scope, not just @SessionScoped • @Stateless • no CDI equivalent • @RequestScoped sort of close(ish)
  14. 14. JavaOne @dblevins @tomitribe#EJBCDI Awesome Power of Scopes
  15. 15. JavaOne @dblevins @tomitribe#EJBCDI http://tomitribe.io/projects/ microscoped
  16. 16. JavaOne @dblevins @tomitribe#EJBCDI Common Mistakes you will make • Not putting a beans.xml in your app (Java EE 6) • No CDI for you! • Not understanding @Typed • Psst, think @Local from EJB • Bites you when using @Produces • Not understanding what Dependent and NormalScope • Dependent == plain object • NormalScoped == proxied object • Bites you when creating custom scopes
  17. 17. JavaOne @dblevins @tomitribe#EJBCDI Biggest benefits of CDI • Very active and open expert group • Fully extendable • Beans can be added at runtime • Fully Open Source • Spec is open source • All implementations are open source • Compliance test (TCK) suite is open source
  18. 18. JavaOne @dblevins @tomitribe#EJBCDI What is Aligned?
  19. 19. JavaOne @dblevins @tomitribe#EJBCDI Transactions - Aligned • @TransactionAttribute & @ApplicationException • Usable by • @Stateless • @Stateful • @Singleton • @Transactional (CDI equivalent, new in Java EE 7)
  20. 20. JavaOne @dblevins @tomitribe#EJBCDI Transaction - EJB flavor
  21. 21. JavaOne @dblevins @tomitribe#EJBCDI Transaction - CDI flavor
  22. 22. JavaOne @dblevins @tomitribe#EJBCDI Observations • Pros • New API is Better • Doesn’t say “EJB” • Cons • Duplicating APIs • Slight changes • Conflicting usage?
  23. 23. JavaOne @dblevins @tomitribe#EJBCDI Observations - What happens? • More work for servers to check for mistakes • More work for IDEs to check for mistakes • New users won’t know which to use and where • Old users won’t remember how they are different • One more place for us all to make mistakes and be confused
  24. 24. JavaOne @dblevins @tomitribe#EJBCDI When you still need EJB (not yet aligned)
  25. 25. JavaOne @dblevins @tomitribe#EJBCDI Security • @RolesAllowed, @PermitAll, @DenyAll • Usable by • @Stateless • @Stateful • @Singleton • Alignment • Low likelihood • Pandora’s box • Not actively being discussed
  26. 26. JavaOne @dblevins @tomitribe#EJBCDI Startup • @Startup • Eagerly creates the instance upon startup • Usable by • @Singleton • Alignment • Strong Candidate
  27. 27. JavaOne @dblevins @tomitribe#EJBCDI Asynchronous • @Asynchronsous • Allows method calls to be asynchronous and return Future objects • Usable by • @Stateless • @Stateful • @Singleton • Alignment • Strong Candidate • Tracked in JIRA, high votes
  28. 28. JavaOne @dblevins @tomitribe#EJBCDI Schedule • @Schedule • Effectively Cron -- schedule invocations by minute or date, etc. • Usable by • @Stateless • @Singleton • Not @Stateful • Alignment • Strong Candidate • Could be a challenge -- timers are stateless, scopes are not
  29. 29. JavaOne @dblevins @tomitribe#EJBCDI Locking • @Lock(READ) / @Lock(WRITE) / @AccessTimeout • Allows for synchronization of methods without complex code • Usable by • @Singleton • Not @Stateless • Not @Stateful • Alignment • Medium Candidate • Applying to CDI possibly easier than EJB
  30. 30. JavaOne @dblevins @tomitribe#EJBCDI MDBs • @MessageDriven • Connector-Driven Beans • Usable by • Not @Singleton • Not @Stateless • Not @Stateful • Alignment • Medium Candidate • Pandora’s Box -- very complicated
  31. 31. JavaOne @dblevins @tomitribe#EJBCDI Thank You

×