SlideShare a Scribd company logo
1 of 36
CDI @ Apache
OpenWebBeans and DeltaSpike
        Deep Dive
       Mark Struberg
      Gerhard Petracek
Agenda
●   CDI and its terms
●   Why OpenWebBeans?
●   Portable CDI Extensions
●   CDI by example with DeltaSpike
CDI is a ...
●   JCP specification started in ~2007
    Contexts and Dependency Injection for
    the Java EE platform (CDI) as JSR-299
●   component model designed for Java EE
    (can be used with Java SE)
CDI Features
●   Type-safe Dependency Injection
●   Interceptors
●   Decorators
●   Events
●   SPI for implementing "Portable Extensions"
●   Unified EL integration
What is Dependency Injection?
●   "Inversion Of Control" object creation
●   No more hardcoded dependencies when
    working with Interfaces
    MailService ms = new VerySpecialMailService();
●   Basically the old Factory Pattern
●   Hollywood Principle:
    "Don't call us, we call you!"
●   Macho Principle
    "Dude, gimme that bloody stuff!"
Singletons and Contexts
●   What is a 'Singleton'
●   "exactly one single instance
    in a well specified context"
Built-in CDI Scopes
●   NormalScoped with well defined lifecycle:
    – @ApplicationScoped
    – @SessionScoped
    – @RequestScoped
    – @ConversationScoped
●   'Pseudo Scope':
     – @Dependent
Terms - Managed Bean
●   ... a Java Class and all it's rules to create
    (contextual) instances of that bean.
●   'Managed Beans' in JSR-299 and JSR-346
    doesn't mean JavaBeans!
●   Interface

    Bean<T> extends Contextual<T>
Terms - Contextual Instance
●   ... a Java instance created with the rules of
    the Managed Bean Bean<T>
●   Contextual Instances usually don't get
    injected directly!
Terms - Contextual Reference
●   ... a proxy for a Contextual Instance.
●   Proxies will automatically be created for
    injecting @NormalScope beans and allow
    decoupled scope handling
Bootstrapping & Runtime
●   Creating the meta information at startup
    –   Bean meta-data can be changed
    –   Fail fast (e.g. AmbiguousResolutionException)
●   Contextual Instance creation at runtime
    –   based on the Managed Beans
    –   the Context will maintain the instances
●   Well defined contextual instance
    termination
Why Apache OpenWebBeans?
●   Fast
●   Stable
●   Modular Plugin Architecture
●   Usable
    (e.g. alternative approach for BDAs)
Portable CDI Extensions
●   Apache MyFaces CODI
    http://myfaces.apache.org/extensions/cdi
●   JBoss Seam3
    http://seamframework.org/Seam3
●   Apache DeltaSpike
    http://incubator.apache.org/deltaspike
DeltaSpike closes the gaps
between ...
●   ... Java-EE and the needs of
        real-world applications
●   ... different CDI communities
History of Apache DeltaSpike
CDI in Action with Apache DeltaSpike
DeltaSpike 0.3 - Overview
●   Core
●   JPA
●   Security
●   Container-Control
Interceptors and Producers in action
@Transactional - 1
●   Transactional bean in the application

    @Transactional
    public class MyBean {
      @Inject
      private EntityManager em;
    }
@Transactional - 2
●   Producer and disposer in the application

    @Produces
    @TransactionScoped
    protected EntityManager defaultEntityManager() {
      return …;
    }

    protected void dispose(@Disposes EntityManager em) {
      if (em.isOpen()) {
         em.close();
      }
    }
@Transactional - 3
●   Interceptor annotation in DeltaSpike

    @InterceptorBinding
    public @interface Transactional {
      //...
    }
@Transactional - 4
●   Interceptor implementation in DeltaSpike

    @Interceptor @Transactional
    public class TransactionalInterceptor implements Serializable {

        @Inject private TransactionStrategy ts;

        @AroundInvoke
        public Object executeInTransaction(
          InvocationContext invocationContext)
          throws Exception {
            return ts.execute(invocationContext);
        }
    }
                                                    + config in the beans.xml
Qualifiers in action
@Transactional - 5
●   Transactional bean in the application

    @Transactional
    public class MyBean {
      @Inject
      private @First EntityManager em1;

        @Inject
        private @Second EntityManager em2;
    }
@Transactional - 6
●   Producer implementations in the application

    @Produces @RequestScoped @First
    protected EntityManager firstEntityManager() {
      //...
    }

    @Produces @RequestScoped @Second
    protected EntityManager secondEntityManager() {
      //...
    }
