SlideShare une entreprise Scribd logo
1  sur  28
Télécharger pour lire hors ligne
Moving from   to
Why move?
●   Plexus is not widely used outside of Maven

●   Lack of documentation, not always up-to-date

●   Extra steps needed to generate Plexus XML

●   Not type-safe, lacks support for generics
●   Single plexus.xml




●   META-INF/plexus/components.xml (Class-Path)
●   Has annotations, but still need to generate XML
Why               ?
●   Standard:   reference implementation for JSR 330

●   Flexible:   can map all sorts of metadata to bindings

●   Type-safe: detailed messages when things go wrong

●   Modular:    multiple extensions available, OSGi-ready
JSR 330
●   New standard for Java dependency injection


                                    // Constructor injection


               // Field injection




                                     // Setter injection
●   Fluent Java binding API




●   Records generic information lost during erasure

●   Can be driven by Java / annotations / XML / ...etc...
Migration Path
●   Preserve investment in legacy Plexus components
●   Allow gradual migration to JSR 330 annotations




●   Must support mixture of Plexus and JSR 330
Customizing
●   Guice provides an SPI to hook into injections

    ●   TypeListeners called for matching bound types
    ●   Register MembersListeners for custom injection
    ●   Register InjectionListeners for custom lifecycles

●   SPI supports binding introspection / rewriting
Injection Listeners
-y Beans
●   Writing all those listener classes can get tedious
●
    guice-bean library cuts out most of the work

    ●   You provide a BeanBinder implementation
    ●   that can provide PropertyBinders for each type
    ●   which can supply PropertyBindings for each property

●   Bean conventions select field / setter properties
Compatibility Shim
Metadata
●   Canonical form of Plexus bindings

●   Captures @Component implementations
●




●   Maps @Component bean properties to

    ●   @Requirement settings
    ●   @Configuration settings

●   Interns Plexus hint strings to save space
Scanning for                   Metadata
●   ClassSpace abstraction supplies classes / resources

●   Can be backed by Plexus Classworlds or OSGi

●   Plexus XML mapped into Plexus annotations

●   Plexus annotations are interpolated and stored
Converting                    Configuration
●   Builds on top of standard Guice TypeConverters




●   Supports properties, nested collections, and beans
●   Guice SPI lets you add your own TypeConverters
Locating                 Components
●   Guice bindings map Keys to Providers
●   Each Key has a type and optional annotation
●   Plexus components have roles and hints


    Key == Class<Role> + @Named(hint)

●   Uses Guice SPI to find component bindings
Binding                  Components
●   Opposite of locating components

●   @Component roles and hints turned into Keys

●   Keys used to bind component implementations

●   Singleton default, unless strategy is "per-lookup"
Injecting                 Requirements
●   @Requirement           locate Plexus components

●   Handles Maps, Lists, instances, and Wildcards

●   Loggers automatically configured and injected

●   @Configuration          convert constant using type
Managing                    Lifecycles
●   Uses an InjectionListener to listen for bean instances

●   Plexus lifecycle "personality" applied after injection

●   Reverse lifecycle applied when container disposed

●   Need to manage extra metadata (like descriptions)
Time for a Demonstration!
Classworlds
●   Plexus Container API still depends on Classworlds

●   But dependency is much less in guice-plexus-shim

●   Just need to write classworlds-shim around OSGi

●   ... to get Plexus apps running on OSGi containers
Extending JSR 330
●   JSR 330 tells us how to mark dependencies



●   and qualify them (just like with Plexus hints)



●   But it does not say how to mark components
Identifying JSR 330 components
●   Wrap the Class-Path up as a ClassSpace and scan it
●   Look for classes with qualifiers such as @Named




●   Empty @Named means "use class name" instead
●   Binding type found by analysing class hierarchy
Next Steps
●   We can now run Plexus apps on top of Guice
●   ... and start separating apps into OSGi bundles
●   OSGi lets us dynamically add / remove bundles




●   ... but Guice bindings are static
Next Steps
●   How can we resolve this mismatch?




●   Find out in "Dynamic Guice Applications" ...
Links
JSR 330        http://code.google.com/p/atinject/


Guice          http://code.google.com/p/google-guice/


Spice-Inject   http://svn.sonatype.org/spice/trunk/spice-inject


OSGi           http://www.osgi.org/About/HowOSGi


Blog Updates   http://www.sonatype.com/people/author/mcculls/
Questions?
Transfo rm ing th e w ay so ftw are is m ad e .

