OSGi in action BlueDavy http://www.osgi.org.cn http://blog.bluedavy.cn 1.1 2007-10-20
Agenda <ul><li>Use OSGi with popular framework </li></ul><ul><li>Deploy exist system to OSGi </li></ul><ul><li>The feature...
Use OSGi with popular framework <ul><li>Use with Hibernate </li></ul><ul><li>Use with Spring </li></ul><ul><li>Use with We...
Use with Hibernate <ul><li>Download Hibernate-OSGi </li></ul><ul><ul><li>http ://www.osgi.org.cn/Hibernate-OSGi ; </li></u...
Use with Hibernate <ul><li>Change the connection info in hibernate.cfg.xml of cn.org.osgi.hibernate bundle; </li></ul><ul>...
Use with Hibernate <ul><li>Register Persistent class as extension point; </li></ul><ul><ul><li>create plugin.xml,then inpu...
Use with Hibernate <ul><li>Summary </li></ul><ul><ul><li>the difference between use with hibernate and use with OSGi & hib...
Use with Hibernate <ul><li>The implemention method of Hibernate-OSGi </li></ul><ul><ul><li>Refactor AbstractClassGenerator...
Use with Hibernate <ul><li>The weakpoint of Hibernate-OSGi </li></ul><ul><ul><li>Not support many hibernate po advanced co...
Use with Spring <ul><li>Download Spring-OSGi; </li></ul><ul><ul><li>http://www.springframework.org/osgi </li></ul></ul><ul...
Use with Spring <ul><li>Create the build and run environment </li></ul><ul><ul><li>install these bundles to eclipse or equ...
Publish Spring bean as OSGi service <ul><li>It’s very simple to do this </li></ul><ul><ul><li>just write this element </li...
Inject OSGi service to Spring bean <ul><li>It’s also very simple to do this, just write this element </li></ul><ul><ul><li...
Best practices <ul><li>Only publish those pojo needed export as OSGi service; </li></ul><ul><li>Use osgi:listener method t...
The weakpoint of Spring-OSGi <ul><li>Cann’t dynamic load spring bean bundle; </li></ul><ul><li>Spring-OSGi bundle must sta...
Use with Webwork <ul><li>Download Webwork-OSGi </li></ul><ul><ul><li>http://www.osgi.org.cn/Webwork-OSGi </li></ul></ul><u...
Use with Webwork <ul><li>New Plug-in project,write action class and action xml as always you do; </li></ul><ul><ul><li><ac...
Use with Webwork <ul><li>Summary </li></ul><ul><ul><li>the difference between use with webwork and use with webwork-OSGi <...
Use with Webwork <ul><li>The implemention of Webwork-OSGi </li></ul><ul><ul><li>Write own action xml file configuration pr...
Use with Webwork <ul><li>The weakpoint of Webwork-OSGi </li></ul><ul><ul><li>Maybe we need write a webwork-OSGi bundle so ...
Intergration key factors <ul><li>Classloader factor </li></ul><ul><ul><li>Can use OSGi Dynamic-ImportPackage and Export-Pa...
Agenda <ul><li>Use OSGi with popular framework </li></ul><ul><li>Deploy exist system to OSGi </li></ul><ul><li>The feature...
Deploy exist system to OSGi <ul><li>Use bnd tool to do this </li></ul><ul><ul><li>http://www.aqute.biz/Code/Bnd </li></ul>...
Agenda <ul><li>Use OSGi with popular framework </li></ul><ul><li>Deploy exist system to OSGi </li></ul><ul><li>The feature...
The feature of  OSGi application <ul><li>Strict and clear modularity </li></ul><ul><ul><li>Quickly know the module depende...
Agenda <ul><li>Use OSGi with popular framework </li></ul><ul><li>Deploy exist system to OSGi </li></ul><ul><li>The feature...
OSGi app design best practices <ul><li>Clear and strict define module; </li></ul><ul><ul><li>Module’s Export Function; </l...
Agenda <ul><li>Use OSGi with popular framework </li></ul><ul><li>Deploy exist system to OSGi </li></ul><ul><li>The feature...
OSGi app develop best practices <ul><li>Keep the dynamic feature </li></ul><ul><ul><li>Don’t suppose the dependence servic...
Agenda <ul><li>Use OSGi with popular framework </li></ul><ul><li>Deploy exist system to OSGi </li></ul><ul><li>The feature...
Resources <ul><li>OSGi R4 Specifications </li></ul><ul><li>《OSGi 实战 》Opendoc </li></ul><ul><li>《OSGi 进阶 》Opendoc </li></ul...
Click to edit company slogan . OSGi China User Group  http://www.osgi.org.cn Thank You !
Upcoming SlideShare
Loading in...5
×

