Fun with EJB                                      and OpenEJB                          David Blevins                      ...
The Basics - History                          • Timeline                           • 1999 - Founded in Exoffice - EJB 1.1 l...
Focuses since inception                          • Always an Embeddable EJB Container                            • Good id...
We were only                          pretending to testFriday, October 7, 2011
EJB Vision & Philosophy                          • Misunderstood technology                           • Many things people...
There is no “heavy”                             requirementFriday, October 7, 2011
Show me the heavyFriday, October 7, 2011
Friday, October 7, 2011
EJB.next and Java EE.next                          • Promote @ManagedBean to a Session bean                          • Bre...
Interceptor -- Today                              @InterceptorBinding                          @Target(value = {ElementTyp...
Interceptor Improvements                              @Log                          public class FooBean {                ...
Interceptor Improvements                              @Log                          public class LoggingInterceptor {     ...
Meta-Annotations                              @RolesAllowed({"SuperUser", "AccountAdmin", "SystemAdmin"})                 ...
Meta-Annotations                              @Singleton                          @TransactionManagement(CONTAINER)       ...
Meta-Annotations                          @SuperBean                          public class MyBean {                       ...
TestingFriday, October 7, 2011
Embeded / Testing Principles                          • Be as invisible as possible                          • No special ...
What can you test?                          • EJBs                           • @Stateless                           • @Sta...
What can you test? (cont.)                          • Container Provided resources                           • DataSources...
What can’t you test?                          • Servlets                          • Filters                          • Lis...
Unique Testing Features                          • Most spec complete embedded container                          • Fast s...
Questions?Friday, October 7, 2011
thank you!                          openejb.apache.orgFriday, October 7, 2011
Upcoming SlideShare
Loading in …5
×

2011 JavaOne Fun with EJB 3.1 and OpenEJB

2,554 views
2,454 views

Published on

Published in: Technology, Education
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,554
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
29
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

2011 JavaOne Fun with EJB 3.1 and OpenEJB

  1. 1. Fun with EJB and OpenEJB David Blevins @dblevins #OpenEJBFriday, October 7, 2011
  2. 2. The Basics - History • Timeline • 1999 - Founded in Exoffice - EJB 1.1 level • 2001 - Integrated in Apple’s WebObjects • 2002 - Moved to SourceForge • 2003 - Integrated in Apache Geronimo • 2004 - Moved to Codehaus • 2006 - Moved to Apache Incubator • 2007 - Graduated Apache OpenEJB • Specification involvement • EJB 2.1 (Monson-Haefel) • EJB 3.0 (Blevins) • EJB 3.1 (Blevins) • EJB 3.2 (Blevins) 2Friday, October 7, 2011
  3. 3. Focuses since inception • Always an Embeddable EJB Container • Good idea for Embeddable Databases, good idea for us • Our downfall in early 2000 -- people were not ready • Our success after EJB 3.0 • No love for traditional Application Servers • Don’t give up main(String[] args) • Always doing the Opposite • Instead of putting the Application in the Container, put the Container in the Application • What do you mean hard to test?? • Don’t blame EJB because your Server is hard to test • In what way is mocking not writing an EJB container? 3Friday, October 7, 2011
  4. 4. We were only pretending to testFriday, October 7, 2011
  5. 5. EJB Vision & Philosophy • Misunderstood technology • Many things people attribute to “EJB” are not part of EJB • EJB can be light • EJB as a concept is not heavy, implementations were heavy • EJB can be simpler • Though the API was cumbersome it could be improved • EJB can be used for plain applications • The portability concept can be flipped on end • The flexability applications get also provides great flexability to the container to do things differently yet not break compliance 5Friday, October 7, 2011
  6. 6. There is no “heavy” requirementFriday, October 7, 2011
  7. 7. Show me the heavyFriday, October 7, 2011
  8. 8. Friday, October 7, 2011
  9. 9. EJB.next and Java EE.next • Promote @ManagedBean to a Session bean • Break up EJB -- separate the toppings • @TransactionManagement • @ConcurrencyManagement • @Schedule • @RolesAllowed • @Asynchronous • Allow all annotations to be used as meta-annotations • Modernize the Connector/MDB relationship • Interceptor improvements • Balance API • Everything that can be turned on should be able to shut off • Improve @ApplicationException 9Friday, October 7, 2011
  10. 10. Interceptor -- Today @InterceptorBinding @Target(value = {ElementType.TYPE}) @Retention(RetentionPolicy.RUNTIME) public @interface Log { } @Log public class FooBean {     public void somethingCommon(){       //...     public void somethingImportant() {      //...     public void somethingNoteworthy() {      //... } @Log public class LoggingInterceptor {     private java.util.logging.Logger logger =             java.util.logging.Logger.getLogger("theLogger");     @AroundInvoke     public Object intercept(InvocationContext context) throws Exception {         logger.info("" + context.getMethod().getName());         return context.proceed();     } } 10Friday, October 7, 2011
  11. 11. Interceptor Improvements @Log public class FooBean {     public void somethingCommon(){         //...     }     @Info     public void somethingImportant() {         //...     }     @Fine     public void somethingNoteworthy() {         //...     } } 11Friday, October 7, 2011
  12. 12. Interceptor Improvements @Log public class LoggingInterceptor {     private java.util.logging.Logger logger =             java.util.logging.Logger.getLogger("theLogger");     @AroundInvoke     public Object finest(InvocationContext context) throws Exception {         logger.finest("" + context.getMethod().getName());         return context.proceed();     }     @Info     public Object info(InvocationContext context) throws Exception {         logger.info("" + context.getMethod().getName());         return context.proceed();     }     @Fine     public Object fine(InvocationContext context) throws Exception {         logger.fine("" + context.getMethod().getName());         return context.proceed();     } } 12Friday, October 7, 2011
  13. 13. Meta-Annotations @RolesAllowed({"SuperUser", "AccountAdmin", "SystemAdmin"}) @Stereotype @Target(METHOD) @Retention(RUNTIME) public interface Admins {} @Schedule(second=”0”, minute=”0”, hour=”0”, month=”*”, dayOfWeek=”*”, year=”*”) @Stereotype @Target(METHOD) @Retention(RUNTIME) public @interface Hourly {} @Schedule(second=”0”, minute=”0”, hour=”0”, month=”*”, dayOfMonth=”15,Last”, year=”*”) @Stereotype @Target(METHOD) @Retention(RUNTIME) public @interface BiMonthly {} @Singleton @TransactionManagement(CONTAINER) @TransactionAttribute(REQUIRED) @ConcurrencyManagement(CONTAINER) @Lock(READ) @Interceptors({LoggingInterceptor.class, StatisticsInterceptor.class}) @Stereotype @Target(TYPE) @Retention(RUNTIME) public @interface SuperBean {} 13Friday, October 7, 2011
  14. 14. Meta-Annotations @Singleton @TransactionManagement(CONTAINER) @TransactionAttribute(REQUIRED) @ConcurrencyManagement(CONTAINER) @Lock(READ) @Interceptors({LoggingInterceptor.class, StatisticsInterceptor.class}) public class MyBean {     @Schedule(second=”0”, minute=”0”, hour=”0”, month=”*”, dayOfWeek=”*”, year=”*”)     public void runBatchJob() {         //...     }     @Schedule(second=”0”, minute=”0”, hour=”0”, month=”*”, dayOfMonth=”15,Last”, year=”*”)     public void sendPaychecks() {         //...     }          @RolesAllowed({"SuperUser", "AccountAdmin", "SystemAdmin"})     public void deleteAccount(String accountId) {         //...     } } 14Friday, October 7, 2011
  15. 15. Meta-Annotations @SuperBean public class MyBean {     @Hourly     public void runBatchJob() {         //...     }     @BiMonthly     public void sendPaychecks() {         //...     }          @Admin     public void deleteAccount(String accountId) {         //...     } } 15Friday, October 7, 2011
  16. 16. TestingFriday, October 7, 2011
  17. 17. Embeded / Testing Principles • Be as invisible as possible • No special classloaders required • No files • All Configuration can be done in the test or via properties • No logging files • No database files (in memory db) • No ports • Remote EJB calls done with “intra-vm” server • JMS done via embedded broker with local transport • Database connections via embedded database • No JavaAgent • Avoidable if not using JPA or if using Hibernate as the provider • OpenJPA to a limited extent 17Friday, October 7, 2011
  18. 18. What can you test? • EJBs • @Stateless • @Stateful • @Singleton • @MessageDriven • @ManagedBean • Interceptors • Legacy EJB 2.x and earlier • Views • @Remote • @Local • @LocalBean • @WebService (requires a port) 18Friday, October 7, 2011
  19. 19. What can you test? (cont.) • Container Provided resources • DataSources • EntityManagers and EntityManagerFactories • JMS Topics/Queues • WebServiceRefs • Any Java EE Connector provided object • Services • Timers • Transactions • Security • Asynchronous methods 19Friday, October 7, 2011
  20. 20. What can’t you test? • Servlets • Filters • Listeners • JSPs • JSF Managed Beans • Non-EJB WebServices Hello, TomEE 20Friday, October 7, 2011
  21. 21. Unique Testing Features • Most spec complete embedded container • Fast startup (1 - 2 seconds) • Test case injection • Overriding • Configuration overriding • Persistence Unit overriding • Logging overriding • Test centric-descriptors • test-specific ejb-jar.xml or persistence.xml, etc. • Validation • Compiler-style output of application compliance issues • Avoid multiple “fix, recompile, redeploy, fail, repeat" cycles • Descriptor output -- great for xml overriding 21Friday, October 7, 2011
  22. 22. Questions?Friday, October 7, 2011
  23. 23. thank you! openejb.apache.orgFriday, October 7, 2011

×