SlideShare a Scribd company logo
Whoops! Where did my architecture go?
Approaches to architecture management for Java and Spring applications



Oliver Gierke




© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
Oliver Gierke

                                                                                        Spring Data
                                                                                        Core/JPA/MongoDB

                                                                                        ogierke@vmware.com
                                                                                        www.olivergierke.de
                                                                                        olivergierke


© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
Background
                                 Few years of consulting
                                  Lots of code reviews
                                Eoin Woods‘ talk on InfoQ



© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
Roadmap
                                         Architecture 101
                                     A Java packages model
                                              Hera



© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
Architecture 101


© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
Know your
                      dependencies

© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
Granularity
                                                          Modules
                                                           Layers
                                                        Vertical slices
                                                         Subsystems


© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
Granularity
                                                        Java ARchive
                                                          Package
                                                            Class



© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
Of layers
                                  and slices…

© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
Slice A                  Slice B         Slice C


                   Layer 1



                  Layer 2



                  Layer 3



© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
Layers
                                    Well understood
                                 Known to developers
                               Less important to business



© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
Slices
                                             Hardly understood
                                             New to developers
                                            Key for business req



© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
Slice A                  Slice B         Slice C


                   Layer 1



                  Layer 2



                  Layer 3



© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
"                      How to implement
                                  an architecture
                                  inside a codebase?


© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
Architecture
                                VS.
                             Codebase

© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
"                      How to implement
                                  an architecture
                                  inside a codebase?


© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
"                      How to enforce
                                  an architecture
                                  inside a codebase?


© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
Code analysis
                                                                 JDepend
                                                                  Sonar




© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
Demo


© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
Sonargraph
                               Formerly known as SonarJ




© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
Demo


© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
A plain Java
            based approach

© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
Slice A                  Slice B         Slice C


                   Layer 1



                  Layer 2



                  Layer 3



© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
….${layer}.${slice}
             VS.
     ….${slice}.${layer}

© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
Layers first
                          Leaks slice internals
                     Lower layers visible to everyone




© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
"                      Start with less
                                  packages and the
                                  least visibility
                                  possible…

© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
Slice A                  Slice B         Slice C


                   Layer 1



                  Layer 2



                  Layer 3



© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
Slice A                  Slice B         Slice C


                   Layer 1



                  Layer 2



                  Layer 3



© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
Slices first
                 Start with package per slice
             Expose interfaces and domain types
                Keep implementations private



© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
Slices first
                        Encapsulates business module
                         Internals understood anyway




© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
Subsystems


© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
Background
          Risk mgmt. at German public bank
         Quite a few other SpringSource clients




© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
"                      The smallest
                                  plugin system
                                  ever!


© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
Host

                          SPI                                              SPI              SPI



                                  Plugin                                                Plugin


© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
Context
                                      No OSGi
                                    Spring based
                              Build-time composition
                            Don‘t touch the host system


© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
App

                                     Plugin                                             Plugin


                                                                       Host


© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
"                      How to make the
                                  host aware of the
                                  plugins?


© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
"                      How to dynami-
                                  cally collect Spring
                                  beans of a given
                                  type?

© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
classpath*:META-INF/
       spring/plugin-context.xml




© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
classpath*:META-INF/
                                       spring/plugin-context.xml

                          SPI                                              SPI                      SPI


                           META-INF/spring/                                             META-INF/spring/
                           plugin-context.xml                                           plugin-context.xml




© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
@Component
 public class MyComponentImpl implements TransferService {

      private List<MyPlugin> plugins;

      @Autowired
      public MyComponentImpl(List<MyPlugin> plugins) {
        this.plugins = plugins;
      }
      …
 }

 public interface MyPlugin {
   void doSomething();
 }



© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
Demo


© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
XML?
                                                   Back in the days




© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
(XML?)
                           Back in the days
                    Probably not a big deal anymore




© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
Easy access?


© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
@Component
 public class MyComponentImpl implements TransferService {

      private List<MyPlugin> plugins;

      @Autowired
      public MyComponentImpl(List<MyPlugin> plugins) {
        this.plugins = plugins;
      }
      …
 }

 public interface MyPlugin {
   void doSomething();
 }



© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
@Component
 public class MyComponentImpl implements TransferService {

      // Constructor omitted

      public Result myMethod(SomeParameter parameter) {

           // Select the first one to match to invoke?
           // Select multiple ones to invoke?
           // Select and fallback to one if none found?
           // Select and throw an exception if none found?
      }
 }




© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
Plugins
                              Selection criterion
                               Callback method
                        Let the implementation decide



© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
Registry
                                   Equipped with plugins
                                  Common access patterns




© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
public interface Plugin<T> {

      public boolean supports(T delimiter );
 }


 public interface PluginRegistry<S extends Plugin<T>, T> {

      T getPluginFor(S delimiter);
      T getPluginFor(S delimiter, T default);
      <E extends Exception> T getPluginFor(S del, E exception) throws E;

      List<T> getPluginsFor(S delimiter);
      …
 }



© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
@Component
 public class MyComponentImpl implements TransferService {

      private PluginRegistry<MyPlugin, String> plugins;

      @Autowired
      public MyComponentImpl(PluginRegistry<MyPlugin, String> plugins) {
        this.plugins = plugins;
      }
      …
 }

 public interface MyPlugin extends Plugin<String> {
   void doSomething();
 }



© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
@Component
 public class MyComponentImpl implements TransferService {
   private final MyPlugin defaultPlugin = new MyDefaultPlugin();

      public Result myMethod(String parameter) {
        // Select the first one to match to invoke?
        … = plugins.getPluginFor(parameter);
        // Select multiple ones to invoke?
        … = plugins.getPluginsFor(parameter);
        // Select and fallback to one if none found?
        … = plugins.getPluginFor(parameter, defaultPlugin);
        // Select and throw an exception if none found?
        … = plugins.getPluginsFor(parameter, new RuntimeException());
      }
 }



© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
OrderAware
                                 PluginRegistry
                               Respects @Order/Ordered
                                    OAPR.reverse()




© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
Bells‘n‘whistles
                                                 FactoryBean
                                               Spring namespace
                                                   Lazy-eval



© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
Hera


© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
Hera
                                         http://hera.synyx.org
                                              Apache 2.0
                                         Soon to be on GitHub



© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
Spring
                               Integration 2



© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
<bean class="….FirstSamplePlugin" />
 <bean class="….SecondSamplePlugin" />

 <int:channel id="input" />
 <int:channel id="output" />

 <int-hera:dynamic-service-activator
   input-channel="input"
   outputChannel="output"
   plugin-type= "….MyPlugin"
   method= "myBusinessMethod"
   delimiter="payload"
   invocation-arguments= "payload" />




© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
Demo


© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
Take-aways
                             Know your dependencies
                               On every granularity
                             Start as strict as possible
                            Get lenient where necessary


© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
Thanks & credits
                               Eoin Woods - Talk @ InfoQ




© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
Resources
                                        Sourcecode @ GitHub
                                             Sonargraph




© 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.

More Related Content

PDF
LatJUG. Spring Roo
PDF
Mobile trends and impressions
PDF
Coding & Music Passion And Profession
PDF
REST based web applications with Spring 3
PDF
Spring Data and MongoDB
PDF
Whoops! where did my architecture go?
PDF
Spring Data and MongoDB
PDF
Increasing developer procutivity with Mylyn (Devoxx 2010)
LatJUG. Spring Roo
Mobile trends and impressions
Coding & Music Passion And Profession
REST based web applications with Spring 3
Spring Data and MongoDB
Whoops! where did my architecture go?
Spring Data and MongoDB
Increasing developer procutivity with Mylyn (Devoxx 2010)

Viewers also liked (13)

KEY
Sophisticated JPA with Spring & Hades
PDF
Spring Roo 1.0.0 Technical Deep Dive
PDF
Mylyn - Increasing developer productivity
PDF
Generic DAOs With Hades
PDF
PDF
Real world dependency injection - DPC10
PDF
Spring in action - Hades & Spring Roo
PDF
Data Access 2.0? Please welcome, Spring Data!
PDF
An introduction into Spring Data
PDF
Spring integration
PDF
Spring Data JPA - Repositories done right
PDF
Data access 2.0? Please welcome: Spring Data!
PDF
Whoops! Where did my architecture go?
Sophisticated JPA with Spring & Hades
Spring Roo 1.0.0 Technical Deep Dive
Mylyn - Increasing developer productivity
Generic DAOs With Hades
Real world dependency injection - DPC10
Spring in action - Hades & Spring Roo
Data Access 2.0? Please welcome, Spring Data!
An introduction into Spring Data
Spring integration
Spring Data JPA - Repositories done right
Data access 2.0? Please welcome: Spring Data!
Whoops! Where did my architecture go?
Ad

Similar to Whoops! Where did my architecture go? (20)

