SlideShare ist ein Scribd-Unternehmen logo
1 von 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!

Weitere ähnliche Inhalte

Was ist angesagt?

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
 

Was ist angesagt? (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)
 

Ähnlich wie 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
 

Ähnlich wie 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
 

Kürzlich hochgeladen

Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 

Kürzlich hochgeladen (20)

Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 

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!