• Save
OpenWebBeans and DeltaSpike at ApacheCon
Upcoming SlideShare
Loading in...5
×
 

Like this? Share it with your network

Share

OpenWebBeans and DeltaSpike at ApacheCon

on

  • 6,426 views

OpenWebBeans and DeltaSpike at ApacheCon 2012

OpenWebBeans and DeltaSpike at ApacheCon 2012

Statistics

Views

Total Views
6,426
Views on SlideShare
2,471
Embed Views
3,955

Actions

Likes
2
Downloads
0
Comments
0

41 Embeds 3,955

http://os890.blogspot.com 1098
http://os890.blogspot.de 757
http://os890.blogspot.co.at 607
http://os890.blogspot.com.br 231
http://os890.blogspot.fr 155
http://os890.blogspot.se 109
http://os890.blogspot.ru 99
http://os890.blogspot.it 96
http://os890.blogspot.ca 85
http://os890.blogspot.ch 68
http://os890.blogspot.com.au 60
http://os890.blogspot.jp 58
http://os890.blogspot.nl 57
http://os890.blogspot.in 55
http://os890.blogspot.co.uk 52
http://os890.blogspot.com.es 49
http://os890.blogspot.no 43
http://os890.blogspot.be 38
http://os890.blogspot.hk 25
http://os890.blogspot.sk 25
http://os890.blogspot.cz 24
http://os890.blogspot.mx 18
http://os890.blogspot.hu 18
http://os890.blogspot.com.tr 17
http://os890.blogspot.com.ar 15
http://os890.blogspot.fi 12
http://os890.blogspot.ie 11
http://os890.blogspot.gr 11
http://os890.blogspot.tw 9
http://os890.blogspot.pt 9
http://os890.blogspot.dk 8
http://os890.blogspot.ro 6
http://os890.blogspot.kr 6
http://os890.blogspot.co.il 5
http://os890.blogspot.co.nz 4
http://translate.googleusercontent.com 4
http://webcache.googleusercontent.com 4
http://os890.blogspot.ae 3
http://os890.blogspot.sg 2
http://www.tubebox.us 1
http://www.os890.blogspot.com 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

