From Tomcat to Java EE, making the transition with TomEE

3,093 views

Published on

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

No Downloads
Views
Total views
3,093
On SlideShare
0
From Embeds
0
Number of Embeds
1,396
Actions
Shares
0
Downloads
51
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide

From Tomcat to Java EE, making the transition with TomEE

  1. 1. David Blevins | ApacheTomcat to JavaEE with Apache TomEE
  2. 2. @dblevinsdblevins@apache.org@ApachTomEE / #TomEEhttp://tomee.apache.org
  3. 3. What is Apache TomEE?
  4. 4. Tomcat + JavaEE = TomEE• Java EE 6 Web Profile certified• Tomcat through and through• All Apache components – OpenJPA – OpenWebBeans – OpenEJB – MyFaces• Core Values – Be small – Be certified – Be Tomcat
  5. 5. Flavors of TomEE• Apache TomEE Web Profile (Java EE 6 Certified) – CDI – EJB – JPA – JSF – Bean Validation• Apache TomEE Plus – JAX-RS – JAX-WS – JMS• Embedded Apache TomEE
  6. 6. Basic Stats• Size – 27mb• Memory usage – very little required – passes TCK with default 64mb• Agility: – Eclipse deploy ~700ms – embedded test 2-4 seconds
  7. 7. Certification• Certified on Amazon EC2 – t1.micro linux images, – 100 spot instances – 613mb memory – 64mb used, 549mb free – t1.micros have slow disks, memory is critical• Current certified OSs – Amazon Linux AMI 2011.09, EBS boot, EC2 t1.micro – Amazon Linux AMI 2011.09, EBS boot, EC2 m1.small – Amazon Linux AMI 2011.09, EBS boot, EC2 c1.medium• Runs daily• Got a Cloud? – Donate time!
  8. 8. “There is also one point to note. TomEE is insanely fast! ” -- Łukasz Budnik, CXF JAX-RS on Apache TomEE @ DZone, May 23rd 2012“From an architect that switched from <XXX> to Tomee. I cantell you Tomee kicks <XXX>s ass in every way. Memory,speed, reliability, validation, you name it.” -- Zeeman, User List, July 3rd 2012“If you are concerned about performance and footprint, butcan accept that youll have to solve problems yourself, goTomEE. (TomEE seems to be _much_ faster than <XXX>)” -- Jonathan Fisher, User List, July 3rd 2012
  9. 9. Gaps in Tomcat
  10. 10. Gaps in Tomcat• No Transaction support• No Connection Pooling support – Pooling should be transactional• No Integrated Security• No support for Global JNDI – java:module – java:app – java:global• No support for @DataSourceDefinition• No support for new <env-entry> types: – java.lang.Class – Enums
  11. 11. Gaps in Tomcat• No @Resource – UserTransaction – BeanManager – Validator – ValidatorFactory – Topic/Queue – ConnectionFactory• No @PersistenceUnit• No @PersistenceContext• No @Inject• No @EJB• No @WebServiceRef
  12. 12. Migration Issues
  13. 13. Building your own app server• Including API jars in the webapp – JPA API – JSF API – etc.• Including implementations in webapp – Mojarra (works in trunk) – Bitronix/Atomikos• Non-compliant DataSource and JPA – too many years of Do It Yourself – providers not enforcing rules
  14. 14. (Mis)Information• Gaps in Knowledge – “that other stuff”• Misinformation – don’t use X, it’s heavy• Leads to... – let’s build own own heavy X!• Bites you – non-portable apps – lacks tens of thousands of tests – lacks shared experience
  15. 15. Closing Gaps in Knowledge
  16. 16. You can’t use this• unless you understand – JTA Transactions – Container-managed EntityManagers – Container-managed DataSources – How to get references to these, properly!
  17. 17. Not Just EJBs• Components with Transaction support – Servlets – JSP – JSF Managed Beans – CDI – EJB – JAX-RS REST Services – JAX-WS Web Services
  18. 18. What are Transactions?
  19. 19. “Undo”
  20. 20. Controlling Transactions• javax.transaction.UserTransaction – Manual approach – Any JavaEE component• @javax.ejb.TransactionAttribute – Class or method annotation – EJB only• @javax.transaction.Transactional – Class or method annotation – Any JavaEE component* – Coming in JavaEE 7
  21. 21. Transaction Hooks• SessionSynchronization – @AfterBegin – @BeforeCompletion – @AfterCompletion• Events – @Observes(during=IN_PROGRESS) – @Observes(during=BEFORE_COMPLETION) – @Observes(during=AFTER_COMPLETION) • @Observes(during=AFTER_SUCCESS) • @Observes(during=AFTER_FAILURE)
  22. 22. “Undo” aware Resources• DataSource• EntityManager• Sending JMS Messages• Receiving JMS Messages• Timers & @Schedule• (more via Java EE connectors) [Some restrictions apply. Offer void where prohibited. Container- provided resources required. Must be 18 years or older to apply]
  23. 23. More specifically
  24. 24. How does it work?
  25. 25. TOP SECRET(authorized personnel only)
  26. 26. This is not a pipe
  27. 27. Not the real thing
  28. 28. The EntityManager You Get
  29. 29. continued...
  30. 30. The DataSource You Get
  31. 31. better than a pipe
  32. 32. ...better than the real thing• thread-safe• undo-aware• leak-free
  33. 33. All boils down to...
  34. 34. “hashmap”“listeners”
  35. 35. ...but
  36. 36. Won’t work with any of this• DataSource – DriverManager.getConnection(...) – new FooDataSource() – autocommit = true• EntityManager – PersistenceProvider.createEntityManag... – EntityManagerFactory.createEntityManager – EntityTransaction
  37. 37. Avoid Do It Yourself
  38. 38. Rule• If you didn’t get it from the Container – it isn’t usable with UserTransaction – connections may leak – memory may leak• Even then there are some BIG notes – EntityManagerFactory • not usable with UserTransaction – <persistence-unit=RESOURCE_LOCAL> • not usable with UserTransaction
  39. 39. Common Migration Issues & Mistakes
  40. 40. Wrong
  41. 41. Wrong
  42. 42. Wrong
  43. 43. Still Wrong
  44. 44. The worst of them all
  45. 45. this...
  46. 46. or this...
  47. 47. with THIS!
  48. 48. darn defaults!
  49. 49. There we go
  50. 50. JPA Rules• RESOURCE_LOCAL – Persistence.createEntityManagerFactory – @PersistenceUnit EntityManagerFactory – <non-jta-data-source>• JTA – @PersistenceContext EntityManager – <jta-data-source> – <non-jta-data-source>• No other combinations are valid
  51. 51. Good• Valid RESOURCE_LOCAL usage
  52. 52. Better• Valid RESOURCE_LOCAL usage
  53. 53. Best• Valid JTA usage
  54. 54. DataSource• Declare – in tomee.xml – in META-INF/resources.xml – via @DataSourceDefinition• Retrieve – @Resource – <resource-ref>• Undo-aware and pooled
  55. 55. Declaring• <tomee-home>/conf/tomee.xml• WEB-INF/resources.xml
  56. 56. Recap
  57. 57. Recap• Use if you need “undo”• Transactions not heavy – Thread safe management – Help prevent Leaks – Enhance programming• More than a TransactionManager – TransactionManagers do nothing alone – Resources must cooperate• Don’t Do It Yourself – Use container-provided resources – no need to re-invent the wheel
  58. 58. Recap• Components with Transaction support – Servlets – JSP – JSF Managed Beans – CDI – EJB – JAX-RS REST Services – JAX-WS Web Services
  59. 59. Recap• Transactional Resources – DataSource – EntityManager – Sending JMS Messages – Receiving JMS Messages – Timers & @Schedule – (more via Java EE connectors)
  60. 60. Questions?
  61. 61. Thank You! @dblevinshttp://tomee.apache.org

×