OsGi.In.Action

3,563

Published on

Published in: Technology, Education
0 Comments
4 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
3,563
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
128
Comments
0
Likes
4
Embeds 0
No embeds

No notes for slide

OsGi.In.Action

  1. 1. OSGi in action BlueDavy http://www.osgi.org.cn http://blog.bluedavy.cn 1.1 2007-10-20
  2. 2. Agenda <ul><li>Use OSGi with popular framework </li></ul><ul><li>Deploy exist system to OSGi </li></ul><ul><li>The feature of OSGi application </li></ul><ul><li>OSGi application design best practices </li></ul><ul><li>OSGi application develop best practices </li></ul><ul><li>Resources </li></ul>
  3. 3. Use OSGi with popular framework <ul><li>Use with Hibernate </li></ul><ul><li>Use with Spring </li></ul><ul><li>Use with Webwork </li></ul><ul><li>Intergration key factors </li></ul>
  4. 4. Use with Hibernate <ul><li>Download Hibernate-OSGi </li></ul><ul><ul><li>http ://www.osgi.org.cn/Hibernate-OSGi ; </li></ul></ul><ul><ul><li>install cn.org.osgi.hibernate bundle or import Hibernate-OSGi source project to eclipse. </li></ul></ul><ul><li>Write demo bundle with Hibernate-OSGi to use Hibernate </li></ul>
  5. 5. Use with Hibernate <ul><li>Change the connection info in hibernate.cfg.xml of cn.org.osgi.hibernate bundle; </li></ul><ul><li>New Plug-in project,and write persistent class as you always do,then generate persistent class hbm file; </li></ul><ul><li>Implemention DAO class with cn.org.osgi.hibernate.service.CommonDaoService or other common Hibernate DAO API; </li></ul>
  6. 6. Use with Hibernate <ul><li>Register Persistent class as extension point; </li></ul><ul><ul><li>create plugin.xml,then input following content into the file,just like this: </li></ul></ul><ul><ul><ul><li><extension point=“cn.org.osgi.hibernate.PoExtension&quot;> </li></ul></ul></ul><ul><ul><ul><li><po class=&quot;cn.org.osgi.bulletin.po.Bulletin&quot;/> </li></ul></ul></ul><ul><ul><ul><li></extension> </li></ul></ul></ul><ul><li>Start the application,then finish the demo that use OSGi with Hibernate </li></ul>
  7. 7. Use with Hibernate <ul><li>Summary </li></ul><ul><ul><li>the difference between use with hibernate and use with OSGi & hibernate only two sides: </li></ul></ul><ul><ul><ul><li>don’t add resource mapping element to hibernate.cfg.xml any more; </li></ul></ul></ul><ul><ul><ul><li>Use extension point to register po. </li></ul></ul></ul>
  8. 8. Use with Hibernate <ul><li>The implemention method of Hibernate-OSGi </li></ul><ul><ul><li>Refactor AbstractClassGenerator.getClassLoader() method to sure use the AbstractClassGenerator class’s classloader to load the associate class </li></ul></ul><ul><ul><ul><li>Why do this? </li></ul></ul></ul><ul><ul><ul><ul><li>Just because AbstractClassGenerator use po class’s classloader to load cglib associate class,but now the bundle including po class don’t need import cglib jar. </li></ul></ul></ul></ul><ul><ul><li>Based on extension point to register/unregister po </li></ul></ul><ul><ul><ul><li>Why do this? </li></ul></ul></ul><ul><ul><ul><ul><li>Just because module seperation rule. </li></ul></ul></ul></ul><ul><ul><ul><ul><li>Use extension point so we can register po outside of HibernateModule. </li></ul></ul></ul></ul><ul><ul><ul><li>The session service use Configuration.addClass to register po from other bundle. </li></ul></ul></ul>
  9. 9. Use with Hibernate <ul><li>The weakpoint of Hibernate-OSGi </li></ul><ul><ul><li>Not support many hibernate po advanced configuration just like po class cache etc. currently; </li></ul></ul><ul><ul><li>Not support multi sessionfactory currently; </li></ul></ul><ul><ul><li>Need support register connection info from other bundles; </li></ul></ul><ul><ul><li>When new pos added or exist pos removed,SessionFactory need be restarted; </li></ul></ul><ul><li>Let’s improve Hibernate-OSGi together </li></ul><ul><ul><li>If u want to join this group,pls visit this webpage: </li></ul></ul><ul><ul><ul><li>http://www.osgi.org.cn/Hibernate-OSGi/join.html </li></ul></ul></ul>
  10. 10. Use with Spring <ul><li>Download Spring-OSGi; </li></ul><ul><ul><li>http://www.springframework.org/osgi </li></ul></ul><ul><li>Create the build and run environment </li></ul><ul><li>Publish Spring bean as OSGi service </li></ul><ul><li>Inject OSGi service to Spring bean </li></ul><ul><li>Best practices </li></ul><ul><li>The weakpoint of Spring-OSGi </li></ul>
  11. 11. Use with Spring <ul><li>Create the build and run environment </li></ul><ul><ul><li>install these bundles to eclipse or equinox </li></ul></ul><ul><ul><ul><li>aopalliance </li></ul></ul></ul><ul><ul><ul><li>aspectjrt </li></ul></ul></ul><ul><ul><ul><li>backport-util-concurrent </li></ul></ul></ul><ul><ul><ul><li>spring-aop </li></ul></ul></ul><ul><ul><ul><li>spring-aspects </li></ul></ul></ul><ul><ul><ul><li>spring-beans </li></ul></ul></ul><ul><ul><ul><li>spring-context </li></ul></ul></ul><ul><ul><ul><li>spring-core </li></ul></ul></ul><ul><ul><ul><li>spring-dao </li></ul></ul></ul><ul><ul><ul><li>spring-osgi-core </li></ul></ul></ul><ul><ul><ul><li>spring-osgi-extender </li></ul></ul></ul><ul><ul><ul><li>spring-osgi-io </li></ul></ul></ul>
  12. 12. Publish Spring bean as OSGi service <ul><li>It’s very simple to do this </li></ul><ul><ul><li>just write this element </li></ul></ul><ul><ul><ul><li><osgi:service id=“serviceID” ref=“spring bean name” interface=“OSGi service interface”/> </li></ul></ul></ul><ul><ul><ul><li>You can add osgi:service-properties to realize the properties configuration in OSGi component’s xml </li></ul></ul></ul>
  13. 13. Inject OSGi service to Spring bean <ul><li>It’s also very simple to do this, just write this element </li></ul><ul><ul><li><osgi:reference id=“Just like Spring bean name” interface=“OSGi service ” cardinality=“[0..n]|[0..1]|[1..n]” filter=“” timeout=“” depends-on=“” context-classloader=“”/> </li></ul></ul><ul><ul><li>We can use two method to inject this OSGi service to spring bean </li></ul></ul><ul><ul><ul><li><bean name=“bean name” class=“bean class”> </li></ul></ul></ul><ul><ul><ul><ul><li><property name=“OSGi service” ref=“OSGi reference id”/> </li></ul></ul></ul></ul><ul><ul><ul><ul><li></bean> </li></ul></ul></ul></ul><ul><ul><ul><li>add osgi:listener to osgi:reference </li></ul></ul></ul><ul><ul><ul><ul><li><osgi:listener ref=“the spring bean name need inject this OSGi service” bind-method=“inject OSGi service’s method name” unbind-method=“when OSGi service unavaible,then call this method”/> </li></ul></ul></ul></ul><ul><ul><ul><ul><li>The bind-method need change to this kind signature </li></ul></ul></ul></ul><ul><ul><ul><ul><ul><li>public void some-method-name(service interface,Dictionary) </li></ul></ul></ul></ul></ul><ul><ul><li>The difference between these two methods </li></ul></ul><ul><ul><ul><li>The first method cann’t get the OSGi service’s dynamic changination,but the second method can do this. </li></ul></ul></ul>
  14. 14. Best practices <ul><li>Only publish those pojo needed export as OSGi service; </li></ul><ul><li>Use osgi:listener method to inject OSGi service to spring bean; </li></ul><ul><li>Handle the OSGi service dynamic change; </li></ul><ul><li>If can publish the pojo in DS style,then use DS style; </li></ul>
  15. 15. The weakpoint of Spring-OSGi <ul><li>Cann’t dynamic load spring bean bundle; </li></ul><ul><li>Spring-OSGi bundle must start before other bundles; </li></ul><ul><li>Spring-OSGi depends excessive bundles. </li></ul>
  16. 16. Use with Webwork <ul><li>Download Webwork-OSGi </li></ul><ul><ul><li>http://www.osgi.org.cn/Webwork-OSGi </li></ul></ul><ul><ul><li>Install cn.org.osgi.webwork bundle or Import Webwork-OSGi project to eclipse </li></ul></ul><ul><ul><li>The bundle did realize webwork intergration with Spring-OSGi </li></ul></ul><ul><li>Write demo bundle with Webwork-OSGi to use webwork with OSGi </li></ul>
  17. 17. Use with Webwork <ul><li>New Plug-in project,write action class and action xml as always you do; </li></ul><ul><ul><li><action name=&quot;list&quot; class=&quot;LIST&quot;> </li></ul></ul><ul><ul><li>Class property upside map to its OSGi service’s property </li></ul></ul><ul><ul><ul><li><property name=&quot;command&quot; value=&quot;ADMINLOGIN&quot;/> </li></ul></ul></ul><ul><li>Publish action class as OSGi service in ds style or spring-OSGi style; </li></ul><ul><li>Export the package where your action classes and action resource files in; </li></ul><ul><li>Register action xml file to extension point; </li></ul><ul><ul><li><extension </li></ul></ul><ul><ul><li>point=“cn.org.osgi.webwork.actionextension&quot;> </li></ul></ul><ul><ul><li><action configFile=&quot;cn/org/osgi/bulletin/list/action/xwork.xml&quot;/> </li></ul></ul><ul><ul><li></extension> </li></ul></ul><ul><li>Start the application,then u can visit the action </li></ul>
  18. 18. Use with Webwork <ul><li>Summary </li></ul><ul><ul><li>the difference between use with webwork and use with webwork-OSGi </li></ul></ul><ul><ul><ul><li>the action class property is not the action class true name,but is the osgi service command property the action class published; </li></ul></ul></ul><ul><ul><ul><li>the action xml file is not write to a singlepoint xwork.xml,but register to webwork-OSGi based on extension point; </li></ul></ul></ul>
  19. 19. Use with Webwork <ul><li>The implemention of Webwork-OSGi </li></ul><ul><ul><li>Write own action xml file configuration provider class </li></ul></ul><ul><ul><ul><li>so webwork-OSGi can dynamic load and unload action xml file outside webwork-OSGi bundle; </li></ul></ul></ul><ul><ul><li>Write own ObjectFactory to load action and other class </li></ul></ul><ul><ul><ul><li>so webwork-OSGi can load action class instance from OSGi service registration and then realize intergration with spring-OSGi; </li></ul></ul></ul><ul><ul><ul><li>Other class loading as webwork always do </li></ul></ul></ul><ul><ul><li>Change webwork action xml file configuration provider and ObjectFactory </li></ul></ul>
  20. 20. Use with Webwork <ul><li>The weakpoint of Webwork-OSGi </li></ul><ul><ul><li>Maybe we need write a webwork-OSGi bundle so when webwork update,we can update quickly; </li></ul></ul><ul><ul><li>Not support servlet filter configuration,but this is httpservice problem </li></ul></ul>
  21. 21. Intergration key factors <ul><li>Classloader factor </li></ul><ul><ul><li>Can use OSGi Dynamic-ImportPackage and Export-Package to solve this factor. </li></ul></ul><ul><li>Resource loader factor </li></ul><ul><ul><li>Can use extension point to realize load resource dynamically and so resource can be placed in module style. </li></ul></ul><ul><li>The most important factor:”modularity” & “Plug and Play” </li></ul>
  22. 22. Agenda <ul><li>Use OSGi with popular framework </li></ul><ul><li>Deploy exist system to OSGi </li></ul><ul><li>The feature of OSGi application </li></ul><ul><li>OSGi application design best practices </li></ul><ul><li>OSGi application develop best practices </li></ul><ul><li>Resources </li></ul>
  23. 23. Deploy exist system to OSGi <ul><li>Use bnd tool to do this </li></ul><ul><ul><li>http://www.aqute.biz/Code/Bnd </li></ul></ul><ul><ul><li>http://www.aqute.biz/Code/BndCn </li></ul></ul><ul><li>Step </li></ul><ul><ul><li>Separate project packages in module style logically; </li></ul></ul><ul><ul><li>Define module need import package and export package; </li></ul></ul><ul><ul><li>Write bnd file for per module; </li></ul></ul><ul><ul><li>Run bnd tool then get the module jar file; </li></ul></ul><ul><ul><li>Deploy the module jar file to OSGi framework </li></ul></ul>
  24. 24. Agenda <ul><li>Use OSGi with popular framework </li></ul><ul><li>Deploy exist system to OSGi </li></ul><ul><li>The feature of OSGi application </li></ul><ul><li>OSGi application design best practices </li></ul><ul><li>OSGi application develop best practices </li></ul><ul><li>Resources </li></ul>
  25. 25. The feature of OSGi application <ul><li>Strict and clear modularity </li></ul><ul><ul><li>Quickly know the module dependency; </li></ul></ul><ul><ul><li>Quickly know the module exported function; </li></ul></ul><ul><ul><li>Quickly know how the module can be extensioned; </li></ul></ul><ul><li>Reusable </li></ul><ul><ul><li>Build company bundle respository </li></ul></ul><ul><li>Dynamic </li></ul><ul><ul><li>“ Plug and Play” </li></ul></ul><ul><li>Extensionable </li></ul>
  26. 26. Agenda <ul><li>Use OSGi with popular framework </li></ul><ul><li>Deploy exist system to OSGi </li></ul><ul><li>The feature of OSGi application </li></ul><ul><li>OSGi application design best practices </li></ul><ul><li>OSGi application develop best practices </li></ul><ul><li>Resources </li></ul>
  27. 27. OSGi app design best practices <ul><li>Clear and strict define module; </li></ul><ul><ul><li>Module’s Export Function; </li></ul></ul><ul><ul><li>Module’s Dependency; </li></ul></ul><ul><ul><li>Module’s Extension Point; </li></ul></ul><ul><li>Interface-oriented and SOCM; </li></ul><ul><ul><li>Bundles compose of components,components communicate each other with OSGi service; </li></ul></ul><ul><ul><li>All service publish in interface type; </li></ul></ul><ul><li>Split Interface & Implemention into separate bundles; </li></ul>
  28. 28. Agenda <ul><li>Use OSGi with popular framework </li></ul><ul><li>Deploy exist system to OSGi </li></ul><ul><li>The feature of OSGi application </li></ul><ul><li>OSGi application design best practices </li></ul><ul><li>OSGi application develop best practices </li></ul><ul><li>Resources </li></ul>
  29. 29. OSGi app develop best practices <ul><li>Keep the dynamic feature </li></ul><ul><ul><li>Don’t suppose the dependence service usable; </li></ul></ul><ul><ul><li>Handle the dynamic change such as extension added/event published/service unavaible; </li></ul></ul><ul><li>If the service is used only inside bundle,then don’t publish it as OSGi service; </li></ul><ul><li>Don’t make static dependency to other bundles; </li></ul>
  30. 30. Agenda <ul><li>Use OSGi with popular framework </li></ul><ul><li>Deploy exist system to OSGi </li></ul><ul><li>The feature of OSGi application </li></ul><ul><li>OSGi application design best practices </li></ul><ul><li>OSGi application develop best practices </li></ul><ul><li>Resources </li></ul>
  31. 31. Resources <ul><li>OSGi R4 Specifications </li></ul><ul><li>《OSGi 实战 》Opendoc </li></ul><ul><li>《OSGi 进阶 》Opendoc </li></ul><ul><li>http://www.osgi.org </li></ul><ul><li>http://www.osgi.org.cn </li></ul><ul><li>http://www.aqute.biz </li></ul><ul><li>http://blog.bluedavy.cn </li></ul>
  32. 32. Click to edit company slogan . OSGi China User Group http://www.osgi.org.cn Thank You !
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×