Contenu connexe

Similaire à Moving From Plexus To Guice

Dynamic Guice Applications
Dynamic Guice ApplicationsDynamic Guice Applications
Dynamic Guice Applications
Stuart McCulloch
 
J2EE vs JavaEE
J2EE vs JavaEEJ2EE vs JavaEE
J2EE vs JavaEE
eanimou
 

Similaire à Moving From Plexus To Guice (20)

Dynamic Guice Applications
Dynamic Guice ApplicationsDynamic Guice Applications
Dynamic Guice Applications
 
NetflixOSS Open House Lightning talks
NetflixOSS Open House Lightning talksNetflixOSS Open House Lightning talks
NetflixOSS Open House Lightning talks
 
node.js 실무 - node js in practice by Jesang Yoon
node.js 실무 - node js in practice by Jesang Yoonnode.js 실무 - node js in practice by Jesang Yoon
node.js 실무 - node js in practice by Jesang Yoon
 
J2EE vs JavaEE
J2EE vs JavaEEJ2EE vs JavaEE
J2EE vs JavaEE
 
Comparison between zookeeper, etcd 3 and other distributed coordination systems
Comparison between zookeeper, etcd 3 and other distributed coordination systemsComparison between zookeeper, etcd 3 and other distributed coordination systems
Comparison between zookeeper, etcd 3 and other distributed coordination systems
 
PostgreSQL, Extensible to the Nth Degree: Functions, Languages, Types, Rules,...
PostgreSQL, Extensible to the Nth Degree: Functions, Languages, Types, Rules,...PostgreSQL, Extensible to the Nth Degree: Functions, Languages, Types, Rules,...
PostgreSQL, Extensible to the Nth Degree: Functions, Languages, Types, Rules,...
 
Balisage - EXPath Packaging
Balisage - EXPath PackagingBalisage - EXPath Packaging
Balisage - EXPath Packaging
 
Puppet managed loadays
Puppet managed loadaysPuppet managed loadays
Puppet managed loadays
 
GlassFish OSGi - Java2days 2010
GlassFish OSGi - Java2days 2010GlassFish OSGi - Java2days 2010
GlassFish OSGi - Java2days 2010
 
Osgi
OsgiOsgi
Osgi
 
What's brewing in the eZ Systems extensions kitchen
What's brewing in the eZ Systems extensions kitchenWhat's brewing in the eZ Systems extensions kitchen
What's brewing in the eZ Systems extensions kitchen
 
Scaling AngularJS: Enterprise SOA on the MEAN Stack (Responsive Web & Mobile)
Scaling AngularJS: Enterprise SOA on the MEAN Stack (Responsive Web & Mobile)Scaling AngularJS: Enterprise SOA on the MEAN Stack (Responsive Web & Mobile)
Scaling AngularJS: Enterprise SOA on the MEAN Stack (Responsive Web & Mobile)
 
Java EE 6 & GlassFish V3 - Alexis Moussine-Pouchkine - May 2010
Java EE 6 & GlassFish V3 - Alexis Moussine-Pouchkine - May 2010Java EE 6 & GlassFish V3 - Alexis Moussine-Pouchkine - May 2010
Java EE 6 & GlassFish V3 - Alexis Moussine-Pouchkine - May 2010
 
Lupus Decoupled Drupal - Drupal Austria Meetup - 2023-04.pdf
Lupus Decoupled Drupal - Drupal Austria Meetup - 2023-04.pdfLupus Decoupled Drupal - Drupal Austria Meetup - 2023-04.pdf
Lupus Decoupled Drupal - Drupal Austria Meetup - 2023-04.pdf
 
Glassfish An Introduction
Glassfish An IntroductionGlassfish An Introduction
Glassfish An Introduction
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework
 
Netflix oss season 1 episode 3
Netflix oss season 1 episode 3 Netflix oss season 1 episode 3
Netflix oss season 1 episode 3
 
I know Java, why should I consider Clojure?
I know Java, why should I consider Clojure?I know Java, why should I consider Clojure?
I know Java, why should I consider Clojure?
 
OTN Developer Days - GlassFish
OTN Developer Days - GlassFishOTN Developer Days - GlassFish
OTN Developer Days - GlassFish
 
Spring Framework Presantation Part 1-Core
Spring Framework Presantation Part 1-CoreSpring Framework Presantation Part 1-Core
Spring Framework Presantation Part 1-Core
 

