SlideShare una empresa de Scribd logo
1 de 46
Descargar para leer sin conexión
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

Más contenido relacionado

La actualidad más candente

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
 

La actualidad más candente (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 a 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 a 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!
 

Último

Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalLionel Briand
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...confluent
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...OnePlan Solutions
 
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxAndreas Kunz
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Velvetech LLC
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentationvaddepallysandeep122
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanyChristoph Pohl
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identityteam-WIBU
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作qr0udbr0
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesŁukasz Chruściel
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfMarharyta Nedzelska
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Developmentvyaparkranti
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsChristian Birchler
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceBrainSell Technologies
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Hr365.us smith
 
How To Manage Restaurant Staff -BTRESTRO
How To Manage Restaurant Staff -BTRESTROHow To Manage Restaurant Staff -BTRESTRO
How To Manage Restaurant Staff -BTRESTROmotivationalword821
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)jennyeacort
 

Último (20)

Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive Goal
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
 
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentation
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identity
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New Features
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdf
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Development
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. Salesforce
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)
 
How To Manage Restaurant Staff -BTRESTRO
How To Manage Restaurant Staff -BTRESTROHow To Manage Restaurant Staff -BTRESTRO
How To Manage Restaurant Staff -BTRESTRO
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
 

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