Your SlideShare is downloading. ×
Osgi Democamp
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Osgi Democamp

1,685
views

Published on

Introduction to OSGi by Yanai Franchi

Introduction to OSGi by Yanai Franchi

Published in: Travel, Technology

1 Comment
9 Likes
Statistics
Notes
No Downloads
Views
Total Views
1,685
On Slideshare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
0
Comments
1
Likes
9
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. Open Your Eyes To OSGi By : Yanai Franchi Chief Architect , Tikal Eclipse DemoCamps Galileo 2009/Tel Aviv
  • 2. Agenda  Introduction – What is OSGi ? – What problems does it help us to solve ? – How does it work ?  OSGi programming model – Live Demo  OSGi in Enterprise Applications – Spring DM Copyright 2009 Tikal Knowledge, Ltd. | 2 |
  • 3. OSG - what? Copyright 2009 Tikal Knowledge, Ltd. | 3 |
  • 4. OSGi Acronym O = Open S = Services G = Gateway i = initiative Copyright 2009 Tikal Knowledge, Ltd. | 4 |
  • 5. TM OSGi OSGi TM The Dynamic Module System For Java Copyright 2009 Tikal Knowledge, Ltd. | 5 |
  • 6. Original OSGi Vision Copyright 2009 Tikal Knowledge, Ltd. | 6 |
  • 7. Who's Doing It ?  Open source implementation » Equinox » Felix » Knoplerfish  Significant enterprise Java usage » Eclipse » IBM – WebSphere, Lotus » JonAS » BEA » Oracle » JBoss » SpringSource Copyright 2009 Tikal Knowledge, Ltd. | 7 |
  • 8. Why Do We Need OSGi ? Copyright 2009 Tikal Knowledge, Ltd. | 8 |
  • 9. The Humble JAR File Copyright 2009 Tikal Knowledge, Ltd. | 9 |
  • 10. Typical Java Application Copyright 2009 Tikal Knowledge, Ltd. | 10 |
  • 11. Copyright 2009 Tikal Knowledge, Ltd. | 11 |
  • 12. Our Application Stack... Copyright 2009 Tikal Knowledge, Ltd. | 12 |
  • 13. No Runtime Representation Copyright 2009 Tikal Knowledge, Ltd. | 13 |
  • 14. Loading Classes... Copyright 2009 Tikal Knowledge, Ltd. | 14 |
  • 15. ...The ClassLoader Found One Copyright 2009 Tikal Knowledge, Ltd. | 15 |
  • 16. ...But I Need The Other Class :( Copyright 2009 Tikal Knowledge, Ltd. | 16 |
  • 17. Copyright 2009 Tikal Knowledge, Ltd. | 17 |
  • 18. Dependency Graph Copyright 2009 Tikal Knowledge, Ltd. | 18 |
  • 19. Still Something Wrong  Classes can be tightly coupled  Even across module boundaries Copyright 2009 Tikal Knowledge, Ltd. | 19 |
  • 20. Copyright 2009 Tikal Knowledge, Ltd. | 20 |
  • 21. We Have a Problem... Copyright 2009 Tikal Knowledge, Ltd. | 21 |
  • 22. ...A Big One... Copyright 2009 Tikal Knowledge, Ltd. | 22 |
  • 23. ...It Crashed :( Copyright 2009 Tikal Knowledge, Ltd. | 23 |
  • 24. Need to Decouple Copyright 2009 Tikal Knowledge, Ltd. | 24 |
  • 25. Late Binding Copyright 2009 Tikal Knowledge, Ltd. | 25 |
  • 26. Why Did Eclipse Adopt OSGi ? Copyright 2009 Tikal Knowledge, Ltd. | 26 |
  • 27. Pre-OSGi Eclipse (<3.0) • Metadata in plugin.xml: • Meaningful Name, Vendor • Version • Dependencies • Private Internals • De-Coupling Framework (Extension Registry) Copyright 2009 Tikal Knowledge, Ltd. | 27 |
  • 28. What Is Missing ??? Copyright 2009 Tikal Knowledge, Ltd. | 28 |
  • 29. Copyright 2009 Tikal Knowledge, Ltd. | 29 |
  • 30. Copyright 2009 Tikal Knowledge, Ltd. | 30 |
  • 31. But in Eclipse... Copyright 2009 Tikal Knowledge, Ltd. | 31 |
  • 32. A Little Open-Heart Surgery • Equinox project started February 2003 • Replace old Eclipse runtime with OSGi • Enhance OSGi standard • Eclipse 3.0 released June 2004 Copyright 2009 Tikal Knowledge, Ltd. | 32 |
  • 33. OSGi Architectural Copyright 2009 Tikal Knowledge, Ltd. | 33 |
  • 34. Bundle  By default a bundle is a black box » Completely protected » You can NOT see inside it • Not even by reflection • Or any other class loading trickery Copyright 2009 Tikal Knowledge, Ltd. | 34 |
  • 35. How Does It Look Like ?  Its a jar file!  No complicated tools or sophisticated packaging required. META-INF/MANIFEST.MF Bundle-Name: Hello World Bundle-SymbolicName: com.tikal.osgi.sample.helloworld Bundle-Version: 2.1.0 Export-Package: com.tikal.osgi.sample Import-Package: com.tikal.osgi.weather ,org.osgi.framework Bundle-Activator: com.tikal.osgi.sample.HelloActivator Copyright 2009 Tikal Knowledge, Ltd. | 35 |
  • 36. Bundle Visibility  Exposing Types can be done explicitly » A bundle can export one or more packages » Optionally with versioning information  Only exported packages are visibly outside of the exporting bundle. » Stops unintended coupling between bundles » Enable independent development » Faster development cycles Copyright 2009 Tikal Knowledge, Ltd. | 36 |
  • 37. Bundle Visibility Cont. Service interface types exported with version information Export-Packages: a,b,c private packages “Passive” contribution Service Types added to type space implementation bundles see new version on locked away resolution after install/refresh Copyright 2009 Tikal Knowledge, Ltd. | 37 |
  • 38. Bundle's Life Cycle– Dynamic ! Copyright 2009 Tikal Knowledge, Ltd. | 38 |
  • 39. OSGi Wiring Copyright 2009 Tikal Knowledge, Ltd. | 39 |
  • 40. OSGi Wiring Copyright 2009 Tikal Knowledge, Ltd. | 40 |
  • 41. OSGi Wiring Copyright 2009 Tikal Knowledge, Ltd. | 41 |
  • 42. Versioning MVC Service Repository ' Copyright 2009 Tikal Knowledge, Ltd. | 42 |
  • 43. Versioning MVC Two versions of the same service type... at the same Service Service ' time! Repository ' Copyright 2009 Tikal Knowledge, Ltd. | 43 |
  • 44. Versioning Copyright 2009 Tikal Knowledge, Ltd. | 44 |
  • 45. Operational Control  See all bundles and their status » OSGi console » Web Console » JMX  Get information on wiring  Install new bundles  Activate/Deactivate bundles (and publish services)  Refresh bundles  Stop bundles  Uninstall bundles All without stop or restart the application Copyright 2009 Tikal Knowledge, Ltd. | 45 |
  • 46. OSGi - Lessons Learned • Visibility • Versioning • Operational Control Copyright 2009 Tikal Knowledge, Ltd. | 46 |
  • 47. OSGi Programming  All access to OSGi is through BundleContext  This is supplied to our BundleActivator Copyright 2009 Tikal Knowledge, Ltd. | 47 |
  • 48. BundleActivator Bundle-Name: Hello World Bundle-SymbolicName: com.tikal.osgi.sample.helloworld Bundle-Activator: com.tikal.osgi.sample.HelloActivator public class HelloActivator implements BundleActivator { public void start(BundleContext context) throws Exception { System.out.println(“Hello, world!”); System.out.println(Arrays.asList(context.getBundles())); } public void stop(BundleContext context) throws Exception { System.out.println(“Goodbye, world!”); } } Copyright 2009 Tikal Knowledge, Ltd. | 48 |
  • 49. Hello-World DEMO Copyright 2009 Tikal Knowledge, Ltd. | 49 |
  • 50. Services in OSGi Copyright 2009 Tikal Knowledge, Ltd. | 50 |
  • 51. SOA Architecture  The OSGi framework promotes a service-oriented interaction pattern among bundles Copyright 2009 Tikal Knowledge, Ltd. | 51 |
  • 52. SOA For The JVM Published Services “Active” contribution Private Services published in implementation registry objects bundles see service changes immediately Copyright 2009 Tikal Knowledge, Ltd. | 52 |
  • 53. SOA in OSGi Copyright 2009 Tikal Knowledge, Ltd. | 53 |
  • 54. SOA in OSGi Copyright 2009 Tikal Knowledge, Ltd. | 54 |
  • 55. SOA in OSGi Copyright 2009 Tikal Knowledge, Ltd. | 55 |
  • 56. SOA in OSGi Copyright 2009 Tikal Knowledge, Ltd. | 56 |
  • 57. SOA in OSGi Copyright 2009 Tikal Knowledge, Ltd. | 57 |
  • 58. Example: Paint Program Copyright 2009 Tikal Knowledge, Ltd. | 58 |
  • 59. Naive Class Diagram Copyright 2009 Tikal Knowledge, Ltd. | 59 |
  • 60. Register Is Easy... Hashtable dict = new Hashtable(); dict.put(SimpleShape.NAME_PROPERTY, "Square"); dict.put(SimpleShape.ICON_PROPERTY, new ImageIcon(getClass().getResource("square.png"))); context.registerService(SimpleShape.class.getName(), new Square(),dict); Copyright 2009 Tikal Knowledge, Ltd. | 60 |
  • 61. Consume Is ... Copyright 2009 Tikal Knowledge, Ltd. | 61 |
  • 62. First Attempt ServiceReference ref = context.getServiceReference( SimpleShape.class.getName()); SimpleShape shape = (SimpleShape) context.getService(ref) shape.draw(); Copyright 2009 Tikal Knowledge, Ltd. | 62 |
  • 63. Oops, “ref” can be Null ServiceReference ref = context.getServiceReference( SimpleShape.class.getName()); if(ref != null) { SimpleShape shape = (SimpleShape) context.getService(ref) shape.draw(); } Copyright 2009 Tikal Knowledge, Ltd. | 63 |
  • 64. Oops, “shape” can be Null ServiceReference ref = context.getServiceReference( SimpleShape.class.getName()); if(ref != null) { SimpleShape shape = (SimpleShape) context.getService(ref); if(shape != null) shape.draw(); } Copyright 2009 Tikal Knowledge, Ltd. | 64 |
  • 65. How ??? Copyright 2009 Tikal Knowledge, Ltd. | 65 |
  • 66. Oops, Need to Clean Up ServiceReference ref = context.getServiceReference( SimpleShape.class.getName()); if(ref != null) { SimpleShape shape = (SimpleShape) context.getService(ref); if(shape != null){ try{ shape.draw(); }finally{ context.ungetService(ref); } } Copyright 2009 Tikal Knowledge, Ltd. | 66 |
  • 67. Copyright 2009 Tikal Knowledge, Ltd. | 67 |
  • 68. ServiceTracker  Shape Tracker goal – Use Inversion of Control principles to inject shapes into application » Created by the BundleActivator » Puts tracking logic in one place » Isolates application from OSGi API  User “Observer” design pattern to track services for clients. Copyright 2009 Tikal Knowledge, Ltd. | 68 |
  • 69. Connecting The Dots Copyright 2009 Tikal Knowledge, Ltd. | 69 |
  • 70. Connecting The Dots Copyright 2009 Tikal Knowledge, Ltd. | 70 |
  • 71. Connecting The Dots Copyright 2009 Tikal Knowledge, Ltd. | 71 |
  • 72. Shapes DEMO Copyright 2009 Tikal Knowledge, Ltd. | 72 |
  • 73. Distributed OSGi... Its Here... Copyright 2009 Tikal Knowledge, Ltd. | 73 |
  • 74. OSGi in ... Enterprise Applications Copyright 2009 Tikal Knowledge, Ltd. | 74 |
  • 75. A Typical JEE Application D Web Application D Lib Lib Context D D Lib Lib D D Middle-tier Lib Context Lib Lib D Copyright 2009 Tikal Knowledge, Ltd. | 75 |
  • 76. JEE Application Base on OSGi Each bundle is a segregated class space MVC MVC MVC Lib Lib Service Service Lib Domain Repository Repository Copyright 2009 Tikal Knowledge, Ltd. | 76 |
  • 77. JEE Application on OSGi ?  How can we exploit OSGi » Without adding complexity ? » Retaining our programming model?  We want to treat bundles as beans » Instantiated, Configure, Assemble, Decorate » We want to easy way to publish/consume services • Dynamic management » Should we code this ourselves? » Preserve ability to test Copyright 2009 Tikal Knowledge, Ltd. | 77 |
  • 78. Spring-DM Kernel  Integrates the simplicity and power of Spring... ...with the dynamic module system of OSGi – Use spring container to configure bundles – Make it easy to publish/subscribe services – Application can be coded with minimal OSGi code • Also easy test/integration-test POJO development on OSGi Copyright 2009 Tikal Knowledge, Ltd. | 78 |
  • 79. Spring-DM Kernel Cont.  NO OSGi code & NO Spring code » No BundleActivator » No ServiceTracker » No Spring invasive code  A Spring application context based on OSGi bundle. » OsgiBundleApplicationContext  Enables UnitTest and Integration Test Copyright 2009 Tikal Knowledge, Ltd. | 79 |
  • 80. Bring POJO to OSGi Services <bean name="bookDao" class="com....BookDaoImpl" /> <property name=”datasource” ref=”datasource”/> </bean> <osgi:service id="bookDaoOsgi" ref="bookDao" interface="com.tikal...BookDao" /> <bean name="bookService" class="com.tikal....BookServiceImpl"> <property name="bookDao"> <osgi:reference interface="com.tikal...BookDao" /> </property> </bean> Copyright 2009 Tikal Knowledge, Ltd. | 80 |
  • 81. Spring dm Server Copyright 2009 Tikal Knowledge, Ltd. | 81 |
  • 82. Copyright 2009 Tikal Knowledge, Ltd. | 82 |
  • 83. Summary  OSGi is a dynamic module system for Java » Proven » Scalable (up and down)  OSGi Offer benefits in terms of » Modularity (visibility) » Versioning » Operational Control  Spring dm kernel/server combines the simplicity and power of Spring with sophistication of OSGi platform. Copyright 2009 Tikal Knowledge, Ltd. | 83 |
  • 84. Q&A Copyright 2009 Tikal Knowledge, Ltd. | 84 |
  • 85. Thank You yanai@tikalk.com Copyright 2009 Tikal Knowledge, Ltd. | 85 |