@Transactional - 7
●   Producers and disposers in the application

    protected void disposeFirst(@Disposes @First
      EntityManager em) {
        if (em.isOpen()) {
           em.close();
        }
    }
    protected void disposeSecond(@Disposes @Second
      EntityManager em) {
        if (em.isOpen()) {
           em.close();
      }
    }
@Transactional - 8
●   Qualifier implementations in the application
    @Qualifier
    public @interface First {
    }

    @Qualifier
    public @interface Second {
    }
Events in action
@BeforeJsfRequest - 1
●   Observer in the application

    public void onBeforeJsfRequest(
      @Observes @BeforeJsfRequest
      FacesContext facesContext) {
       //…
    }
@BeforeJsfRequest - 2
●   Fired event in DeltaSpike

    @Inject
    @BeforeJsfRequest
    private Event<FacesContext> beforeJsfRequestEvent;

    this.beforeJsfRequestEvent.fire(facesContext);
@Specializes and @Alternative
@Specializes configs - 1
●   Specialized type-safe config in the
    application

    @Specializes
    public class CustomWindowContextConfig
      extends WindowContextConfig {
        public int getWindowContextTimeoutInMinutes() {
           return 240;
        }
    }
@Specializes configs - 2
●   Config implementation in CODI (/DS)

    @ApplicationScoped
    public class WindowContextConfig {
      public int getWindowContextTimeoutInMinutes() {
        return 60;
      }
      public int getMaxWindowContextCount() {
        return 64;
      }
      //…
    }
@Alternative - 1
●   Alternative implementation in the
    application

    @Alternative
    @Exclude(
      exceptIfProjectStage = ProjectStage.Development.class)
    public class MockedMailService
      implements MailService {
    }




                                                  + config in beans.xml
@Alternative - 2
●   Primary implementation in the application

    public interface MailService {
    }

    @ApplicationScoped
    public class DefaultMailService
      implements MailService {
    }
Apache DeltaSpike.Next
●   Simple answer:
    There is no fixed master plan!
    The future depends on the community
    -> get involved!

More Related Content

What's hot

Spring - CDI Interop
Spring - CDI InteropSpring - CDI Interop
Spring - CDI InteropRay Ploski
 
Polygot Java EE on the GraalVM
Polygot Java EE on the GraalVMPolygot Java EE on the GraalVM
Polygot Java EE on the GraalVMRyan Cuprak
 
MyFaces Extensions Validator r3 News
MyFaces Extensions Validator r3 NewsMyFaces Extensions Validator r3 News
MyFaces Extensions Validator r3 Newsos890
 
Node.js Development with Apache NetBeans
Node.js Development with Apache NetBeansNode.js Development with Apache NetBeans
Node.js Development with Apache NetBeansRyan Cuprak
 
Faster Java EE Builds with Gradle
Faster Java EE Builds with GradleFaster Java EE Builds with Gradle
Faster Java EE Builds with GradleRyan Cuprak
 
Note - Apache Maven Intro
Note - Apache Maven IntroNote - Apache Maven Intro
Note - Apache Maven Introboyw165
 
Developing modern java web applications with java ee 7 and angular js
Developing modern java web applications with java ee 7 and angular jsDeveloping modern java web applications with java ee 7 and angular js
Developing modern java web applications with java ee 7 and angular jsShekhar Gulati
 
OSGi in 5 minutes
OSGi in 5 minutesOSGi in 5 minutes
OSGi in 5 minutesSerge Huber
 
Getting Started with Java EE 7
Getting Started with Java EE 7Getting Started with Java EE 7
Getting Started with Java EE 7Arun Gupta
 
OSGi and Java EE: A Hybrid Approach to Enterprise Java Application Development
OSGi and Java EE: A Hybrid Approach to Enterprise Java Application DevelopmentOSGi and Java EE: A Hybrid Approach to Enterprise Java Application Development
OSGi and Java EE: A Hybrid Approach to Enterprise Java Application DevelopmentSanjeeb Sahoo
 
Step by step guide to create theme for liferay dxp 7
Step by step guide to create theme for liferay dxp 7Step by step guide to create theme for liferay dxp 7
Step by step guide to create theme for liferay dxp 7Azilen Technologies Pvt. Ltd.
 
