CDI 2.0 Deep Dive
MarkStruberg
• Member Apache Software Foundation
• VP, Apache OpenWebBeans
• CDI expert group member
• Twitter: @struberg
• Blog: struberg.wordpress.com
@struberg @thjanssen123CDI 2.0 Deep Dive
ThorbenJanssen
• Independent author and trainer
• Senior developer and architect @ Qualitype GmbH
• CDI 2.0 expert group member
• Twitter: @thjanssen123
• Blog: www.thoughts-on-java.org
@struberg @thjanssen123CDI 2.0 Deep Dive
CDI? What‘s that?
@struberg @thjanssen123CDI 2.0 Deep Dive
WhatisCDI? • Contexts and Dependency Injection for JavaTM 2.0 (JSR 365)
• Provides
• Contexts
• Dependency Injection
• Events
• Interceptors and decorators
• Extensions
@struberg @thjanssen123CDI 2.0 Deep Dive
HistoryofCDI • CDI 1.0 (Java EE 6) December 2009
• CDI 1.1 (Java EE 7) June 2013
• CDI 1.2 April 2014
• CDI 2.0 Start September 2014
• CDI 2.0 Early Draft Release 2015
• CDI 2.0 Release 1st half of 2016
• CDI 2.1 Start after 2.0 Release
@struberg @thjanssen123CDI 2.0 Deep Dive
CDI 2.0
@struberg @thjanssen123CDI 2.0 Deep Dive
CDI2.0 • Work on CDI 2.0 is still in progress
• No final decision yet
• Everything might change
@struberg @thjanssen123CDI 2.0 Deep Dive
MainTopics • Improve the event system
• Bootstrapping for Java SE
• Modularity
• Improve AOP
• Enhance SPI and Contexts
• Support Java 8 features
@struberg @thjanssen123CDI 2.0 Deep Dive
MainTopics • Defined by
• Existing entries in Jira
• Requirements by other specs
• Input from former expert group members
• Community survey
@struberg @thjanssen123CDI 2.0 Deep Dive
CommunitySurvey • June 2014
• 260 participants
• 20 features to rate
• Asynchronous events
• Bootstrapping outside of Java EE
• AOP for produced or custom beans
• Observer ordering
@struberg @thjanssen123CDI 2.0 Deep Dive
Events
@struberg @thjanssen123CDI 2.0 Deep Dive
Events • One of the bigger topics in CDI 2.0
• High demand by community
• Features
• Asynchronous events
• Ordering of events
@struberg @thjanssen123CDI 2.0 Deep Dive
SynchronousEvents • Fire a synchronous event
@Inject
Event<UserEvent> userEvent;
…
userEvent.fire (new UserEvent(…));
• Observe a synchronous event
public void handleUserEvent(@Observes UserEvent e)
{…}
@struberg @thjanssen123CDI 2.0 Deep Dive
AsynchronousEvents • Fire an asynchronous event
@Inject
Event<UserEvent> userEvent;
…
userEvent.fireAsync(new UserEvent(…));
• Observe an asynchronous event
public void handleUserEvent(@ObserveAsync UserEvent e)
{…}
@struberg @thjanssen123CDI 2.0 Deep Dive
AsynchronousEvents • Result and exception handling
event.fireAsync(new UserEvent(…))
.whenComplete((event, throwable) -> {
if (throwable != null) {
logger.error(“Error during processing of
UserEvent” +
throwable.getMessage());
} else {
logger.info(“Processing successful”);
}
});
@struberg @thjanssen123CDI 2.0 Deep Dive
AsynchronousEvents • What could possibly go wrong?
• Thread executor group might get blocked by slow observers
• Mutable non-threadsafe payload
e.g. visitor pattern with ArrayList in event payload
• @SessionScoped doesn‘t get propagated between threads
• @RequestScoped doesn‘t get propagated between threads
e.g. @Inject Principal currentUser
@struberg @thjanssen123CDI 2.0 Deep Dive
AsynchronousEvents • What could possibly go wrong?
• ThreadLocals of all kind don‘t get propagated
e.g. log4j MappedDiagnosticContext
• Transactions don‘t get propagated
TransactionSynchronisationRegistry is basically a ThreadLocal
• New EntityManager and @PersistenceContext for each thread
• @Observes(during=TransactionPhase.AFTER_SUCCESS)
• Each async observer gets ist own transaction!
@struberg @thjanssen123CDI 2.0 Deep Dive
AsynchronousEvents • All these problems are caused by multi-threading behavior
in Java EE and not CDI specific
• Very same problems occure with EJB @Asynchronous
and Concurrency-Utils for Java EE
@struberg @thjanssen123CDI 2.0 Deep Dive
AsynchronousEvents • Introduces new, asynchronous kind of events
• CompletionStage<U> fireAsync(U event)
• @ObservesAsync
Event method @Observes notified @ObservesAsync
notified
fire() Yes No
fireAsync() No Yes
@struberg @thjanssen123CDI 2.0 Deep Dive
OrderingofEvents • Define the order of event observers
public void handleUserEvent(
@Observe @Priority(1000) UserEvent e) {…}
• Call smallest priority first
• Uses default priority if not defined
• Order undefined for Observer with same priority
@struberg @thjanssen123CDI 2.0 Deep Dive
Bootstrapping
@struberg @thjanssen123CDI 2.0 Deep Dive
Bootstrapping • Define a standard way to boot the CDI container in Java SE
• Already part of Weld and Open Web Beans
• First API proposed in EDR 1
@struberg @thjanssen123CDI 2.0 Deep Dive
Bootstrapping • API proposal in EDR1
public static void main(String... args) {
try(CDI<Object> cdi =
CDI.getCDIProvider().initialize()) {
// start the container,
// retrieve a bean and do work with it
MyBean myBean = cdi.select(MyBean.class).get();
myBean.doWork();
}
// shuts down automatically after
// the try with resources block.
}
https://docs.jboss.org/cdi/spec/2.0.EDR1/cdi-spec.html#bootstrap-
se
@struberg @thjanssen123CDI 2.0 Deep Dive
Bootstrapping • API currently under discussion
• Context control not defined yet
• Bean discovery mode still under discussion
• Provide an option to choose implementation
@struberg @thjanssen123CDI 2.0 Deep Dive
CdiCtrlCdiContainer • Allows to boot embedded EE containers with a vendor
independent API
• Implementations for:
• Apache OpenWebBeans
• JBoss Weld
• JBoss WildFly in the making
• Apache OpenEJB (TomEE embedded)
• add your own
• Simply replace the impl jar to switch!
@struberg @thjanssen123CDI 2.0 Deep Dive
CdiCtrl-ContainerBootstrap • Very usable for unit tests, batches or other standalone Java
processes:
CdiContainer cdiContainer =
CdiContainerLoader.getCdiContainer();
cdiContainer.boot();
cdiContainer.getContextControl().startContexts();
…
cdiContainer.shutdown();
@struberg @thjanssen123CDI 2.0 Deep Dive
CdiCtrl-ContextControl • Also usable in EE containers
• Usage:
@Inject ContextControl ctxCtrl;
• Allows to attach dummy RequestContext, SessionContext
etc to the current Thread.
• Usable for Quartz extensions or any other async work
@struberg @thjanssen123CDI 2.0 Deep Dive
AOP
@struberg @thjanssen123CDI 2.0 Deep Dive
AOP • Work on AOP improvements just started
• Topics
• Improve handling of UnproxyableResolutionException
• Interceptors and Decorators on produced and custom
beans
• Support AOP on inner calls
@struberg @thjanssen123CDI 2.0 Deep Dive
ClassProxies • No Java SE support so far!
• All done in a container depending own way
• Most times uses bytecode libraries like javassist, ASM, cglib,
bcel or serp
• Create a sub-class of the given type
• Override all public methods
@struberg @thjanssen123CDI 2.0 Deep Dive
UnproxyAble? • CDI throws an UnproxyAbleResolutionException for all
classes which have
• No default constructor
• final, non-static and non-private methods
e.g. ConcurrentHashMap
www.thoughts-on-java.org
SubclassProxyExample1/2 • The business class
@SessionScoped
public class User {
private String name;
public String getName() {
return name;
}
}
@struberg @thjanssen123CDI 2.0 Deep Dive
SubclassProxyExample2/2 public class User$$Proxy extends User {
@Override
public String getName() {
return getInstance().getName();
}
private T getInstance() {
beanManager.getContext().get(...);
}
}
@struberg @thjanssen123CDI 2.0 Deep Dive
AllowProxying • Proposed solution
• Annotation @AllowProxying
• beans.xml <allowProxying>
@struberg @thjanssen123CDI 2.0 Deep Dive
AllowProxying • Proposed solution 1
• Annotation @AllowProxying
Public class Owner {
@Produces
@RequestScoped
@TenantA
@AllowProxying
ConcurrentHashMap createConfigBase() {…}
}
@struberg @thjanssen123CDI 2.0 Deep Dive
AllowProxying • Proposed solution
• beans.xml <allowProxying>
<allowProxying>
<class>java.util.concurrent.ConcurrentHashMap</class>
</allowProxying>
@struberg @thjanssen123CDI 2.0 Deep Dive
InterceptorsonProducers • Long discussions…
• Probably solvable by introducing javax.proxy.ProxyFactory?
• Like java.lang.reflect.Proxy but with subclassing
see DeltaSpike PartialBean
@struberg @thjanssen123CDI 2.0 Deep Dive
Java 8
@struberg @thjanssen123CDI 2.0 Deep Dive
Java8 • Java 8 was released after Java EE 7
• Support for Java 8 features
• All new APIs will use Java 8
• Changes of existing APIs are still under discussion
@struberg @thjanssen123CDI 2.0 Deep Dive
Java8 • Asynchronous events
fireAsync methods return new CompletionStage
public <U extends T> CompletionStage<U> fireAsync(U event);
public <U extends T> CompletionStage<U> fireAsync(U event,
Executor executor);
@struberg @thjanssen123CDI 2.0 Deep Dive
Java8 • Repeatable qualifiers and interceptor bindings
• Proposed by RI Weld, not specified so far
@Produces
@Language(„english“)
@Language(„german“)
public Translator createTranslator() { … }
@struberg @thjanssen123CDI 2.0 Deep Dive
Get in touch
@struberg @thjanssen123CDI 2.0 Deep Dive
Getintouch • Website: http://www.cdi-spec.org
• Blog: http://www.cdi-spec.org/news/
• Twitter: @cdispec
• Mailing list: https://lists.jboss.org/mailman/listinfo/cdi-dev
• JIRA: https://issues.jboss.org/
@struberg @thjanssen123CDI 2.0 Deep Dive
Getintouch
Mark Struberg
Twitter: @struberg
Blog: struberg.wordpress.com
Thorben Janssen
Twitter: @thjanssen123
Blog: www.thoughts-on-java.org
@struberg @thjanssen123CDI 2.0 Deep Dive
Resources • CDI website:
http://www.cdi-spec.org
• JSR 365 – CDI 2.0:
https://jcp.org/en/jsr/detail?id=365
• CDI 2.0 EDR1:
https://docs.jboss.org/cdi/spec/2.0.EDR1/cdi-spec.html
• The path to CDI 2.0 by Antoine Sabot-Durand:
https://www.youtube.com/watch?v=RynnZPsQdxM
http://de.slideshare.net/antoinesd/the-path-to-cdi-20
• Blog Weld – CDI reference implementation:
http://weld.cdi-spec.org/news/
• Apache OpenWebBeans:
http://openwebbeans.apache.org
@struberg @thjanssen123CDI 2.0 Deep Dive

