Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
SlideShare a Scribd company logo
JavaOne
@dblevins @tomitribe#EJBCDI
EJB/CDI Alignment
(What Does It Mean?)
David Blevins
Tomitribe
Jean-Louis Monteiro
Tomitribe
JavaOne
@dblevins @tomitribe#EJBCDI
CDI - EJB Alignment
(understand the conversation)
JavaOne
@dblevins @tomitribe#EJBCDI
CDI History In Brief
JavaOne
@dblevins @tomitribe#EJBCDI
CDI Influences
• Dependency Injection
• Definite Spring influence
• Strong Google Guice syntax
• Originally called “WebBeans”
• Grew from Seam
• Glued JSF and EJB together
JavaOne
@dblevins @tomitribe#EJBCDI
CDI Behind the Scenes
• Achieved through sneaky interceptor trick
• Caused major delay to the Java EE 6 delivery
• Almost didn’t make it
• Criticized for going too far
• Stepped on EE toes (spec overlap)
• Stepped on SE toes (too “enterprisey”)
JavaOne
@dblevins @tomitribe#EJBCDI
CDI Rifts
• Creation of @ManagedBean spec at EE level
• Fuzzy aim at unifying EE component models
• Effort to not lose ground in EE
• Too ambiguous
• Creation of @Inject spec at SE level
• Fuzzy aim at being simpler version of the standard
• Effort to not lose ground in SE
• Too simple, no spec
JavaOne
@dblevins @tomitribe#EJBCDI
EJB Shortcomings
• Legacy
• Reputation
• Fully loaded by default
• Every method starts a transaction
• Throwing an exception destroys the instance
• Instances are non-concurrent
JavaOne
@dblevins @tomitribe#EJBCDI
CDI Takeover
• EJB adopts CDI (Java EE 6)
• JSF adopts CDI (Java EE 7)
• MVC adopts CDI (Java EE 8)
• JAX-RS considers CDI (Java EE 8)
• CDI moves to SE (Java EE 8)
JavaOne
@dblevins @tomitribe#EJBCDI
Result for EJB?
• Java EE 7
• Focus on realignment: @Transactional
• Java EE 8
• First spec round with no new EJB JSR
• Realignment stalled
• Awkward relationship
JavaOne
@dblevins @tomitribe#EJBCDI
CDI from an EJB perspective
JavaOne
@dblevins @tomitribe#EJBCDI
Proxy
(Fake)
Proxy
(Fake)
Interceptors
Decorators
Instance
(Real)
Security
Transaction
Interceptors
Decorators
Instance
(Real)
1. Resolution
2. Services
3. Invocation
(Pool)
1. Resolution
2. Services
3. Invocation
(Context/Scope)
CDI 1.0 EJB 3.1
JavaOne
@dblevins @tomitribe#EJBCDI
Proxy
(Fake)
Proxy
(Fake)
Security
Transaction
Interceptors
Decorators
Instance
(Real)
1. Resolution
2. Services
3. Invocation
(Pool)
1. Resolution
2. Services
3. Invocation
(Context/Scope)
CDI 1.1 EJB 3.2
Transaction
Interceptors
Decorators
Instance
(Real)
JavaOne
@dblevins @tomitribe#EJBCDI
Lifecycle Lineup
• @Singleton
• same as CDI @ApplicationScoped
• @Stateful
• applies to any CDI Scope, not just @SessionScoped
• @Stateless
• no CDI equivalent
• @RequestScoped sort of close(ish)
JavaOne
@dblevins @tomitribe#EJBCDI
Awesome Power of Scopes
JavaOne
@dblevins @tomitribe#EJBCDI
http://tomitribe.io/projects/
microscoped
JavaOne
@dblevins @tomitribe#EJBCDI
Common Mistakes you will make
• Not putting a beans.xml in your app (Java EE 6)
• No CDI for you!
• Not understanding @Typed
• Psst, think @Local from EJB
• Bites you when using @Produces
• Not understanding what Dependent and NormalScope
• Dependent == plain object
• NormalScoped == proxied object
• Bites you when creating custom scopes
JavaOne
@dblevins @tomitribe#EJBCDI
Biggest benefits of CDI
• Very active and open expert group
• Fully extendable
• Beans can be added at runtime
• Fully Open Source
• Spec is open source
• All implementations are open source
• Compliance test (TCK) suite is open source
JavaOne
@dblevins @tomitribe#EJBCDI
What is Aligned?
JavaOne
@dblevins @tomitribe#EJBCDI
Transactions - Aligned
• @TransactionAttribute & @ApplicationException
• Usable by
• @Stateless
• @Stateful
• @Singleton
• @Transactional (CDI equivalent, new in Java EE 7)
JavaOne
@dblevins @tomitribe#EJBCDI
Transaction - EJB flavor
JavaOne
@dblevins @tomitribe#EJBCDI
Transaction - CDI flavor
JavaOne
@dblevins @tomitribe#EJBCDI
Observations
• Pros
• New API is Better
• Doesn’t say “EJB”
• Cons
• Duplicating APIs
• Slight changes
• Conflicting usage?
JavaOne
@dblevins @tomitribe#EJBCDI
Observations - What happens?
• More work for servers to check for mistakes
• More work for IDEs to check for mistakes
• New users won’t know which to use and where
• Old users won’t remember how they are different
• One more place for us all to make mistakes and be confused
JavaOne
@dblevins @tomitribe#EJBCDI
When you still need EJB
(not yet aligned)
JavaOne
@dblevins @tomitribe#EJBCDI
Security
• @RolesAllowed, @PermitAll, @DenyAll
• Usable by
• @Stateless
• @Stateful
• @Singleton
• Alignment
• Low likelihood
• Pandora’s box
• Not actively being discussed
JavaOne
@dblevins @tomitribe#EJBCDI
Startup
• @Startup
• Eagerly creates the instance upon startup
• Usable by
• @Singleton
• Alignment
• Strong Candidate
JavaOne
@dblevins @tomitribe#EJBCDI
Asynchronous
• @Asynchronsous
• Allows method calls to be asynchronous and return Future objects
• Usable by
• @Stateless
• @Stateful
• @Singleton
• Alignment
• Strong Candidate
• Tracked in JIRA, high votes
JavaOne
@dblevins @tomitribe#EJBCDI
Schedule
• @Schedule
• Effectively Cron -- schedule invocations by minute or date, etc.
• Usable by
• @Stateless
• @Singleton
• Not @Stateful
• Alignment
• Strong Candidate
• Could be a challenge -- timers are stateless, scopes are not
JavaOne
@dblevins @tomitribe#EJBCDI
Locking
• @Lock(READ) / @Lock(WRITE) / @AccessTimeout
• Allows for synchronization of methods without complex code
• Usable by
• @Singleton
• Not @Stateless
• Not @Stateful
• Alignment
• Medium Candidate
• Applying to CDI possibly easier than EJB
JavaOne
@dblevins @tomitribe#EJBCDI
MDBs
• @MessageDriven
• Connector-Driven Beans
• Usable by
• Not @Singleton
• Not @Stateless
• Not @Stateful
• Alignment
• Medium Candidate
• Pandora’s Box -- very complicated
JavaOne
@dblevins @tomitribe#EJBCDI
Thank You

More Related Content

2015 JavaOne EJB/CDI Alignment