Open Services Gateway Initiative (OSGI)
Open Services Gateway Initiative (OSGI)Open Services Gateway Initiative (OSGI)
Open Services Gateway Initiative (OSGI)Peter R. Egli
 
Maven for Dummies
Maven for DummiesMaven for Dummies
Maven for DummiesTomer Gabel
 
Java 9 and the impact on Maven Projects (ApacheCon Europe 2016)
Java 9 and the impact on Maven Projects (ApacheCon Europe 2016)Java 9 and the impact on Maven Projects (ApacheCon Europe 2016)
Java 9 and the impact on Maven Projects (ApacheCon Europe 2016)Robert Scholte
 

What's hot (20)

Spring - CDI Interop
Spring - CDI InteropSpring - CDI Interop
Spring - CDI Interop
 
Core java
Core javaCore java
Core java
 
Polygot Java EE on the GraalVM
Polygot Java EE on the GraalVMPolygot Java EE on the GraalVM
Polygot Java EE on the GraalVM
 
MyFaces Extensions Validator r3 News
MyFaces Extensions Validator r3 NewsMyFaces Extensions Validator r3 News
MyFaces Extensions Validator r3 News
 
Java EE 8
Java EE 8Java EE 8
Java EE 8
 
Node.js Development with Apache NetBeans
Node.js Development with Apache NetBeansNode.js Development with Apache NetBeans
Node.js Development with Apache NetBeans
 
Faster Java EE Builds with Gradle
Faster Java EE Builds with GradleFaster Java EE Builds with Gradle
Faster Java EE Builds with Gradle
 
Note - Apache Maven Intro
Note - Apache Maven IntroNote - Apache Maven Intro
Note - Apache Maven Intro
 
Developing modern java web applications with java ee 7 and angular js
Developing modern java web applications with java ee 7 and angular jsDeveloping modern java web applications with java ee 7 and angular js
Developing modern java web applications with java ee 7 and angular js
 
OSGi in 5 minutes
OSGi in 5 minutesOSGi in 5 minutes
OSGi in 5 minutes
 
Getting Started with Java EE 7
Getting Started with Java EE 7Getting Started with Java EE 7
Getting Started with Java EE 7
 
OSGi Presentation
OSGi PresentationOSGi Presentation
OSGi Presentation
 
OSGi and Java EE: A Hybrid Approach to Enterprise Java Application Development
OSGi and Java EE: A Hybrid Approach to Enterprise Java Application DevelopmentOSGi and Java EE: A Hybrid Approach to Enterprise Java Application Development
OSGi and Java EE: A Hybrid Approach to Enterprise Java Application Development
 
Step by step guide to create theme for liferay dxp 7
Step by step guide to create theme for liferay dxp 7Step by step guide to create theme for liferay dxp 7
Step by step guide to create theme for liferay dxp 7
 
Open Services Gateway Initiative (OSGI)
Open Services Gateway Initiative (OSGI)Open Services Gateway Initiative (OSGI)
Open Services Gateway Initiative (OSGI)
 
Java 9 preview
Java 9 previewJava 9 preview
Java 9 preview
 
Reactjs
ReactjsReactjs
Reactjs
 
Intro To OSGi
Intro To OSGiIntro To OSGi
Intro To OSGi
 
Maven for Dummies
Maven for DummiesMaven for Dummies
Maven for Dummies
 
Java 9 and the impact on Maven Projects (ApacheCon Europe 2016)
Java 9 and the impact on Maven Projects (ApacheCon Europe 2016)Java 9 and the impact on Maven Projects (ApacheCon Europe 2016)
Java 9 and the impact on Maven Projects (ApacheCon Europe 2016)
 

Similar to CDI @ Apache: Deep Dive into OpenWebBeans and DeltaSpike

Context and Dependency Injection 2.0
Context and Dependency Injection 2.0Context and Dependency Injection 2.0
Context and Dependency Injection 2.0Brian S. Paskin
 
J2EE vs JavaEE
J2EE vs JavaEEJ2EE vs JavaEE
J2EE vs JavaEEeanimou
 
Context and Dependency Injection
Context and Dependency InjectionContext and Dependency Injection
Context and Dependency InjectionWerner Keil
 
Android App Architecture with modern libs in practice. Our way in R.I.D., Ser...
Android App Architecture with modern libs in practice. Our way in R.I.D., Ser...Android App Architecture with modern libs in practice. Our way in R.I.D., Ser...
Android App Architecture with modern libs in practice. Our way in R.I.D., Ser...Sigma Software
 