More Related Content

PDF
Effiziente Datenpersistierung mit JPA 2.1 und Hibernate
PPTX
Hibernate Performance Tuning @JUG Thüringen
PPTX
Hibernate Tips ‘n’ Tricks - 15 Tips to solve common problems
PPTX
Effiziente persistierung
PPT
Performance Tuning with JPA 2.1 and Hibernate (Geecon Prague 2015)
PPT
Hibernate presentation
PPTX
Spring data jpa
PDF
Gaej For Beginners
Effiziente Datenpersistierung mit JPA 2.1 und Hibernate
Hibernate Performance Tuning @JUG Thüringen
Hibernate Tips ‘n’ Tricks - 15 Tips to solve common problems
Effiziente persistierung
Performance Tuning with JPA 2.1 and Hibernate (Geecon Prague 2015)
Hibernate presentation
Spring data jpa
Gaej For Beginners

What's hot (20)

PPT
jQuery Objects
KEY
iOSDevCamp 2011 Core Data
PDF
ERGroupware
PDF
Connect 2016-Move Your XPages Applications to the Fast Lane
PPTX
Advance java session 11
PDF
Multithreading on iOS
PPTX
Creating Single Page Web App using Backbone JS
PPTX
Akka Actor presentation
PDF
Gradle - Build System
PPTX
Hibernate Basic Concepts - Presentation
PDF
RuleBox : A natural language Rule Engine
PDF
Fighting security trolls_with_high-quality_mindsets
PPT
Core data orlando i os dev group
PDF
Architecture Components
PPTX
Тарас Олексин - Sculpt! Your! Tests!
PDF
Cassandra Day Atlanta 2015: Building Your First Application with Apache Cassa...
PDF
Ajax chap 2.-part 1
PDF
Ajax chap 3
PDF
iOS for ERREST - alternative version
PPTX
Parallel batch processing with spring batch slideshare
jQuery Objects
iOSDevCamp 2011 Core Data
ERGroupware
Connect 2016-Move Your XPages Applications to the Fast Lane
Advance java session 11
Multithreading on iOS
Creating Single Page Web App using Backbone JS
Akka Actor presentation
Gradle - Build System
Hibernate Basic Concepts - Presentation
RuleBox : A natural language Rule Engine
Fighting security trolls_with_high-quality_mindsets
Core data orlando i os dev group
Architecture Components
Тарас Олексин - Sculpt! Your! Tests!
Cassandra Day Atlanta 2015: Building Your First Application with Apache Cassa...
Ajax chap 2.-part 1
Ajax chap 3
iOS for ERREST - alternative version
Parallel batch processing with spring batch slideshare
Ad

