• Save
PT.JUG CDI/Deltaspike
Upcoming SlideShare
Loading in...5
×
 

PT.JUG CDI/Deltaspike

on

  • 1,277 views

 

Statistics

Views

Total Views
1,277
Views on SlideShare
516
Embed Views
761

Actions

Likes
1
Downloads
0
Comments
0

15 Embeds 761

http://jug.pt 688
http://lopestech.blogspot.pt 36
http://lanyrd.com 13
http://ptjug.wordpress.com 6
http://lopestech.blogspot.com 5
http://lopestech.blogspot.com.br 3
http://lopestech.blogspot.de 2
http://lopestech.blogspot.jp 1
http://lopestech.blogspot.it 1
http://lopestech.blogspot.gr 1
http://lopestech.blogspot.com.ar 1
http://lopestech.blogspot.hu 1
http://lopestech.blogspot.ae 1
http://feedly.com 1
http://lopestech.blogspot.kr 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • Second part dedicated to Apache Deltaspike.

PT.JUG CDI/Deltaspike PT.JUG CDI/Deltaspike Presentation Transcript

  • CDI / DELTASPIKE ISCTE-IUL, Lisboa – January, 16th João-Luis Goncalves Monteiro @JLouisMonteiro #TomEE
  • ME • • • • Jean-Louis Monteiro Senior Java EE Software Architect Apache Software Foundation Committer/PMC in various Apache projects: – OpenWebBeans, OpenEJB/TomEE, Sirona, … • EJB 3.2 EG member • Java EE teacher at University in France
  • WHAT WE WILL SEE • CDI – Basic concepts – Diving into – Extensions • DeltaSpike – History – Into details – Future
  • WHAT IS CDI? • JCP specification started in 2007 – JSR 299: Context and Dependency Injection • Component model for Java EE – works on Java SE • Implementations – Apache OpenWebBeans, CanDI, Weld
  • MAIN FEATURES • • • • • Type-safe Dependency Injection Interceptors and Decorators Events / Observers Portable Extensions (SPI) Unified EL integration
  • WHAT IS DEPENDENCY INJECTION? Hollywood Principle: “Don’t call us, we call you” “Inversion of Control” Factory pattern Dependency management
  • WHAT CAN I INJECT? Any POJO Any other Type declared via the SPI Session Beans Web Services Persistence Unit/Context Any JNDI resource
  • HOW DI CONTAINERS WORK? • Contextual Instance Factory Pattern • Even in CDI, someone has to trigger the instance creation • But it has no control over the implementation class nor instance
  • SINGLETONS AND CONTEXTS @ApplicationScoped @SessionScoped Exactly one single instance … in a well specified context @RequestScoped @ConversationScoped And of course your own
  • SPECIAL SCOPES • @Dependant  the default – Pseudo scope – Gets the same lifecycle as the parent • The bean they get injected to • If no other scope is defined @Dependant is assumed
  • IMPORTANT DEFINITIONS
  • MANAGED BEAN • Does not mean JavaBean • Meta information for your factories • The CDI managed beans are the rules set – They are used to create contextual instances • Bean<T>
  • CONTEXTUAL INSTANCE • It’s the singleton instance in the well defined context • The context is defined by the rules • So a contextual instance is the Java instance created using the rules – They don’t get injected directly
  • PROXIES • Contextual reference for a contextual instance • Interface proxy versus Class proxy – We like POJOs so Interface proxies not applicable – No java.lang.Proxy • Class proxying creates sub classes – Overload non-private, non-static methods – Not specific to CDI (Hibernate, Spring) • Makes it possible to plug in Interceptors and Decorators.
  • CONTAINER LIFECYCLE • CDI container boots … – Classpath scanning (if CDI enabled) – Create Managed beans (stored as Bean<T>) • Contextual instances created – Recursively fill all injectionPoints • Cleanly terminates contextual instance
  • QUALIFIERS Annotation based (@Qualifier) Specific implementation at runtime Type safety preserved and reinforced Distinct beans of the same type @Named – special qualifier for EL names
  • PRODUCERS When factory rules not enough Common way to inject PersistenceContext New producer fields Elegant way to clean up (@Dispose)
  • SPECIALIZE AND ALTERNATIVE • Specialize – Overrides the super class Managed Bean – Completely replace and disable an implementation of a bean • Alternative – Exchange interface implementation Managed Bean – Disabled by default – Does not mean the default implementation is disabled
  • INTERCEPTOR Cross cutting concerns Decouple technical concerns from business logic Disabled by default Transactions Logging Security
  • EVENTS Common Observer/Observable pattern Decoupled peaces of code Not scoped Synchronous method call But you don’t know whom Internal CDI events for extensions
  • EXTENSIONS SPI META-INF/services/javax.enterprise.inject.spi.Extension Portable Activate? Drop the jar into the classpath Easy to write Based on CDI well defined events Apache MyFaces CODI JBoss Seam CDI Source Apache DeltaSpike
  • APACHE DELTASPIKE Build a set of portable extension for CDI
  • EXTENSIONS BASICS • During the boot, the BeanManager sends CDI Lifecycle events to the Extensions • CDI Extension can do anything you can do with annotations – … and much more
  • EXTENSIONS LIFECYCLE BeforeBeanDiscovery ProcessAnnotatedType ProcessInjectionTarget AfterBeanDiscovery AfterDeploymentValidation BeforeShutdown @Observes what you want in your extension
  • http://myfaces.apache.org/extensions/cdi http://deltaspike.apache.org http://seamframework.org/Seam3
  • APACHE MYFACES CODI IS … • A portable CDI set of extensions – But not a CDI implementation • Java EE 5+ • Easy to use and extend • Very fast and stable • Open source
  • HISTORY OF APACHE MYFACES CODI Intesresting concepts 12-2009 2-2010 11-2010 7-2011 • Apache MyFaces Orchestra • Spring • CDI 1.0 • MyFaces ExtCDI (aka CODI) started • First stable release (6 modules) • Release of v1.0.0 (formal step - CODI was very stable already)
  • CODI MODULES JPA Core (api + impl) JSF Module (for 1.2 and 2.0 and 2.1) Bean Validation i18N Scripting
  • CODI FEATURES TO NAME A FEW Type-safe and extensible Project Stage Conditional Bean activation Transactional Type-safe view-config and navigation Security Scopes Advanced i18n
  • JBOSS SEAM3 • JBoss Seam – JSR 299 Context and Dependency injection inspiration – Previously named “Web Beans” • JBoss Seam 3, in 2 parts – Weld – CDI reference implementation – Seam3 – Set of CDI portable extensions ?!? • Development stopped
  • JBOSS SEAM :: SOLDER • Basis to write other extensions • @Requires(« »)  highly not portable !!! • High level and user friendly EL wrapper  useful • @Resource of everything (URL, properties, etc) • AnnotatedTypeBuilder, AnnotationInstanceProvider • BeanManagerAware
  • AND MUCH MORE • • • • • • • • • • • • • • • • • • • • • • Seam Solder Apache DeltaSpike Seam Catch Apache DeltaSpike Seam Config Apache Aries Seam Cron TBD Seam Drools Drools Project Seam Faces Apache DeltaSpike and JSF 2.2 Seam Errai Errai Seam InternationalApache DeltaSpike Seam JCR ModeShape Seam JMS JSR 343 Seam Mail cdi-mail Seam Persistence Apache DeltaSpike and JTA 1.1 Seam Remoting Deprecated Seam Reports TBD Seam Rest RESTEasy Seam Security PicketLink Seam Servlet CDI 1.1 Seam Social Agorava Seam Spring Proposed for Apache DeltaSpike Seam Validation Bean Validation 1.1 Seam Wicket Apache Wicket PDF and Spreadsheets TBD
  • APACHE DELTASPIKE IS … • Common code and features between both – JBoss Seam3 – Apache MyFaces CODI • Same developpers – … joining forces to promote CDI • Focus on portability – … tested on a bunch of containers • Open source
  • HISTORY OF APACHE DELTASPIKE • Accepted to join Apache Incubator 12-2011 02-2012 • First release (0.1-incubating) • Core • 2nd release (0.2-incubating) • Core (improved) 04-2012 • Security (New) • Graduation as a top level project 05-2013 • Release 0.5 09-2013
  • DELTASPIKE MODULES JPA Module Core Module JSF Module Security Module Bean Validation Module Data Module
  • DELTASPIKE-CORE • Solves core java problems • No external deps • And Java EE deps • Used as base for all other DeltaSpike modules
  • CORE :: CONFIGURATION • Problem – A binary like a WAR file must not get changed after it got created and tested • How to use the same binary – In Test environment – To propagate it to the staging environment – And finally to production system • But also useful in CDI extensions  not managed (lifecycle) – ConfigResolver as the root class • • • • ConfigResolver#getPropertyValue(String key) ConfigResolver#getAllPropertyValues(String key) ConfigResolver#getProjectStageAwarePropertyValue(String key) ConfigResolver#getProjectStageAwarePropertyValue(String key, String property)
  • CORE :: PROJECT STAGE AND EXCLUDES
  • CORE :: EXCEPTION
  • CORE :: INVOCATION HANDLER
  • CORE :: JMX
  • CORE :: MESSAGES
  • CORE :: BEAN MANAGER PROVIDER Access to the BeanManager in places where it cannot get injected JMX MBean JSF Components JPA Entity Listeners Servlet listener and filters when no Java EE
  • CORE :: EXTENSION HELPERS
  • DELTASPIKE-CDICTRL • CDI does not provide any way to control a CDI container in plain Java SE – What about reusing my CDI stuff in batches? • Control contexts so you can use @RequestScoped beans for example • @Transactional possible for simple transaction needs
  • DELTASPIKE-JPA • Datasource configuration from CODI • Transactional interceptor
  • DELTASPIKE-JPA
  • DELTASPIKE-JPA
  • DELTASPIKE-SECURITY • Merge between JBoss Seam3 and CODI • Based on an Interceptor
  • DELTASPIKE-JSF • • • • • • All Seam3 events (observe all lifecycle events) Type-safe view-config Type-safe JSF Messages Browser tab support New scopes (Window, View, Render, Conversation …) Conversation support • Useful but still under development and industrialisation.
  • DELTASPIKE-DATA • Comes from CDISource • Same idea as Spring-Data but better Java EE integration • Needs an EntityManager exposed via a producer – Which is a common pratice • Even with JPA replacing many repository aspects, the pattern is still useful – But still requiring boilerplate and clutter
  • DELTASPIKE-DATA
  • DELTASPIKE-DATA • Multiple Entity Manager • When good method name makes comments unnecessary
  • DELTASPIKE.NEXT() • • • • Publish the 1.0 soon Finish JSF module Improve Data module Spring Bridge • Anything else you wanna get?
  • THANKS Jean-Louis Monteiro @JLouisMonteiro jlmonteiro@apache.org tomee.apache.org