19
@antoine_sd @cdispec # AdoptAJSR Adopt a JSR, why not CDI 2.0 ? Antoine Sabot-Durand Red Hat @ antoine_sd @cdispec http://cdi-spec.org

Adopt a JSR: CDI 2.0 at Devoxx UK

Embed Size (px)

Citation preview

Page 1: Adopt a JSR: CDI 2.0 at Devoxx UK

@antoine_sd @cdispec#AdoptAJSR

Adopt a JSR, why not CDI 2.0 ?

Antoine Sabot-Durand Red Hat @antoine_sd @cdispec http://cdi-spec.org

Page 2: Adopt a JSR: CDI 2.0 at Devoxx UK

@antoine_sd @cdispec#AdoptAJSR

• A brief story of CDI

• Main Goal of CDI 2.0

• What will be in EDR1

• Adopt CDI

Adopt a JSR, why not CDI 2.0 ?

Page 3: Adopt a JSR: CDI 2.0 at Devoxx UK

@YourTwitterHandle#DVXFR14{session hashtag} @antoine_sd @cdispec#AdoptAJSR

A brie

f hist

ory o

f CDI

Page 4: Adopt a JSR: CDI 2.0 at Devoxx UK

@antoine_sd @cdispec#AdoptAJSR

•CDI stands for Contexts and Dependency Injection

•At the origin CDI was thought to fill the gap between Front spec and EJB - All EJB session beans are also CDI beans - CDI integrates Servlet scope as its core built-in contexts

•CDI propose a programming model which provides: - A well-defined lifecycle for stateful objects bound to lifecycle contexts, where the

set of contexts is extensible - A typesafe dependency injection mechanism - The ability to decorate or to associate interceptors to objects with a typesafe

approach - An event notification model - An SPI allowing portable extensions to integrate cleanly with the container

What is CDI

Page 5: Adopt a JSR: CDI 2.0 at Devoxx UK

CDI Timeline

Dec 2009 June 2013 Apr 2014 Sep 2014

CDI 1.0

(Jav

a EE

6)

CDI 1.1

(Jav

a EE

7)

CDI 1.2

(1.1 M

R)

CDI 2.0

Star

ts

2016

CDI 2.0

relea

sed

Page 6: Adopt a JSR: CDI 2.0 at Devoxx UK

@YourTwitterHandle#DVXFR14{session hashtag} @antoine_sd @cdispec#AdoptAJSR

Main

Goa

ls of

CDI 2

.0

Page 7: Adopt a JSR: CDI 2.0 at Devoxx UK

@antoine_sd @cdispec#AdoptAJSR

•We had strong feedback from the community:

- Users feedback: - Need CDI to be more widely available in other Java EE

specifications as a transverse integration solution - Be able to run CDI outside of a Java EE container.

- 3rd parties spec and framework feedback: - Need to have an enhance SPI to ease integration - Need to have a lighter footprint of CDI API / Impl

Goals

Page 8: Adopt a JSR: CDI 2.0 at Devoxx UK

@antoine_sd @cdispec#AdoptAJSR

•Java SE support (the spec was renamed Contexts and Dependency Injection for Java):

- Use in desktop or alternative containers

•Modularity allowing us to work on a CDI light “part”: - Removing parts of spec requiring proxies in

implementation - Ease 3rd parties to develop CDI integration - This could make CDI compatible with embedded

platform…

CDI 2.0 main goals

Page 9: Adopt a JSR: CDI 2.0 at Devoxx UK

@YourTwitterHandle#DVXFR14{session hashtag} @antoine_sd @cdispec#AdoptAJSR

CDI 2

.0 Ea

rly D

raft

1

Page 10: Adopt a JSR: CDI 2.0 at Devoxx UK

@antoine_sd @cdispec#AdoptAJSR

•Early Draft 1 is about to be released

•We are a bit late on our schedule but the work was bigger than expected

•Some very old and important request were included in it

•Features are in the 10 first requested ones by the survey

Early Draft

Page 11: Adopt a JSR: CDI 2.0 at Devoxx UK

@antoine_sd @cdispec#AdoptAJSR

•We specified API to boot CDI in Java SE:

•Desktop and non Java EE application can now use a standard way to boot CDI

Early Draft content, Java SE support

public static void main(String... args) { CDIProvider provider = CDI.getCDIProvider(); CDI<Object> cdi = provider.initialize(); // retrieve a bean and do work with it MyBean myBean = cdi.select(MyBean.class).get(); myBean.doWork(); // when done cdi.shutdown(); }

Page 12: Adopt a JSR: CDI 2.0 at Devoxx UK

@antoine_sd @cdispec#AdoptAJSR

•The specification is now split in 3 parts - CDI core: the common specification regardless of the

platform - CDI for Java SE: specific features for Java SE

- Mainly SE boot - CDI for Java EE: specific feature for Java

- EJB, servlet, EL, JSF integration

•This split was necessary for Java SE support

•It’s also the first step for a future CDI light

Early Draft content, spec split

Page 13: Adopt a JSR: CDI 2.0 at Devoxx UK

@antoine_sd @cdispec#AdoptAJSR

•One of the oldest user request :

•We decided to use the @Priority from commons annotation (JSR 250)

•JSR 250 will need a Maintenance Release to have @Priority targeting a parameter

Early Draft content, Event Ordering

void afterLogin(@Observes @Priority(APPLICATION) LoggedInEvent event) { ... }

Page 14: Adopt a JSR: CDI 2.0 at Devoxx UK

@antoine_sd @cdispec#AdoptAJSR

•The most popular feature in the survey:

•Based on Java 8 new Async API

•Introducing a new kind of observes for backward compatibility with @ObservesAsync

Early Draft content, Asynchronous

public interface Event<T> { … public <U extends T> CompletionStage<U> fireAsync(U event); public <U extends T> CompletionStage<U> fireAsync(U event, Executor executor); …}

Page 15: Adopt a JSR: CDI 2.0 at Devoxx UK

@YourTwitterHandle@antoine_sd @cdispec#AdoptAJSR

More info on CDI 2.0

in our talk on Friday 3pm

Page 16: Adopt a JSR: CDI 2.0 at Devoxx UK

@YourTwitterHandle#DVXFR14{session hashtag} @antoine_sd @cdispec#AdoptAJSR

Adopt

CDI 2

.0

Page 17: Adopt a JSR: CDI 2.0 at Devoxx UK

@antoine_sd @cdispec#AdoptAJSR

•Reading and checking the spec after the split

•Feedback on Java SE and other features

•Vote on features on the CDI Jira

•Propose new features or IDEAS

CDI needs you!

Page 18: Adopt a JSR: CDI 2.0 at Devoxx UK

@antoine_sd @cdispec#AdoptAJSR

•CDI Website: http://cdi-spec.org

•Weld website: http://weld.cdi-spec.org

•Mailing list: https://lists.jboss.org/mailman/listinfo/cdi-dev

•Discussion: IRC / Freenode / #cdispec

•Keep in touch: @cdispec

Resources

Page 19: Adopt a JSR: CDI 2.0 at Devoxx UK

Which JSR you’ll use 365 days a year?

JSR 365