DDD Framework for Java: JdonFramework
DDD Framework for Java: JdonFrameworkDDD Framework for Java: JdonFramework
DDD Framework for Java: JdonFrameworkbanq jdon
 
S314168 - What's New in Enterprise Java Bean Technology @ JavaOne Brazil 2010
S314168 - What's New in Enterprise Java Bean Technology @ JavaOne Brazil 2010S314168 - What's New in Enterprise Java Bean Technology @ JavaOne Brazil 2010
S314168 - What's New in Enterprise Java Bean Technology @ JavaOne Brazil 2010Arun Gupta
 
The new and smart way to build microservices - Eclipse MicroProfile
The new and smart way to build microservices - Eclipse MicroProfileThe new and smart way to build microservices - Eclipse MicroProfile
The new and smart way to build microservices - Eclipse MicroProfileEmily Jiang
 
Testable JavaScript: Application Architecture
Testable JavaScript:  Application ArchitectureTestable JavaScript:  Application Architecture
Testable JavaScript: Application ArchitectureMark Trostler
 
Cut your Dependencies with Dependency Injection for East Bay.NET User Group
Cut your Dependencies with Dependency Injection for East Bay.NET User Group Cut your Dependencies with Dependency Injection for East Bay.NET User Group
Cut your Dependencies with Dependency Injection for East Bay.NET User Group Theo Jungeblut
 
Ob1k presentation at Java.IL
Ob1k presentation at Java.ILOb1k presentation at Java.IL
Ob1k presentation at Java.ILEran Harel
 
Building resilient scheduling in distributed systems with Spring
Building resilient scheduling in distributed systems with SpringBuilding resilient scheduling in distributed systems with Spring
Building resilient scheduling in distributed systems with SpringMarek Jeszka
 
Whoops! Where did my architecture go?
Whoops! Where did my architecture go?Whoops! Where did my architecture go?
Whoops! Where did my architecture go?Oliver Gierke
 
Dynamic Groovy Edges
Dynamic Groovy EdgesDynamic Groovy Edges
Dynamic Groovy EdgesJimmy Ray
 
Level Up Your Integration Testing With Testcontainers
Level Up Your Integration Testing With TestcontainersLevel Up Your Integration Testing With Testcontainers
Level Up Your Integration Testing With TestcontainersVMware Tanzu
 
Java EE Connector Architecture 1.6 (JSR 322) Technology
Java EE Connector Architecture 1.6 (JSR 322) TechnologyJava EE Connector Architecture 1.6 (JSR 322) Technology
Java EE Connector Architecture 1.6 (JSR 322) TechnologySivakumar Thyagarajan
 
谷歌 Scott-lessons learned in testability
谷歌 Scott-lessons learned in testability谷歌 Scott-lessons learned in testability
谷歌 Scott-lessons learned in testabilitydrewz lin
 
A Cocktail of Guice and Seam, the missing ingredients for Java EE 6
A Cocktail of Guice and Seam, the missing ingredients for Java EE 6A Cocktail of Guice and Seam, the missing ingredients for Java EE 6
A Cocktail of Guice and Seam, the missing ingredients for Java EE 6Saltmarch Media
 

Similar to CDI @ Apache: Deep Dive into OpenWebBeans and DeltaSpike (20)

Context and Dependency Injection 2.0
Context and Dependency Injection 2.0Context and Dependency Injection 2.0
Context and Dependency Injection 2.0
 
Javaee6 Overview
Javaee6 OverviewJavaee6 Overview
Javaee6 Overview
 
J2EE vs JavaEE
J2EE vs JavaEEJ2EE vs JavaEE
J2EE vs JavaEE
 
Context and Dependency Injection
Context and Dependency InjectionContext and Dependency Injection
Context and Dependency Injection
 
Android App Architecture with modern libs in practice. Our way in R.I.D., Ser...
Android App Architecture with modern libs in practice. Our way in R.I.D., Ser...Android App Architecture with modern libs in practice. Our way in R.I.D., Ser...
Android App Architecture with modern libs in practice. Our way in R.I.D., Ser...
 
DDD Framework for Java: JdonFramework
DDD Framework for Java: JdonFrameworkDDD Framework for Java: JdonFramework
DDD Framework for Java: JdonFramework
 
Java Enterprise Edition
Java Enterprise EditionJava Enterprise Edition
Java Enterprise Edition
 