Similar to CDI 2.0 Deep Dive (20)

PDF
Building Top-Notch Androids SDKs
PPT
jDays Sweden 2016
PDF
Apache DeltaSpike the CDI toolbox
PDF
Apache DeltaSpike: The CDI Toolbox
PPT
Java EE changes design pattern implementation: JavaDays Kiev 2015
PDF
Build a Web App with JavaScript and jQuery (5:18:17, Los Angeles)
PDF
CDI: How do I ?
PDF
You Shall Not Pass - Security in Symfony
PDF
Surviving the Java Deserialization Apocalypse // OWASP AppSecEU 2016
PPTX
Introduction to Jquery
PPTX
Using and contributing to the next Guice
PPTX
Mobile Developers Talks: Delve Mobile
PDF
Java EE 6 CDI Integrates with Spring & JSF
PDF
Evolve your coding with some BDD
PDF
Android with dagger_2
PDF
How to Contribute to Apache Usergrid
PPTX
MicroProfile: A Quest for a Lightweight and Modern Enterprise Java Platform
PDF
Using Play Framework 2 in production
PDF
Starting on Stash
PPTX
Async task, threads, pools, and executors oh my!
Building Top-Notch Androids SDKs
jDays Sweden 2016
Apache DeltaSpike the CDI toolbox
Apache DeltaSpike: The CDI Toolbox
Java EE changes design pattern implementation: JavaDays Kiev 2015
Build a Web App with JavaScript and jQuery (5:18:17, Los Angeles)
CDI: How do I ?
You Shall Not Pass - Security in Symfony
Surviving the Java Deserialization Apocalypse // OWASP AppSecEU 2016
Introduction to Jquery
Using and contributing to the next Guice
Mobile Developers Talks: Delve Mobile
Java EE 6 CDI Integrates with Spring & JSF
Evolve your coding with some BDD
Android with dagger_2
How to Contribute to Apache Usergrid
MicroProfile: A Quest for a Lightweight and Modern Enterprise Java Platform
Using Play Framework 2 in production
Starting on Stash
Async task, threads, pools, and executors oh my!
Ad

