Dynamic Guice Applications
Upcoming SlideShare
Loading in...5
×
 

Like this? Share it with your network

Share

Dynamic Guice Applications

on

  • 2,623 views

 

Statistics

Views

Total Views
2,623
Views on SlideShare
2,605
Embed Views
18

Actions

Likes
0
Downloads
23
Comments
0

2 Embeds 18

http://www.slideshare.net 15
http://www.linkedin.com 3

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

CC Attribution-ShareAlike LicenseCC Attribution-ShareAlike License

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Dynamic Guice Applications Presentation Transcript

  • 1. Dynamic Applications
  • 2. 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
  • 3. ● Fluent Java binding API ● Records generic information lost during erasure ● Can be driven by Java / annotations / XML / ...etc...
  • 4. JSR 330 ● New standard for Java dependency injection // Constructor injection // Field injection // Setter injection
  • 5. 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
  • 6. 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
  • 7. What is a dynamic application? ● OSGi lets us dynamically add / remove bundles ● ... without needing to restart the application ● This may add / remove qualified components ● ... but Guice bindings are static
  • 8. Dynamic application vs. static bindings ● How can we resolve this mismatch? ● Need support for dynamic component collections!
  • 9. Injector Graph
  • 10. Bean Locator
  • 11. Dynamic Collections ● Backed by dynamic Iterable of qualified beans ● Iterables updated as injectors come and go ● Copy-on-iteration avoids synchronization overhead ● Weak-ref detects when Iterable not used anymore
  • 12. Qualified Dependencies ● Qualified Map ● Qualified Instance
  • 13. Hinted Dependencies ● Hinted Map ● Hinted List
  • 14. Dynamic Updates ● Passive collections are not enough ● Sometimes need active notifications ● Should we force use of an explicit API? ● ... or use reflection to scan for methods?
  • 15. Mediator Pattern Bean Locator add bean remove bean Mediator POJO
  • 16. Mediator Benefits ● Watching application bean can remain a POJO ● Mediators detected just like any other component ● Created on-demand as bean instances created ● Removed when the watching bean is GC'd
  • 17. Bootstrapping ● Just wrap your Class-Path as a ClassSpace ● ... install the QualifiedScannerModule ● and kick-start Guice injection as usual
  • 18. Time for a Demonstration!
  • 19. What about Peaberry? ● Majority of plugin bindings tied to its lifecycle ● Can simply create one injector per plugin ● For plugin services that are not tied to the lifecycle we need something more dynamic! ● Proxies backed by the OSGi Service Registry
  • 20. Links JSR 330 http://code.google.com/p/atinject/ Guice http://code.google.com/p/google-guice/ Peaberry http://code.google.com/p/peaberry/ 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/
  • 21. Questions?
  • 22. Transfo rm ing th e w ay so ftw are is m ad e .