S314168 - What's New in Enterprise Java Bean Technology @ JavaOne Brazil 2010
S314168 - What's New in Enterprise Java Bean Technology @ JavaOne Brazil 2010S314168 - What's New in Enterprise Java Bean Technology @ JavaOne Brazil 2010
S314168 - What's New in Enterprise Java Bean Technology @ JavaOne Brazil 2010
 
The new and smart way to build microservices - Eclipse MicroProfile
The new and smart way to build microservices - Eclipse MicroProfileThe new and smart way to build microservices - Eclipse MicroProfile
The new and smart way to build microservices - Eclipse MicroProfile
 
Testable JavaScript: Application Architecture
Testable JavaScript:  Application ArchitectureTestable JavaScript:  Application Architecture
Testable JavaScript: Application Architecture
 
Cut your Dependencies with Dependency Injection for East Bay.NET User Group
Cut your Dependencies with Dependency Injection for East Bay.NET User Group Cut your Dependencies with Dependency Injection for East Bay.NET User Group
Cut your Dependencies with Dependency Injection for East Bay.NET User Group
 
Ob1k presentation at Java.IL
Ob1k presentation at Java.ILOb1k presentation at Java.IL
Ob1k presentation at Java.IL
 
Building resilient scheduling in distributed systems with Spring
Building resilient scheduling in distributed systems with SpringBuilding resilient scheduling in distributed systems with Spring
Building resilient scheduling in distributed systems with Spring
 
Whoops! Where did my architecture go?
Whoops! Where did my architecture go?Whoops! Where did my architecture go?
Whoops! Where did my architecture go?
 
Dynamic Groovy Edges
Dynamic Groovy EdgesDynamic Groovy Edges
Dynamic Groovy Edges
 
Spring boot
Spring bootSpring boot
Spring boot
 
Level Up Your Integration Testing With Testcontainers
Level Up Your Integration Testing With TestcontainersLevel Up Your Integration Testing With Testcontainers
Level Up Your Integration Testing With Testcontainers
 
Java EE Connector Architecture 1.6 (JSR 322) Technology
Java EE Connector Architecture 1.6 (JSR 322) TechnologyJava EE Connector Architecture 1.6 (JSR 322) Technology
Java EE Connector Architecture 1.6 (JSR 322) Technology
 
谷歌 Scott-lessons learned in testability
谷歌 Scott-lessons learned in testability谷歌 Scott-lessons learned in testability
谷歌 Scott-lessons learned in testability
 
A Cocktail of Guice and Seam, the missing ingredients for Java EE 6
A Cocktail of Guice and Seam, the missing ingredients for Java EE 6A Cocktail of Guice and Seam, the missing ingredients for Java EE 6
A Cocktail of Guice and Seam, the missing ingredients for Java EE 6
 

Recently uploaded

Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 

Recently uploaded (20)

Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 

