Your SlideShare is downloading. ×

OSGi for mere mortals

3,593
views

Published on

Slides of my "OSGi for mere mortals" talk at ApacheCon NA 2011, http://na11.apachecon.com/talks/19416

Slides of my "OSGi for mere mortals" talk at ApacheCon NA 2011, http://na11.apachecon.com/talks/19416

Published in: Technology

0 Comments
8 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
3,593
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
102
Comments
0
Likes
8
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. OSGifor mere mortals Simple and robus t sof t ware is go o d f or yo ur wor k-life b alance .Bertrand DelacrétazSenior Developer, Adobe Digital Enterprise Systems, www.day.comApache So ware Foundation Member and (current) Directorh p://grep.codeconsult.ch - twi er: @bdelacretaz - bdelacretaz@apache.orgApacheCon North America 2011, Vancouver, November 2011slides revision: 2011-11-05 (on a plane)OSGi for 1Mere Mortals 1
  • 2. what? a simple RESTful server built from scratch on OSGi to show that it’s not rocket science, even starting from scratch...OSGi forMere Mortals 2
  • 3. RESTfulcontent:POST to store server?$ date | curl -T - -X POST -D - http://localhost:8080/store/exampleHTTP/1.1 201 CreatedLocation: /store/exampleContent-Type: text/plain; charset=utf-8Content-Length: 178Server: Jetty(6.1.x)Stored at /store/exampleStoredBy:ch.x42.osgi.samples.osgi101.app.servlets.StorageServletStoredAt:Fri Nov 04 10:41:30 CET 2011Path:/store/exampleFri Nov 4 10:41:30 CET 2011OSGi forMere Mortals 3
  • 4. RESTful server!GET to retrieve content:$ curl http://localhost:8080/store/exampleStoredBy:ch.x42.osgi.samples.osgi101.app.servlets.StorageServletStoredAt:Fri Nov 04 10:41:30 CET 2011Path:/store/exampleFri Nov 4 10:41:30 CET 2011 In terms of functionality, that’s it!OSGi forMere Mortals 4
  • 5. It’s not big... 107 ./app/pom.xml 35 ./app/.../InMemoryStorage.java 34 ./app/.../PathsStorage.java 147 ./app/.../StorageServlet.java 101 ./core/pom.xml 6 ./core/...CoreConstants.java 32 ./core/...DefaultGetServlet.java 32 ./core/...DefaultPostServlet.java 116 ./core/...DispatcherServlet.java 8 ./core/...Storage.java 208 ./launcher/pom.xml 84 ./launcher/...OsgiBootstrap.java 52 ./pom.xml 962 lines in total, including 468 lines in pom.xml files...OSGi forMere Mortals 5
  • 6. Components Dynamic Services Server OSGi framework Application core Application services Bootstrapping and standard services HTTP HttpService Dispatcher InMemoryStorage Servlet Services Components Default POST Runtime (SCR) StorageServlet Servlet Configuration Default GET PathsStorage Servlet Logging HTTP Felix Web Console shell Felix Shell indicates SCR ser vices also: maven-bundle plugin maven-scr-pluginOSGi for maven-dependency-pluginMere Mortals 6
  • 7. Bootstrapping and loading bundlesOSGi for 7Mere Mortals 7
  • 8. Framework start and stopCalled from a plain main() methodOSGi forMere Mortals 8
  • 9. Get bundles from Maven repoCopy to a folder using maven-dependency-plugin in launcherOSGi forMere Mortals 9
  • 10. Install bundles from lesystemBundleContext.installBundle(URL)Install all bundles rst, then start allOSGi forMere Mortals 10
  • 11. Live bundles listFrom the Felix console at /system/console We’re good to go!OSGi forMere Mortals 11
  • 12. Our OSGi bundles HttpService org.apache.felix.h p.je y Logging org.apache.sling.commons.log Services Components Runtime (SCR) org.apache.felix.scr Configuration org.apache.felix.metatype org.apache.felix.con gadmin Felix Shell org.apache.felix.shell org.apache.felix.shell.tui Felix Web Console org.apache.felix.webconsole Application Core osgi-for-mere-mortals-core Application Services osgi-for-mere-mortals-appOSGi forMere Mortals 12
  • 13. Dispatcher ServletOSGi for 13Mere Mortals 13
  • 14. DispatcherServletforComponentRegister with H pService and watch Servlet services Dispatcher ServletOSGi forMere Mortals 14
  • 15. DispatcherServletServletsDispatch to OSGi services which are Dispatcher Servlet Default GET ServletOSGi forMere Mortals 15
  • 16. Default GET ServletOSGi for 16Mere Mortals 16
  • 17. Default GETSCR annotationsJust a servlet, with some servlet Default GET ServletOSGi forMere Mortals 17
  • 18. Storage ServicesOSGi for 18Mere Mortals 18
  • 19. Storage service interfaceDe ned in the core bundle, package is exportedOSGi forMere Mortals 19
  • 20. Storage service#1: in memoryActive by defaultOSGi forMere Mortals 20
  • 21. Storage service#2: can be activated in consoleAlternate service, inactive by default, just pathsOSGi forMere Mortals 21
  • 22. Storage ServletOSGi for 22Mere Mortals 22
  • 23. StorageServlet serviceUses @Reference to get a Storage Properties used by DispatcherSer vlet The Component will only start once a Storage service is availableOSGi forMere Mortals 23
  • 24. Alternate Storage demoOSGi for 24Mere Mortals 24
  • 25. Replaceone and enabling another ComponentStorageBy disabling In-memory with paths 1) disable inMemoryStorage -> StorageServlet stops 2) enable PathsStorage -> StorageServlet is backOSGi forMere Mortals 25
  • 26. Con guration demoOSGi for 26Mere Mortals 26
  • 27. Configuring the StorageServletCon gurationAdmin service, console and annotations1) User provides con guration data in web console (or Felix shell, Sling Installer, ...) Felix Web Console2) Console (con guration agent) changes values ConfigurationAdmin StorageServlet3) Con gurationAdmin deactivates andreactivates Component with new Con g 0) Component has metatype=true and someOSGi for non-private @Property annotationsMere Mortals 27
  • 28. StorageServlet Configuration codeAnnotations + read values in activate() Parameter names + descriptions in metatype.propertiesOSGi forMere Mortals 28
  • 29. Conclusions 29
  • 30. ConclusionsPowerful out of the boxinfrastructure, not muchcode to write.Modular component-basedarchitecture.Dynamic (re)con guration,both in terms of componentsand parameters.OSGi materializes the component-based programmingvision in Java, and using it is not rocket science! Code at github.com/bdelacretaz/OSGi-for-mere-mortals Your host today: @bdelacretaz, grep.codeconsult.chOSGi forMere Mortals 30

×