Recently uploaded (20)

PPTX
Cybersecurity-and-Fraud-Protecting-Your-Digital-Life.pptx
PDF
How Tridens DevSecOps Ensures Compliance, Security, and Agility
PPTX
Weekly report ppt - harsh dattuprasad patel.pptx
PPTX
WiFi Honeypot Detecscfddssdffsedfseztor.pptx
PDF
Multiverse AI Review 2025: Access All TOP AI Model-Versions!
PDF
BoxLang Dynamic AWS Lambda - Japan Edition
PPTX
Cybersecurity: Protecting the Digital World
PPTX
most interesting chapter in the world ppt
PPTX
MLforCyber_MLDataSetsandFeatures_Presentation.pptx
PDF
The Dynamic Duo Transforming Financial Accounting Systems Through Modern Expe...
DOC
UTEP毕业证学历认证,宾夕法尼亚克拉里恩大学毕业证未毕业
PPTX
CNN LeNet5 Architecture: Neural Networks
PDF
AI/ML Infra Meetup | Beyond S3's Basics: Architecting for AI-Native Data Access
PDF
MCP Security Tutorial - Beginner to Advanced
PDF
CCleaner 6.39.11548 Crack 2025 License Key
PPTX
Airline CRS | Airline CRS Systems | CRS System
DOCX
How to Use SharePoint as an ISO-Compliant Document Management System
PPTX
Introduction to Windows Operating System
PDF
Guide to Food Delivery App Development.pdf
PDF
AI Guide for Business Growth - Arna Softech
Cybersecurity-and-Fraud-Protecting-Your-Digital-Life.pptx
How Tridens DevSecOps Ensures Compliance, Security, and Agility
Weekly report ppt - harsh dattuprasad patel.pptx
WiFi Honeypot Detecscfddssdffsedfseztor.pptx
Multiverse AI Review 2025: Access All TOP AI Model-Versions!
BoxLang Dynamic AWS Lambda - Japan Edition
Cybersecurity: Protecting the Digital World
most interesting chapter in the world ppt
MLforCyber_MLDataSetsandFeatures_Presentation.pptx
The Dynamic Duo Transforming Financial Accounting Systems Through Modern Expe...
UTEP毕业证学历认证,宾夕法尼亚克拉里恩大学毕业证未毕业
CNN LeNet5 Architecture: Neural Networks
AI/ML Infra Meetup | Beyond S3's Basics: Architecting for AI-Native Data Access
MCP Security Tutorial - Beginner to Advanced
CCleaner 6.39.11548 Crack 2025 License Key
Airline CRS | Airline CRS Systems | CRS System
How to Use SharePoint as an ISO-Compliant Document Management System
Introduction to Windows Operating System
Guide to Food Delivery App Development.pdf
AI Guide for Business Growth - Arna Softech

