OSGi For Eclipse Developers

  • 5,818 views
Uploaded on

A presentation given at JAX 2009

A presentation given at JAX 2009

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
No Downloads

Views

Total Views
5,818
On Slideshare
0
From Embeds
0
Number of Embeds
5

Actions

Shares
Downloads
0
Comments
1
Likes
17

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide














































Transcript

  • 1. OSGi for Eclipse Developers Chris Aniszczyk (EclipseSource) zx@eclipsesource.com http://twitter.com/caniszczyk Bernd Kolb (SAP) bernd.kolb@sap.com http://twitter.com/berndkolb Martin Lippert (it-agile) lippert@acm.org © 2009 by C. Aniszczyk, B. Kolb | OSGi for Eclipse Developers | April 23rd, 2009
  • 2. Overview • Introduction • Topics Frameworks o Import-Package vs. Require-Bundle o Dynamic Bundles o Versioning o Extensions and Services o Compendium Services o OSGi Tooling o • Conclusion © 2009 by C. Aniszczyk, B. Kolb | OSGi for Eclipse Developers | April 23rd, 2009
  • 3. Introduction • OSGi Alliance Worldwide consortium of technology innovators that advances o OSGi technology • OSGi Technology Set of specifications that define a dynamic component system for o Java OSGi is a lot more than Eclipse • Many Eclipse developers oblivious to OSGi topics • How about starting with a history lesson? © 2009 by C. Aniszczyk, B. Kolb | OSGi for Eclipse Developers | April 23rd, 2009
  • 4. A Blast from the Past... • Eclipse had it's own non-standard plug-in model • OSGi and old Eclipse plug-in model were similar © 2009 by C. Aniszczyk, B. Kolb | OSGi for Eclipse Developers | April 23rd, 2009
  • 5. Eclipse + OSGi FTW • Eclipse went to OSGi in 3.0 with Equinox* The transition went “smoothly” o *http://portal.acm.org/citation.cfm?id=1086616 © 2009 by C. Aniszczyk, B. Kolb | OSGi for Eclipse Developers | April 23rd, 2009
  • 6. © 2009 by C. Aniszczyk, B. Kolb | OSGi for Eclipse Developers | April 23rd, 2009
  • 7. Eclipse folks Plug-In © 2009 by C. Aniszczyk, B. Kolb | OSGi for Eclipse Developers | April 23rd, 2009
  • 8. Eclipse OSGi folks guys Bundle Plug-In © 2009 by C. Aniszczyk, B. Kolb | OSGi for Eclipse Developers | April 23rd, 2009
  • 9. Overview • Introduction • Topics Frameworks o Import-Package vs. Require-Bundle o Dynamic Bundles o Versioning o Extensions and Services o Compendium Services o OSGi Tooling o • Conclusion © 2009 by C. Aniszczyk, B. Kolb | OSGi for Eclipse Developers | April 23rd, 2009
  • 10. Frameworks • There’s a world outside of Eclipse and Equinox © 2009 by C. Aniszczyk, B. Kolb | OSGi for Eclipse Developers | April 23rd, 2009
  • 11. Be aware of special headers… • Forget about: Eclipse-BuddyPolicy o Eclipse-PatchFragment o Eclipse-SourceBundle o Eclipse-… o Otherwise you are tied to Equinox • Tip: PAX Runner to test against multiple frameworks http://wiki.ops4j.org/display/ops4j/Pax+Runner o © 2009 by C. Aniszczyk, B. Kolb | OSGi for Eclipse Developers | April 23rd, 2009
  • 12. Overview • Introduction • Topics Frameworks o Import-Package vs. Require-Bundle o Dynamic Bundles o Versioning o Extensions and Services o Compendium Services o OSGi Tooling o • Conclusion © 2009 by C. Aniszczyk, B. Kolb | OSGi for Eclipse Developers | April 23rd, 2009
  • 13. The Alien called “Import-Package” • Eclipse Dependencies are declared using Require-Bundle o Never heard of Import-Package, sounds strange o Plug-in • OSGi Uuuha, no, please don’t use Require-Bundle at all o o Instead, define dependencies using Import-Package Bundle © 2009 by C. Aniszczyk, B. Kolb | OSGi for Eclipse Developers | April 23rd, 2009
  • 14. What is the difference? • Require-Bundle Imports all exported packages of the bundle, including re- o exported and split bundle packages p-1.0.1 p-1.0.1 q-1.0 q-1.0 t u Require Bundle • Import-Package Import just the package you need o p-1.0 p-1.0.1 q-1.0 q-1.0 t u Import Package © 2009 by C. Aniszczyk, B. Kolb | OSGi for Eclipse Developers | April 23rd, 2009
  • 15. When to use what? • Prefer using Import-Package Lighter coupling between bundles o Less visibilities o Eases refactoring p-1.0.1 o p-1.0 q-1.0 t u q-1.0 • Require-Bundle, when necessary Higher coupling between bundles o Use only for very specific situations: o  split packages (same package in different bundles) © 2009 by C. Aniszczyk, B. Kolb | OSGi for Eclipse Developers | April 23rd, 2009
  • 16. Overview • Introduction • Topics Frameworks o Import-Package vs. Require-Bundle o Dynamic Bundles o Versioning o Extensions and Services o Compendium Services o OSGi Tooling o • Conclusion © 2009 by C. Aniszczyk, B. Kolb | OSGi for Eclipse Developers | April 23rd, 2009
  • 17. Bundles are dynamic? You're kidding… © 2009 by C. Aniszczyk, B. Kolb | OSGi for Eclipse Developers | April 23rd, 2009
  • 18. Dynamics with OSGi • OSGi allows you to manage bundles at runtime Install o Update o Uninstall o • But there is no magic behind the scenes nothing is changed automatically o objects stay the same o references remain valid o • This means you need to cleanup after yourself so the GC can help you! © 2009 by C. Aniszczyk, B. Kolb | OSGi for Eclipse Developers | April 23rd, 2009
  • 19. Updating a bundle at runtime means... • Dependent bundles (with wires to the updated bundle via Require-Bundle or Import-Package) are stopped and re-started • The consequence: updating a bundle might cause the system to “restart” o this is not what I associate with “cool dynamics” o  When programming anticipate OSGi’s dynamics © 2009 by C. Aniszczyk, B. Kolb | OSGi for Eclipse Developers | April 23rd, 2009
  • 20. Think about dependencies • Less is more! Less dependencies o Dependency Inversion Principle (DIP) o • Think more about APIs API in separate bundle o depend only on API bundle o implementation can change o © 2009 by C. Aniszczyk, B. Kolb | OSGi for Eclipse Developers | April 23rd, 2009
  • 21. Overview • Introduction • Topics Frameworks o Import-Package vs. Require-Bundle o Dynamic Bundles o Versioning o Extensions and Services o Compendium Services o OSGi Tooling o • Conclusion © 2009 by C. Aniszczyk, B. Kolb | OSGi for Eclipse Developers | April 23rd, 2009
  • 22. Versioning Guidelines • Bundle-Version: 3.4.2.qualifier  3 - major version  4 - minor version  2 - micro version • From the OSGi specification... • Eclipse Versioning Guidelines  http://wiki.eclipse.org/Version_Numbering © 2009 by C. Aniszczyk, B. Kolb | OSGi for Eclipse Developers | April 23rd, 2009
  • 23. Versioning Bundles • On Bundle level Each Bundle has a version o You should set a version range when using require-bundle o • On Package level Packages should also have a version when exported o o Remember: Import-Package o Package imports should have version ranges as well! • Summary Version everything! o A version isn’t a marketing number! o © 2009 by C. Aniszczyk, B. Kolb | OSGi for Eclipse Developers | April 23rd, 2009
  • 24. Versioning Tools • PDE API Tools  http://www.eclipse.org/pde/pde-api-tools/ • Assists with the mechanics of API evolution Binary compatibility (breaking) issues  API leaks  API freeze issues  Suggestions bundle versions  Runs headless and in your workspace  © 2009 by C. Aniszczyk, B. Kolb | OSGi for Eclipse Developers | April 23rd, 2009
  • 25. Overview • Introduction • Topics Frameworks o Import-Package vs. Require-Bundle o Dynamic Bundles o Versioning o Extensions and Services o Compendium Services o OSGi Tooling o • Conclusion © 2009 by C. Aniszczyk, B. Kolb | OSGi for Eclipse Developers | April 23rd, 2009
  • 26. OSGi Services – another alien… • Services? SOA? Oh no... please no buzzwords!!! • Something like Extension Points? • Hey, wait! o OSGi Services are the key feature to build modular and dynamic apps © 2009 by C. Aniszczyk, B. Kolb | OSGi for Eclipse Developers | April 23rd, 2009
  • 27. OSGi Services – your best friend OSGi Service providers: OSGi Service consumers: implement an interface and register lookup a service via the interface an implementation © 2009 by C. Aniszczyk, B. Kolb | OSGi for Eclipse Developers | April 23rd, 2009
  • 28. Versioned Contracts • the service interface is the contract many consumers possible o many producers possible o • this contract is versioned multiple versions of service might be available o you get only those that matches your dependencies o You cannot get that with extension points singleton bundles − You always get the latest version − © 2009 by C. Aniszczyk, B. Kolb | OSGi for Eclipse Developers | April 23rd, 2009
  • 29. “You come and go” • A bundle is started: services are registered o and available from that on o • A bundle is stopped: services are unregistered o no longer available o • OSGi services are dynamic by definition! + dozens of techniques to deal with these dynamics o © 2009 by C. Aniszczyk, B. Kolb | OSGi for Eclipse Developers | April 23rd, 2009
  • 30. Life Cycle Differences • Services are bound to the ACTIVE state • Extensions are available in RESOLVED state © 2009 by C. Aniszczyk, B. Kolb | OSGi for Eclipse Developers | April 23rd, 2009
  • 31. Declarative and lazy • OSGi services are bound to the active state they need class loading to happen o they need objects to be created o • There are declarative approaches for OSGi services OSGi Declarative Services o OSGi Blueprint o Spring Dynamic Modules o iPOJO o © 2009 by C. Aniszczyk, B. Kolb | OSGi for Eclipse Developers | April 23rd, 2009
  • 32. When to use what? • OSGi Services: Dependencies between bundles o Dynamics o Looser coupling o quot;I provide a service for anybody out therequot; o quot;I need a service and don't care who delivers itquot; o • Extension-Registry: UI contributions (too small for OSGi services) o Non-code contributions o quot;I open up myself for extensions that I don't know upfrontquot; o If you have tons of thousand of extensions o © 2009 by C. Aniszczyk, B. Kolb | OSGi for Eclipse Developers | April 23rd, 2009
  • 33. Overview • Introduction • Topics Frameworks o Import-Package vs. Require-Bundle o Dynamic Bundles o Versioning o Extensions and Services o Compendium Services o OSGi Tooling o • Conclusion © 2009 by C. Aniszczyk, B. Kolb | OSGi for Eclipse Developers | April 23rd, 2009
  • 34. Compendium Services • OSGi has spec’d 20+ services • LogService • EventAdmin • HttpService • Declarative Services • Configuration Admin © 2009 by C. Aniszczyk, B. Kolb | OSGi for Eclipse Developers | April 23rd, 2009
  • 35. LogService • A general purpose message logger (20kb) • LogService Log message, level, exception, service ref, bundle o • LogReaderService Retrieve current or previous log entries o • Note: ExtendedLogService (bug 260672) named loggers o extended log entry (e.g., thread id) o filters for log listeners o © 2009 by C. Aniszczyk, B. Kolb | OSGi for Eclipse Developers | April 23rd, 2009
  • 36. EventAdmin • An inter-bundle pub-sub system (30kb) • EventAdmin publish events synchronously and asynchronously o  postEvent(new Event(quot;com/acme/timerquot;, time ));  sendEvent(new Event(quot;com/acme/timerquot;, time )); • EventHandler handle events based on topics o  handleEvent(Event event) • Event has topic and properties as attributes o © 2009 by C. Aniszczyk, B. Kolb | OSGi for Eclipse Developers | April 23rd, 2009
  • 37. HttpService • A way to register servlets and resources • HttpService Register servlets and resources o • Http Registry (org.eclipse.equinox.http.registry) © 2009 by C. Aniszczyk, B. Kolb | OSGi for Eclipse Developers | April 23rd, 2009
  • 38. Declarative Services • A declarative model for publishing, finding and binding to OSGi services (150kb) • ServiceTracker's – the programmatic way to get a service – suck © 2009 by C. Aniszczyk, B. Kolb | OSGi for Eclipse Developers | April 23rd, 2009
  • 39. Declarative Services Tooling Graphical Editor • Validation • Source Editing • © 2009 by C. Aniszczyk, B. Kolb | OSGi for Eclipse Developers | April 23rd, 2009
  • 40. ConfigAdmin • A service to configure components (bundles) o A configuration is a list of key-value pairs • The configuration admin service persists and distributes these configurations to interested parties • Components to be configured register a ManagedService • To apply several configurations of the same kind you could use a ManagedServiceFactory © 2009 by C. Aniszczyk, B. Kolb | OSGi for Eclipse Developers | April 23rd, 2009
  • 41. Overview • Introduction • Topics Frameworks o Import-Package vs. Require-Bundle o Dynamic Bundles o Versioning o Extensions and Services o Compendium Services o OSGi Tooling o • Conclusion © 2009 by C. Aniszczyk, B. Kolb | OSGi for Eclipse Developers | April 23rd, 2009
  • 42. PDE • Eclipse has been tooling OSGi forever with PDE Plug-ins == Bundles! Blugins? o • PDE Tools: Bundles o Fragments o Declarative Services o • New Plug-in Project wizard has OSGi love © 2009 by C. Aniszczyk, B. Kolb | OSGi for Eclipse Developers | April 23rd, 2009
  • 43. BND • Bundle Tool (BND) creates and diagnoses OSGi bundles o Maven, Eclipse and Ant integration o http://www.aqute.biz/Code/Bnd o • Relies on specification (.bnd file) + classpath • Generates bundle artifacts like manifests • Useful for converting third party libs to bundles © 2009 by C. Aniszczyk, B. Kolb | OSGi for Eclipse Developers | April 23rd, 2009
  • 44. Sigil • Provides OSGi Tooling • http://sigil.codecauldron.org/ • driven by sigil.properties file • BND used under the covers • bundles fetched from repositories  based on your Import-Package statements © 2009 by C. Aniszczyk, B. Kolb | OSGi for Eclipse Developers | April 23rd, 2009
  • 45. © 2009 by C. Aniszczyk, B. Kolb | OSGi for Eclipse Developers | April 23rd, 2009
  • 46. Thank you for your attention! • Questions and feedback welcome! C. Aniszczyk zx@eclipsesource.com http://twitter.com/caniszczyk B. Kolb bernd.kolb@sap.com http://twitter.com/berndkolb M. Lippert (it-agile) lippert@acm.org © 2009 by C. Aniszczyk, B. Kolb | OSGi for Eclipse Developers | April 23rd, 2009