Dernier

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Dernier (20)

GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
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
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
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
 
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
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 

Moving From Plexus To Guice

  • 2. Why move? ● Plexus is not widely used outside of Maven ● Lack of documentation, not always up-to-date ● Extra steps needed to generate Plexus XML ● Not type-safe, lacks support for generics
  • 3. Single plexus.xml ● META-INF/plexus/components.xml (Class-Path)
  • 4. Has annotations, but still need to generate XML
  • 5. Why ? ● Standard: reference implementation for JSR 330 ● Flexible: can map all sorts of metadata to bindings ● Type-safe: detailed messages when things go wrong ● Modular: multiple extensions available, OSGi-ready
  • 6. JSR 330 ● New standard for Java dependency injection // Constructor injection // Field injection // Setter injection
  • 7. Fluent Java binding API ● Records generic information lost during erasure ● Can be driven by Java / annotations / XML / ...etc...
  • 8. Migration Path ● Preserve investment in legacy Plexus components ● Allow gradual migration to JSR 330 annotations ● Must support mixture of Plexus and JSR 330
  • 9. Customizing ● Guice provides an SPI to hook into injections ● TypeListeners called for matching bound types ● Register MembersListeners for custom injection ● Register InjectionListeners for custom lifecycles ● SPI supports binding introspection / rewriting
  • 11. -y Beans ● Writing all those listener classes can get tedious ● guice-bean library cuts out most of the work ● You provide a BeanBinder implementation ● that can provide PropertyBinders for each type ● which can supply PropertyBindings for each property ● Bean conventions select field / setter properties
  • 13. Metadata ● Canonical form of Plexus bindings ● Captures @Component implementations ● ● Maps @Component bean properties to ● @Requirement settings ● @Configuration settings ● Interns Plexus hint strings to save space
  • 14. Scanning for Metadata ● ClassSpace abstraction supplies classes / resources ● Can be backed by Plexus Classworlds or OSGi ● Plexus XML mapped into Plexus annotations ● Plexus annotations are interpolated and stored
  • 15. Converting Configuration ● Builds on top of standard Guice TypeConverters ● Supports properties, nested collections, and beans ● Guice SPI lets you add your own TypeConverters
  • 16. Locating Components ● Guice bindings map Keys to Providers ● Each Key has a type and optional annotation ● Plexus components have roles and hints Key == Class<Role> + @Named(hint) ● Uses Guice SPI to find component bindings
  • 17. Binding Components ● Opposite of locating components ● @Component roles and hints turned into Keys ● Keys used to bind component implementations ● Singleton default, unless strategy is "per-lookup"
  • 18. Injecting Requirements ● @Requirement locate Plexus components ● Handles Maps, Lists, instances, and Wildcards ● Loggers automatically configured and injected ● @Configuration convert constant using type
  • 19. Managing Lifecycles ● Uses an InjectionListener to listen for bean instances ● Plexus lifecycle "personality" applied after injection ● Reverse lifecycle applied when container disposed ● Need to manage extra metadata (like descriptions)
  • 20. Time for a Demonstration!
  • 21. Classworlds ● Plexus Container API still depends on Classworlds ● But dependency is much less in guice-plexus-shim ● Just need to write classworlds-shim around OSGi ● ... to get Plexus apps running on OSGi containers
  • 22. Extending JSR 330 ● JSR 330 tells us how to mark dependencies ● and qualify them (just like with Plexus hints) ● But it does not say how to mark components
  • 23. Identifying JSR 330 components ● Wrap the Class-Path up as a ClassSpace and scan it ● Look for classes with qualifiers such as @Named ● Empty @Named means "use class name" instead ● Binding type found by analysing class hierarchy
  • 24. Next Steps ● We can now run Plexus apps on top of Guice ● ... and start separating apps into OSGi bundles ● OSGi lets us dynamically add / remove bundles ● ... but Guice bindings are static
  • 25. Next Steps ● How can we resolve this mismatch? ● Find out in "Dynamic Guice Applications" ...
  • 26. Links JSR 330 http://code.google.com/p/atinject/ Guice http://code.google.com/p/google-guice/ Spice-Inject http://svn.sonatype.org/spice/trunk/spice-inject OSGi http://www.osgi.org/About/HowOSGi Blog Updates http://www.sonatype.com/people/author/mcculls/
  • 28. Transfo rm ing th e w ay so ftw are is m ad e .