CDI 2.0 Deep Dive

  • 2. MarkStruberg • Member Apache Software Foundation • VP, Apache OpenWebBeans • CDI expert group member • Twitter: @struberg • Blog: struberg.wordpress.com @struberg @thjanssen123CDI 2.0 Deep Dive
  • 3. ThorbenJanssen • Independent author and trainer • Senior developer and architect @ Qualitype GmbH • CDI 2.0 expert group member • Twitter: @thjanssen123 • Blog: www.thoughts-on-java.org @struberg @thjanssen123CDI 2.0 Deep Dive
  • 4. CDI? What‘s that? @struberg @thjanssen123CDI 2.0 Deep Dive
  • 5. WhatisCDI? • Contexts and Dependency Injection for JavaTM 2.0 (JSR 365) • Provides • Contexts • Dependency Injection • Events • Interceptors and decorators • Extensions @struberg @thjanssen123CDI 2.0 Deep Dive
  • 6. HistoryofCDI • CDI 1.0 (Java EE 6) December 2009 • CDI 1.1 (Java EE 7) June 2013 • CDI 1.2 April 2014 • CDI 2.0 Start September 2014 • CDI 2.0 Early Draft Release 2015 • CDI 2.0 Release 1st half of 2016 • CDI 2.1 Start after 2.0 Release @struberg @thjanssen123CDI 2.0 Deep Dive
  • 8. CDI2.0 • Work on CDI 2.0 is still in progress • No final decision yet • Everything might change @struberg @thjanssen123CDI 2.0 Deep Dive
  • 9. MainTopics • Improve the event system • Bootstrapping for Java SE • Modularity • Improve AOP • Enhance SPI and Contexts • Support Java 8 features @struberg @thjanssen123CDI 2.0 Deep Dive
  • 10. MainTopics • Defined by • Existing entries in Jira • Requirements by other specs • Input from former expert group members • Community survey @struberg @thjanssen123CDI 2.0 Deep Dive
  • 11. CommunitySurvey • June 2014 • 260 participants • 20 features to rate • Asynchronous events • Bootstrapping outside of Java EE • AOP for produced or custom beans • Observer ordering @struberg @thjanssen123CDI 2.0 Deep Dive
  • 13. Events • One of the bigger topics in CDI 2.0 • High demand by community • Features • Asynchronous events • Ordering of events @struberg @thjanssen123CDI 2.0 Deep Dive
  • 14. SynchronousEvents • Fire a synchronous event @Inject Event<UserEvent> userEvent; … userEvent.fire (new UserEvent(…)); • Observe a synchronous event public void handleUserEvent(@Observes UserEvent e) {…} @struberg @thjanssen123CDI 2.0 Deep Dive
  • 15. AsynchronousEvents • Fire an asynchronous event @Inject Event<UserEvent> userEvent; … userEvent.fireAsync(new UserEvent(…)); • Observe an asynchronous event public void handleUserEvent(@ObserveAsync UserEvent e) {…} @struberg @thjanssen123CDI 2.0 Deep Dive
  • 16. AsynchronousEvents • Result and exception handling event.fireAsync(new UserEvent(…)) .whenComplete((event, throwable) -> { if (throwable != null) { logger.error(“Error during processing of UserEvent” + throwable.getMessage()); } else { logger.info(“Processing successful”); } }); @struberg @thjanssen123CDI 2.0 Deep Dive
  • 17. AsynchronousEvents • What could possibly go wrong? • Thread executor group might get blocked by slow observers • Mutable non-threadsafe payload e.g. visitor pattern with ArrayList in event payload • @SessionScoped doesn‘t get propagated between threads • @RequestScoped doesn‘t get propagated between threads e.g. @Inject Principal currentUser @struberg @thjanssen123CDI 2.0 Deep Dive
  • 18. AsynchronousEvents • What could possibly go wrong? • ThreadLocals of all kind don‘t get propagated e.g. log4j MappedDiagnosticContext • Transactions don‘t get propagated TransactionSynchronisationRegistry is basically a ThreadLocal • New EntityManager and @PersistenceContext for each thread • @Observes(during=TransactionPhase.AFTER_SUCCESS) • Each async observer gets ist own transaction! @struberg @thjanssen123CDI 2.0 Deep Dive
  • 19. AsynchronousEvents • All these problems are caused by multi-threading behavior in Java EE and not CDI specific • Very same problems occure with EJB @Asynchronous and Concurrency-Utils for Java EE @struberg @thjanssen123CDI 2.0 Deep Dive
  • 20. AsynchronousEvents • Introduces new, asynchronous kind of events • CompletionStage<U> fireAsync(U event) • @ObservesAsync Event method @Observes notified @ObservesAsync notified fire() Yes No fireAsync() No Yes @struberg @thjanssen123CDI 2.0 Deep Dive
  • 21. OrderingofEvents • Define the order of event observers public void handleUserEvent( @Observe @Priority(1000) UserEvent e) {…} • Call smallest priority first • Uses default priority if not defined • Order undefined for Observer with same priority @struberg @thjanssen123CDI 2.0 Deep Dive
  • 23. Bootstrapping • Define a standard way to boot the CDI container in Java SE • Already part of Weld and Open Web Beans • First API proposed in EDR 1 @struberg @thjanssen123CDI 2.0 Deep Dive
  • 24. Bootstrapping • API proposal in EDR1 public static void main(String... args) { try(CDI<Object> cdi = CDI.getCDIProvider().initialize()) { // start the container, // retrieve a bean and do work with it MyBean myBean = cdi.select(MyBean.class).get(); myBean.doWork(); } // shuts down automatically after // the try with resources block. } https://docs.jboss.org/cdi/spec/2.0.EDR1/cdi-spec.html#bootstrap- se @struberg @thjanssen123CDI 2.0 Deep Dive
  • 25. Bootstrapping • API currently under discussion • Context control not defined yet • Bean discovery mode still under discussion • Provide an option to choose implementation @struberg @thjanssen123CDI 2.0 Deep Dive
  • 26. CdiCtrlCdiContainer • Allows to boot embedded EE containers with a vendor independent API • Implementations for: • Apache OpenWebBeans • JBoss Weld • JBoss WildFly in the making • Apache OpenEJB (TomEE embedded) • add your own • Simply replace the impl jar to switch! @struberg @thjanssen123CDI 2.0 Deep Dive
  • 27. CdiCtrl-ContainerBootstrap • Very usable for unit tests, batches or other standalone Java processes: CdiContainer cdiContainer = CdiContainerLoader.getCdiContainer(); cdiContainer.boot(); cdiContainer.getContextControl().startContexts(); … cdiContainer.shutdown(); @struberg @thjanssen123CDI 2.0 Deep Dive
  • 28. CdiCtrl-ContextControl • Also usable in EE containers • Usage: @Inject ContextControl ctxCtrl; • Allows to attach dummy RequestContext, SessionContext etc to the current Thread. • Usable for Quartz extensions or any other async work @struberg @thjanssen123CDI 2.0 Deep Dive
  • 30. AOP • Work on AOP improvements just started • Topics • Improve handling of UnproxyableResolutionException • Interceptors and Decorators on produced and custom beans • Support AOP on inner calls @struberg @thjanssen123CDI 2.0 Deep Dive
  • 31. ClassProxies • No Java SE support so far! • All done in a container depending own way • Most times uses bytecode libraries like javassist, ASM, cglib, bcel or serp • Create a sub-class of the given type • Override all public methods @struberg @thjanssen123CDI 2.0 Deep Dive
  • 32. UnproxyAble? • CDI throws an UnproxyAbleResolutionException for all classes which have • No default constructor • final, non-static and non-private methods e.g. ConcurrentHashMap www.thoughts-on-java.org
  • 33. SubclassProxyExample1/2 • The business class @SessionScoped public class User { private String name; public String getName() { return name; } } @struberg @thjanssen123CDI 2.0 Deep Dive
  • 34. SubclassProxyExample2/2 public class User$$Proxy extends User { @Override public String getName() { return getInstance().getName(); } private T getInstance() { beanManager.getContext().get(...); } } @struberg @thjanssen123CDI 2.0 Deep Dive
  • 35. AllowProxying • Proposed solution • Annotation @AllowProxying • beans.xml <allowProxying> @struberg @thjanssen123CDI 2.0 Deep Dive
  • 36. AllowProxying • Proposed solution 1 • Annotation @AllowProxying Public class Owner { @Produces @RequestScoped @TenantA @AllowProxying ConcurrentHashMap createConfigBase() {…} } @struberg @thjanssen123CDI 2.0 Deep Dive
  • 37. AllowProxying • Proposed solution • beans.xml <allowProxying> <allowProxying> <class>java.util.concurrent.ConcurrentHashMap</class> </allowProxying> @struberg @thjanssen123CDI 2.0 Deep Dive
  • 38. InterceptorsonProducers • Long discussions… • Probably solvable by introducing javax.proxy.ProxyFactory? • Like java.lang.reflect.Proxy but with subclassing see DeltaSpike PartialBean @struberg @thjanssen123CDI 2.0 Deep Dive
  • 40. Java8 • Java 8 was released after Java EE 7 • Support for Java 8 features • All new APIs will use Java 8 • Changes of existing APIs are still under discussion @struberg @thjanssen123CDI 2.0 Deep Dive
  • 41. Java8 • Asynchronous events fireAsync methods return new CompletionStage public <U extends T> CompletionStage<U> fireAsync(U event); public <U extends T> CompletionStage<U> fireAsync(U event, Executor executor); @struberg @thjanssen123CDI 2.0 Deep Dive
  • 42. Java8 • Repeatable qualifiers and interceptor bindings • Proposed by RI Weld, not specified so far @Produces @Language(„english“) @Language(„german“) public Translator createTranslator() { … } @struberg @thjanssen123CDI 2.0 Deep Dive
  • 43. Get in touch @struberg @thjanssen123CDI 2.0 Deep Dive
  • 44. Getintouch • Website: http://www.cdi-spec.org • Blog: http://www.cdi-spec.org/news/ • Twitter: @cdispec • Mailing list: https://lists.jboss.org/mailman/listinfo/cdi-dev • JIRA: https://issues.jboss.org/ @struberg @thjanssen123CDI 2.0 Deep Dive
  • 45. Getintouch Mark Struberg Twitter: @struberg Blog: struberg.wordpress.com Thorben Janssen Twitter: @thjanssen123 Blog: www.thoughts-on-java.org @struberg @thjanssen123CDI 2.0 Deep Dive
  • 46. Resources • CDI website: http://www.cdi-spec.org • JSR 365 – CDI 2.0: https://jcp.org/en/jsr/detail?id=365 • CDI 2.0 EDR1: https://docs.jboss.org/cdi/spec/2.0.EDR1/cdi-spec.html • The path to CDI 2.0 by Antoine Sabot-Durand: https://www.youtube.com/watch?v=RynnZPsQdxM http://de.slideshare.net/antoinesd/the-path-to-cdi-20 • Blog Weld – CDI reference implementation: http://weld.cdi-spec.org/news/ • Apache OpenWebBeans: http://openwebbeans.apache.org @struberg @thjanssen123CDI 2.0 Deep Dive