CDI @ Apache: Deep Dive into OpenWebBeans and DeltaSpike

  • 1. CDI @ Apache OpenWebBeans and DeltaSpike Deep Dive Mark Struberg Gerhard Petracek
  • 2. Agenda ● CDI and its terms ● Why OpenWebBeans? ● Portable CDI Extensions ● CDI by example with DeltaSpike
  • 3. CDI is a ... ● JCP specification started in ~2007 Contexts and Dependency Injection for the Java EE platform (CDI) as JSR-299 ● component model designed for Java EE (can be used with Java SE)
  • 4. CDI Features ● Type-safe Dependency Injection ● Interceptors ● Decorators ● Events ● SPI for implementing "Portable Extensions" ● Unified EL integration
  • 5. What is Dependency Injection? ● "Inversion Of Control" object creation ● No more hardcoded dependencies when working with Interfaces MailService ms = new VerySpecialMailService(); ● Basically the old Factory Pattern ● Hollywood Principle: "Don't call us, we call you!" ● Macho Principle "Dude, gimme that bloody stuff!"
  • 6. Singletons and Contexts ● What is a 'Singleton' ● "exactly one single instance in a well specified context"
  • 7. Built-in CDI Scopes ● NormalScoped with well defined lifecycle: – @ApplicationScoped – @SessionScoped – @RequestScoped – @ConversationScoped ● 'Pseudo Scope': – @Dependent
  • 8. Terms - Managed Bean ● ... a Java Class and all it's rules to create (contextual) instances of that bean. ● 'Managed Beans' in JSR-299 and JSR-346 doesn't mean JavaBeans! ● Interface Bean<T> extends Contextual<T>
  • 9. Terms - Contextual Instance ● ... a Java instance created with the rules of the Managed Bean Bean<T> ● Contextual Instances usually don't get injected directly!
  • 10. Terms - Contextual Reference ● ... a proxy for a Contextual Instance. ● Proxies will automatically be created for injecting @NormalScope beans and allow decoupled scope handling
  • 11. Bootstrapping & Runtime ● Creating the meta information at startup – Bean meta-data can be changed – Fail fast (e.g. AmbiguousResolutionException) ● Contextual Instance creation at runtime – based on the Managed Beans – the Context will maintain the instances ● Well defined contextual instance termination
  • 12. Why Apache OpenWebBeans? ● Fast ● Stable ● Modular Plugin Architecture ● Usable (e.g. alternative approach for BDAs)
  • 13. Portable CDI Extensions ● Apache MyFaces CODI http://myfaces.apache.org/extensions/cdi ● JBoss Seam3 http://seamframework.org/Seam3 ● Apache DeltaSpike http://incubator.apache.org/deltaspike
  • 14. DeltaSpike closes the gaps between ... ● ... Java-EE and the needs of real-world applications ● ... different CDI communities
  • 15. History of Apache DeltaSpike
  • 16. CDI in Action with Apache DeltaSpike
  • 17. DeltaSpike 0.3 - Overview ● Core ● JPA ● Security ● Container-Control
  • 19. @Transactional - 1 ● Transactional bean in the application @Transactional public class MyBean { @Inject private EntityManager em; }
  • 20. @Transactional - 2 ● Producer and disposer in the application @Produces @TransactionScoped protected EntityManager defaultEntityManager() { return …; } protected void dispose(@Disposes EntityManager em) { if (em.isOpen()) { em.close(); } }
  • 21. @Transactional - 3 ● Interceptor annotation in DeltaSpike @InterceptorBinding public @interface Transactional { //... }
  • 22. @Transactional - 4 ● Interceptor implementation in DeltaSpike @Interceptor @Transactional public class TransactionalInterceptor implements Serializable { @Inject private TransactionStrategy ts; @AroundInvoke public Object executeInTransaction( InvocationContext invocationContext) throws Exception { return ts.execute(invocationContext); } } + config in the beans.xml
  • 24. @Transactional - 5 ● Transactional bean in the application @Transactional public class MyBean { @Inject private @First EntityManager em1; @Inject private @Second EntityManager em2; }
  • 25. @Transactional - 6 ● Producer implementations in the application @Produces @RequestScoped @First protected EntityManager firstEntityManager() { //... } @Produces @RequestScoped @Second protected EntityManager secondEntityManager() { //... }
  • 26. @Transactional - 7 ● Producers and disposers in the application protected void disposeFirst(@Disposes @First EntityManager em) { if (em.isOpen()) { em.close(); } } protected void disposeSecond(@Disposes @Second EntityManager em) { if (em.isOpen()) { em.close(); } }
  • 27. @Transactional - 8 ● Qualifier implementations in the application @Qualifier public @interface First { } @Qualifier public @interface Second { }
  • 29. @BeforeJsfRequest - 1 ● Observer in the application public void onBeforeJsfRequest( @Observes @BeforeJsfRequest FacesContext facesContext) { //… }
  • 30. @BeforeJsfRequest - 2 ● Fired event in DeltaSpike @Inject @BeforeJsfRequest private Event<FacesContext> beforeJsfRequestEvent; this.beforeJsfRequestEvent.fire(facesContext);
  • 32. @Specializes configs - 1 ● Specialized type-safe config in the application @Specializes public class CustomWindowContextConfig extends WindowContextConfig { public int getWindowContextTimeoutInMinutes() { return 240; } }
  • 33. @Specializes configs - 2 ● Config implementation in CODI (/DS) @ApplicationScoped public class WindowContextConfig { public int getWindowContextTimeoutInMinutes() { return 60; } public int getMaxWindowContextCount() { return 64; } //… }
  • 34. @Alternative - 1 ● Alternative implementation in the application @Alternative @Exclude( exceptIfProjectStage = ProjectStage.Development.class) public class MockedMailService implements MailService { } + config in beans.xml
  • 35. @Alternative - 2 ● Primary implementation in the application public interface MailService { } @ApplicationScoped public class DefaultMailService implements MailService { }
  • 36. Apache DeltaSpike.Next ● Simple answer: There is no fixed master plan! The future depends on the community -> get involved!