PDF
An Introduction to Spring Data
PDF
Flash camp portugal - Let's talk about Flex baby
PDF
Shoretel brilliantly simple_overview
PDF
Montpellier - Flex UG
PDF
Project Controls Expo, 13th Nov 2013 - "Integrated Project Planning/Schedulin...
PDF
Converge SE 2011 Building a Strong Foundation
PDF
Flex presentation for Paris Android User group PAUG
PDF
Flexpaug 111207121300-phpapp01
PDF
スマートフォン対策ビジネスセミナー / Session1:Adobe AIRで実現する超生産的スマートフォンアプリ開発
PPTX
Sweet dreams of load testing
PDF
Oop2012 mobile workshops
PDF
engineering mechanics andrew pytelch 11
PDF
Using Google Analytics with jQuery Mobile
PDF
Jenkins Enterprise by CloudBees Webinar
PDF
In The Future We All Use Symfony2
PPTX
Opening opensource : The Jenkins Way
PDF
Project Controls Expo, 13th Nov 2013 - "A new visual way to engage executive ...
PDF
Reasons for Flash: Flash Development in an HTML5 and App Store World
PPTX
SharePoint2010Integration
KEY
360iDev OTA Distribution and Build Automation
An Introduction to Spring Data
Flash camp portugal - Let's talk about Flex baby
Shoretel brilliantly simple_overview
Montpellier - Flex UG
Project Controls Expo, 13th Nov 2013 - "Integrated Project Planning/Schedulin...
Converge SE 2011 Building a Strong Foundation
Flex presentation for Paris Android User group PAUG
Flexpaug 111207121300-phpapp01
スマートフォン対策ビジネスセミナー / Session1:Adobe AIRで実現する超生産的スマートフォンアプリ開発
Sweet dreams of load testing
Oop2012 mobile workshops
engineering mechanics andrew pytelch 11
Using Google Analytics with jQuery Mobile
Jenkins Enterprise by CloudBees Webinar
In The Future We All Use Symfony2
Opening opensource : The Jenkins Way
Project Controls Expo, 13th Nov 2013 - "A new visual way to engage executive ...
Reasons for Flash: Flash Development in an HTML5 and App Store World
SharePoint2010Integration
360iDev OTA Distribution and Build Automation
Ad

Recently uploaded (20)

PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PPT
Teaching material agriculture food technology
PDF
KodekX | Application Modernization Development
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Empathic Computing: Creating Shared Understanding
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Electronic commerce courselecture one. Pdf
PDF
Approach and Philosophy of On baking technology
PPTX
Big Data Technologies - Introduction.pptx
PDF
Modernizing your data center with Dell and AMD
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Reach Out and Touch Someone: Haptics and Empathic Computing
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Teaching material agriculture food technology
KodekX | Application Modernization Development
Review of recent advances in non-invasive hemoglobin estimation
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Empathic Computing: Creating Shared Understanding
NewMind AI Monthly Chronicles - July 2025
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Building Integrated photovoltaic BIPV_UPV.pdf
NewMind AI Weekly Chronicles - August'25 Week I
MYSQL Presentation for SQL database connectivity
Electronic commerce courselecture one. Pdf
Approach and Philosophy of On baking technology
Big Data Technologies - Introduction.pptx
Modernizing your data center with Dell and AMD
Diabetes mellitus diagnosis method based random forest with bat algorithm
“AI and Expert System Decision Support & Business Intelligence Systems”

