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

So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfpanagenda
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterMydbops
 
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
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integrationmarketing932765
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024TopCSSGallery
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationKnoldus Inc.
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
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 Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesBernd Ruecker
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...itnewsafrica
 

Recently uploaded (20)

So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL Router
 
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.
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
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 Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architectures
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
 

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!