OpenWebBeans and DeltaSpike at ApacheCon Presentation Transcript

  • 1. CDI @ ApacheOpenWebBeans and DeltaSpike Deep Dive Mark Struberg Gerhard Petracek
  • 2. Agenda● CDI and its terms● Why OpenWebBeans?● Portable CDI Extensions● CDI by example with DeltaSpike
  • 3. CDI is a ...● JCP specification started in ~2007 Contexts and Dependency Injection for the Java EE platform (CDI) as JSR-299● component model designed for Java EE (can be used with Java SE)
  • 4. CDI Features● Type-safe Dependency Injection● Interceptors● Decorators● Events● SPI for implementing "Portable Extensions"● Unified EL integration
  • 5. What is Dependency Injection?● "Inversion Of Control" object creation● No more hardcoded dependencies when working with Interfaces MailService ms = new VerySpecialMailService();● Basically the old Factory Pattern● Hollywood Principle: "Dont call us, we call you!"● Macho Principle "Dude, gimme that bloody stuff!"
  • 6. Singletons and Contexts● What is a Singleton● "exactly one single instance in a well specified context"
  • 7. Built-in CDI Scopes● NormalScoped with well defined lifecycle: – @ApplicationScoped – @SessionScoped – @RequestScoped – @ConversationScoped● Pseudo Scope: – @Dependent
  • 8. Terms - Managed Bean● ... a Java Class and all its rules to create (contextual) instances of that bean.● Managed Beans in JSR-299 and JSR-346 doesnt mean JavaBeans!● Interface Bean<T> extends Contextual<T>
  • 9. Terms - Contextual Instance● ... a Java instance created with the rules of the Managed Bean Bean<T>● Contextual Instances usually dont get injected directly!
  • 10. Terms - Contextual Reference● ... a proxy for a Contextual Instance.● Proxies will automatically be created for injecting @NormalScope beans and allow decoupled scope handling
  • 11. Bootstrapping & Runtime● Creating the meta information at startup – Bean meta-data can be changed – Fail fast (e.g. AmbiguousResolutionException)● Contextual Instance creation at runtime – based on the Managed Beans – the Context will maintain the instances● Well defined contextual instance termination
  • 12. Why Apache OpenWebBeans?● Fast● Stable● Modular Plugin Architecture● Usable (e.g. alternative approach for BDAs)
  • 13. Portable CDI Extensions● Apache MyFaces CODI http://myfaces.apache.org/extensions/cdi● JBoss Seam3 http://seamframework.org/Seam3● Apache DeltaSpike http://incubator.apache.org/deltaspike
  • 14. DeltaSpike closes the gapsbetween ...● ... Java-EE and the needs of real-world applications● ... different CDI communities
  • 15. History of Apache DeltaSpike
  • 16. CDI in Action with Apache DeltaSpike
  • 17. DeltaSpike 0.3 - Overview● Core● JPA● Security● Container-Control
  • 18. Interceptors and Producers in action
  • 19. @Transactional - 1● Transactional bean in the application @Transactional public class MyBean { @Inject private EntityManager em; }
  • 20. @Transactional - 2● Producer and disposer in the application @Produces @TransactionScoped protected EntityManager defaultEntityManager() { return …; } protected void dispose(@Disposes EntityManager em) { if (em.isOpen()) { em.close(); } }
  • 21. @Transactional - 3● Interceptor annotation in DeltaSpike @InterceptorBinding public @interface Transactional { //... }
  • 22. @Transactional - 4● Interceptor implementation in DeltaSpike @Interceptor @Transactional public class TransactionalInterceptor implements Serializable { @Inject private TransactionStrategy ts; @AroundInvoke public Object executeInTransaction( InvocationContext invocationContext) throws Exception { return ts.execute(invocationContext); } } + config in the beans.xml
  • 23. Qualifiers in action
  • 24. @Transactional - 5● Transactional bean in the application @Transactional public class MyBean { @Inject private @First EntityManager em1; @Inject private @Second EntityManager em2; }
  • 25. @Transactional - 6● Producer implementations in the application @Produces @RequestScoped @First protected EntityManager firstEntityManager() { //... } @Produces @RequestScoped @Second protected EntityManager secondEntityManager() { //... }
  • 26. @Transactional - 7● Producers and disposers in the application protected void disposeFirst(@Disposes @First EntityManager em) { if (em.isOpen()) { em.close(); } } protected void disposeSecond(@Disposes @Second EntityManager em) { if (em.isOpen()) { em.close(); } }
  • 27. @Transactional - 8● Qualifier implementations in the application @Qualifier public @interface First { } @Qualifier public @interface Second { }
  • 28. Events in action
  • 29. @BeforeJsfRequest - 1● Observer in the application public void onBeforeJsfRequest( @Observes @BeforeJsfRequest FacesContext facesContext) { //… }
  • 30. @BeforeJsfRequest - 2● Fired event in DeltaSpike @Inject @BeforeJsfRequest private Event<FacesContext> beforeJsfRequestEvent; this.beforeJsfRequestEvent.fire(facesContext);
  • 31. @Specializes and @Alternative
  • 32. @Specializes configs - 1● Specialized type-safe config in the application @Specializes public class CustomWindowContextConfig extends WindowContextConfig { public int getWindowContextTimeoutInMinutes() { return 240; } }
  • 33. @Specializes configs - 2● Config implementation in CODI (/DS) @ApplicationScoped public class WindowContextConfig { public int getWindowContextTimeoutInMinutes() { return 60; } public int getMaxWindowContextCount() { return 64; } //… }
  • 34. @Alternative - 1● Alternative implementation in the application @Alternative @Exclude( exceptIfProjectStage = ProjectStage.Development.class) public class MockedMailService implements MailService { } + config in beans.xml
  • 35. @Alternative - 2● Primary implementation in the application public interface MailService { } @ApplicationScoped public class DefaultMailService implements MailService { }
  • 36. Apache DeltaSpike.Next● Simple answer: There is no fixed master plan! The future depends on the community -> get involved!