SlideShare a Scribd company logo
1 of 46
Download to read offline
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

What's hot

iOSDevCamp 2011 Core Data
iOSDevCamp 2011 Core DataiOSDevCamp 2011 Core Data
iOSDevCamp 2011 Core DataChris Mar
 
Connect 2016-Move Your XPages Applications to the Fast Lane
Connect 2016-Move Your XPages Applications to the Fast LaneConnect 2016-Move Your XPages Applications to the Fast Lane
Connect 2016-Move Your XPages Applications to the Fast LaneHoward Greenberg
 
Advance java session 11
Advance java session 11Advance java session 11
Advance java session 11Smita B Kumar
 
Multithreading on iOS
Multithreading on iOSMultithreading on iOS
Multithreading on iOSMake School
 
Creating Single Page Web App using Backbone JS
Creating Single Page Web App using Backbone JSCreating Single Page Web App using Backbone JS
Creating Single Page Web App using Backbone JSAkshay Mathur
 
Akka Actor presentation
Akka Actor presentationAkka Actor presentation
Akka Actor presentationGene Chang
 
Hibernate Basic Concepts - Presentation
Hibernate Basic Concepts - PresentationHibernate Basic Concepts - Presentation
Hibernate Basic Concepts - PresentationKhoa Nguyen
 
RuleBox : A natural language Rule Engine
RuleBox : A natural language Rule EngineRuleBox : A natural language Rule Engine
RuleBox : A natural language Rule EngineOrtus Solutions, Corp
 
Fighting security trolls_with_high-quality_mindsets
Fighting security trolls_with_high-quality_mindsetsFighting security trolls_with_high-quality_mindsets
Fighting security trolls_with_high-quality_mindsetsddeogun
 
Core data orlando i os dev group
Core data   orlando i os dev groupCore data   orlando i os dev group
Core data orlando i os dev groupAndrew Kozlik
 
Architecture Components
Architecture ComponentsArchitecture Components
Architecture ComponentsSang Eel Kim
 
Тарас Олексин - Sculpt! Your! Tests!
Тарас Олексин  - Sculpt! Your! Tests!Тарас Олексин  - Sculpt! Your! Tests!
Тарас Олексин - Sculpt! Your! Tests!DataArt
 
Cassandra Day Atlanta 2015: Building Your First Application with Apache Cassa...
Cassandra Day Atlanta 2015: Building Your First Application with Apache Cassa...Cassandra Day Atlanta 2015: Building Your First Application with Apache Cassa...
Cassandra Day Atlanta 2015: Building Your First Application with Apache Cassa...DataStax Academy
 
iOS for ERREST - alternative version
iOS for ERREST - alternative versioniOS for ERREST - alternative version
iOS for ERREST - alternative versionWO Community
 
Parallel batch processing with spring batch slideshare
Parallel batch processing with spring batch   slideshareParallel batch processing with spring batch   slideshare
Parallel batch processing with spring batch slideshareMorten Andersen-Gott
 

What's hot (20)

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

Similar to CDI 2.0 Deep Dive

Building Top-Notch Androids SDKs
Building Top-Notch Androids SDKsBuilding Top-Notch Androids SDKs
Building Top-Notch Androids SDKsrelayr
 
Java EE changes design pattern implementation: JavaDays Kiev 2015
Java EE changes design pattern implementation: JavaDays Kiev 2015Java EE changes design pattern implementation: JavaDays Kiev 2015
Java EE changes design pattern implementation: JavaDays Kiev 2015Alex Theedom
 
Build a Web App with JavaScript and jQuery (5:18:17, Los Angeles)
Build a Web App with JavaScript and jQuery (5:18:17, Los Angeles)Build a Web App with JavaScript and jQuery (5:18:17, Los Angeles)
Build a Web App with JavaScript and jQuery (5:18:17, Los Angeles)Thinkful
 
You Shall Not Pass - Security in Symfony
You Shall Not Pass - Security in SymfonyYou Shall Not Pass - Security in Symfony
You Shall Not Pass - Security in SymfonyThe Software House
 
Surviving the Java Deserialization Apocalypse // OWASP AppSecEU 2016
Surviving the Java Deserialization Apocalypse // OWASP AppSecEU 2016Surviving the Java Deserialization Apocalypse // OWASP AppSecEU 2016
Surviving the Java Deserialization Apocalypse // OWASP AppSecEU 2016Christian Schneider
 
Using and contributing to the next Guice
Using and contributing to the next GuiceUsing and contributing to the next Guice
Using and contributing to the next GuiceAdrian Cole
 
Mobile Developers Talks: Delve Mobile
Mobile Developers Talks: Delve MobileMobile Developers Talks: Delve Mobile
Mobile Developers Talks: Delve MobileKonstantin Loginov
 
Java EE 6 CDI Integrates with Spring & JSF
Java EE 6 CDI Integrates with Spring & JSFJava EE 6 CDI Integrates with Spring & JSF
Java EE 6 CDI Integrates with Spring & JSFJiayun Zhou
 
Android with dagger_2
Android with dagger_2Android with dagger_2
Android with dagger_2Kros Huang
 
How to Contribute to Apache Usergrid
How to Contribute to Apache UsergridHow to Contribute to Apache Usergrid
How to Contribute to Apache UsergridDavid M. Johnson
 
MicroProfile: A Quest for a Lightweight and Modern Enterprise Java Platform
MicroProfile: A Quest for a Lightweight and Modern Enterprise Java PlatformMicroProfile: A Quest for a Lightweight and Modern Enterprise Java Platform
MicroProfile: A Quest for a Lightweight and Modern Enterprise Java PlatformMike Croft
 
Using Play Framework 2 in production
Using Play Framework 2 in productionUsing Play Framework 2 in production
Using Play Framework 2 in productionChristian Papauschek
 
Starting on Stash
Starting on Stash Starting on Stash
Starting on Stash colleenfry
 
Async task, threads, pools, and executors oh my!
Async task, threads, pools, and executors oh my!Async task, threads, pools, and executors oh my!
Async task, threads, pools, and executors oh my!Stacy Devino
 

Similar to CDI 2.0 Deep Dive (20)

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

Recently uploaded

SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceanilsa9823
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️anilsa9823
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 

Recently uploaded (20)

SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 

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