Whoops! Where did my architecture go?

  • 1. Whoops! Where did my architecture go? Approaches to architecture management for Java and Spring applications Oliver Gierke © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 2. Oliver Gierke Spring Data Core/JPA/MongoDB ogierke@vmware.com www.olivergierke.de olivergierke © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 3. Background Few years of consulting Lots of code reviews Eoin Woods‘ talk on InfoQ © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 4. Roadmap Architecture 101 A Java packages model Hera © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 5. Architecture 101 © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 6. Know your dependencies © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 7. Granularity Modules Layers Vertical slices Subsystems © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 8. Granularity Java ARchive Package Class © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 9. Of layers and slices… © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 10. Slice A Slice B Slice C Layer 1 Layer 2 Layer 3 © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 11. Layers Well understood Known to developers Less important to business © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 12. Slices Hardly understood New to developers Key for business req © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 13. Slice A Slice B Slice C Layer 1 Layer 2 Layer 3 © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 14. " How to implement an architecture inside a codebase? © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 15. Architecture VS. Codebase © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 16. " How to implement an architecture inside a codebase? © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 17. " How to enforce an architecture inside a codebase? © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 18. Code analysis JDepend Sonar © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 19. Demo © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 20. Sonargraph Formerly known as SonarJ © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 21. Demo © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 22. A plain Java based approach © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 23. Slice A Slice B Slice C Layer 1 Layer 2 Layer 3 © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 24. ….${layer}.${slice} VS. ….${slice}.${layer} © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 25. Layers first Leaks slice internals Lower layers visible to everyone © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 26. " Start with less packages and the least visibility possible… © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 27. Slice A Slice B Slice C Layer 1 Layer 2 Layer 3 © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 28. Slice A Slice B Slice C Layer 1 Layer 2 Layer 3 © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 29. Slices first Start with package per slice Expose interfaces and domain types Keep implementations private © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 30. Slices first Encapsulates business module Internals understood anyway © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 31. Subsystems © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 32. Background Risk mgmt. at German public bank Quite a few other SpringSource clients © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 33. " The smallest plugin system ever! © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 34. Host SPI SPI SPI Plugin Plugin © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 35. Context No OSGi Spring based Build-time composition Don‘t touch the host system © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 36. App Plugin Plugin Host © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 37. " How to make the host aware of the plugins? © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 38. " How to dynami- cally collect Spring beans of a given type? © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 39. classpath*:META-INF/ spring/plugin-context.xml © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 40. classpath*:META-INF/ spring/plugin-context.xml SPI SPI SPI META-INF/spring/ META-INF/spring/ plugin-context.xml plugin-context.xml © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 41. @Component public class MyComponentImpl implements TransferService { private List<MyPlugin> plugins; @Autowired public MyComponentImpl(List<MyPlugin> plugins) { this.plugins = plugins; } … } public interface MyPlugin { void doSomething(); } © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 42. Demo © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 43. XML? Back in the days © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 44. (XML?) Back in the days Probably not a big deal anymore © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 45. Easy access? © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 46. @Component public class MyComponentImpl implements TransferService { private List<MyPlugin> plugins; @Autowired public MyComponentImpl(List<MyPlugin> plugins) { this.plugins = plugins; } … } public interface MyPlugin { void doSomething(); } © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 47. @Component public class MyComponentImpl implements TransferService { // Constructor omitted public Result myMethod(SomeParameter parameter) { // Select the first one to match to invoke? // Select multiple ones to invoke? // Select and fallback to one if none found? // Select and throw an exception if none found? } } © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 48. Plugins Selection criterion Callback method Let the implementation decide © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 49. Registry Equipped with plugins Common access patterns © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 50. public interface Plugin<T> { public boolean supports(T delimiter ); } public interface PluginRegistry<S extends Plugin<T>, T> { T getPluginFor(S delimiter); T getPluginFor(S delimiter, T default); <E extends Exception> T getPluginFor(S del, E exception) throws E; List<T> getPluginsFor(S delimiter); … } © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 51. @Component public class MyComponentImpl implements TransferService { private PluginRegistry<MyPlugin, String> plugins; @Autowired public MyComponentImpl(PluginRegistry<MyPlugin, String> plugins) { this.plugins = plugins; } … } public interface MyPlugin extends Plugin<String> { void doSomething(); } © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 52. @Component public class MyComponentImpl implements TransferService { private final MyPlugin defaultPlugin = new MyDefaultPlugin(); public Result myMethod(String parameter) { // Select the first one to match to invoke? … = plugins.getPluginFor(parameter); // Select multiple ones to invoke? … = plugins.getPluginsFor(parameter); // Select and fallback to one if none found? … = plugins.getPluginFor(parameter, defaultPlugin); // Select and throw an exception if none found? … = plugins.getPluginsFor(parameter, new RuntimeException()); } } © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 53. OrderAware PluginRegistry Respects @Order/Ordered OAPR.reverse() © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 54. Bells‘n‘whistles FactoryBean Spring namespace Lazy-eval © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 55. Hera © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 56. Hera http://hera.synyx.org Apache 2.0 Soon to be on GitHub © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 57. Spring Integration 2 © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 58. <bean class="….FirstSamplePlugin" /> <bean class="….SecondSamplePlugin" /> <int:channel id="input" /> <int:channel id="output" /> <int-hera:dynamic-service-activator input-channel="input" outputChannel="output" plugin-type= "….MyPlugin" method= "myBusinessMethod" delimiter="payload" invocation-arguments= "payload" /> © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 59. Demo © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 60. Take-aways Know your dependencies On every granularity Start as strict as possible Get lenient where necessary © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 61. Thanks & credits Eoin Woods - Talk @ InfoQ © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.
  • 62. Resources Sourcecode @ GitHub Sonargraph © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.