Upload
guest9a87167
View
3.523
Download
0
Tags:
Embed Size (px)
Citation preview
OSGi in action
BlueDavyhttp://www.osgi.org.cnhttp://blog.bluedavy.cn
1.12007-10-20
23/4/1123/4/11 22 OSGi China User Group: http://www.osgi.org.cn 致力于致力于 OSGiOSGi 的推广和发的推广和发展展
Agenda Use OSGi with popular framework Deploy exist system to OSGi The feature of OSGi application OSGi application design best practices OSGi application develop best practices Resources
23/4/1123/4/11 33 OSGi China User Group: http://www.osgi.org.cn 致力于致力于 OSGiOSGi 的推广和发的推广和发展展
Use OSGi with popular framework Use with Hibernate Use with Spring Use with Webwork Intergration key factors
23/4/1123/4/11 44 OSGi China User Group: http://www.osgi.org.cn 致力于致力于 OSGiOSGi 的推广和发的推广和发展展
Use with HibernateDownload Hibernate-OSGi
http://www.osgi.org.cn/Hibernate-OSGi; install cn.org.osgi.hibernate bundle or import Hibernat
e-OSGi source project to eclipse.
Write demo bundle with Hibernate-OSGi to use Hibernate
23/4/1123/4/11 55 OSGi China User Group: http://www.osgi.org.cn 致力于致力于 OSGiOSGi 的推广和发的推广和发展展
Use with HibernateChange the connection info in hibernate.cfg.xml
of cn.org.osgi.hibernate bundle;New Plug-in project,and write persistent class as
you always do,then generate persistent class hbm file;
Implemention DAO class with cn.org.osgi.hibernate.service.CommonDaoService or other common Hibernate DAO API;
23/4/1123/4/11 66 OSGi China User Group: http://www.osgi.org.cn 致力于致力于 OSGiOSGi 的推广和发的推广和发展展
Use with HibernateRegister Persistent class as extension point;
create plugin.xml,then input following content into the file,just like this:
– <extension point=“cn.org.osgi.hibernate.PoExtension">– <po class="cn.org.osgi.bulletin.po.Bulletin"/>– </extension>
Start the application,then finish the demo that use OSGi with Hibernate
23/4/1123/4/11 77 OSGi China User Group: http://www.osgi.org.cn 致力于致力于 OSGiOSGi 的推广和发的推广和发展展
Use with Hibernate Summary
the difference between use with hibernate and use with OSGi & hibernate only two sides:
– don’t add resource mapping element to hibernate.cfg.xml any more;
– Use extension point to register po.
23/4/1123/4/11 88 OSGi China User Group: http://www.osgi.org.cn 致力于致力于 OSGiOSGi 的推广和发的推广和发展展
Use with Hibernate The implemention method of Hibernate-OSGi
Refactor AbstractClassGenerator.getClassLoader() method to sure use the AbstractClassGenerator class’s classloader to load the associate class
– Why do this?– Just because AbstractClassGenerator use po class’s classload
er to load cglib associate class,but now the bundle including po class don’t need import cglib jar.
Based on extension point to register/unregister po– Why do this?
– Just because module seperation rule.– Use extension point so we can register po outside of Hibernate
Module.
– The session service use Configuration.addClass to register po from other bundle.
23/4/1123/4/11 99 OSGi China User Group: http://www.osgi.org.cn 致力于致力于 OSGiOSGi 的推广和发的推广和发展展
Use with HibernateThe weakpoint of Hibernate-OSGi
Not support many hibernate po advanced configuration just like po class cache etc. currently;
Not support multi sessionfactory currently; Need support register connection info from other bund
les; When new pos added or exist pos removed,SessionF
actory need be restarted;
Let’s improve Hibernate-OSGi together If u want to join this group,pls visit this webpage:
– http://www.osgi.org.cn/Hibernate-OSGi/join.html
23/4/1123/4/11 1010 OSGi China User Group: http://www.osgi.org.cn 致力于致力于 OSGiOSGi 的推广和发的推广和发展展
Use with SpringDownload Spring-OSGi;
http://www.springframework.org/osgi
Create the build and run environmentPublish Spring bean as OSGi serviceInject OSGi service to Spring beanBest practicesThe weakpoint of Spring-OSGi
23/4/1123/4/11 1111 OSGi China User Group: http://www.osgi.org.cn 致力于致力于 OSGiOSGi 的推广和发的推广和发展展
Use with Spring Create the build and run environment
install these bundles to eclipse or equinox– aopalliance
– aspectjrt
– backport-util-concurrent
– spring-aop
– spring-aspects
– spring-beans
– spring-context
– spring-core
– spring-dao
– spring-osgi-core
– spring-osgi-extender
– spring-osgi-io
23/4/1123/4/11 1212 OSGi China User Group: http://www.osgi.org.cn 致力于致力于 OSGiOSGi 的推广和发的推广和发展展
Publish Spring bean as OSGi serviceIt’s very simple to do this
just write this element– <osgi:service id=“serviceID” ref=“spring bean name” interfac
e=“OSGi service interface”/>– You can add osgi:service-properties to realize the properties
configuration in OSGi component’s xml
23/4/1123/4/11 1313 OSGi China User Group: http://www.osgi.org.cn 致力于致力于 OSGiOSGi 的推广和发的推广和发展展
Inject OSGi service to Spring bean It’s also very simple to do this, just write this element
<osgi:reference id=“Just like Spring bean name” interface=“OSGi service ” cardinality=“[0..n]|[0..1]|[1..n]” filter=“” timeout=“” depends-on=“” context-classloader=“”/>
We can use two method to inject this OSGi service to spring bean
– <bean name=“bean name” class=“bean class”><property name=“OSGi service” ref=“OSGi reference id”/> </bean>
– add osgi:listener to osgi:reference– <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”/>
– The bind-method need change to this kind signature public void some-method-name(service interface,Dictionary)
The difference between these two methods– The first method cann’t get the OSGi service’s dynamic changinatio
n,but the second method can do this.
23/4/1123/4/11 1414 OSGi China User Group: http://www.osgi.org.cn 致力于致力于 OSGiOSGi 的推广和发的推广和发展展
Best practicesOnly publish those pojo needed export as OSGi
service;Use osgi:listener method to inject OSGi service t
o spring bean;Handle the OSGi service dynamic change;If can publish the pojo in DS style,then use DS st
yle;
23/4/1123/4/11 1515 OSGi China User Group: http://www.osgi.org.cn 致力于致力于 OSGiOSGi 的推广和发的推广和发展展
The weakpoint of Spring-OSGiCann’t dynamic load spring bean bundle;Spring-OSGi bundle must start before other bun
dles;Spring-OSGi depends excessive bundles.
23/4/1123/4/11 1616 OSGi China User Group: http://www.osgi.org.cn 致力于致力于 OSGiOSGi 的推广和发的推广和发展展
Use with WebworkDownload Webwork-OSGi
http://www.osgi.org.cn/Webwork-OSGi Install cn.org.osgi.webwork bundle or Import Webwor
k-OSGi project to eclipse The bundle did realize webwork intergration with Spri
ng-OSGi
Write demo bundle with Webwork-OSGi to use webwork with OSGi
23/4/1123/4/11 1717 OSGi China User Group: http://www.osgi.org.cn 致力于致力于 OSGiOSGi 的推广和发的推广和发展展
Use with Webwork New Plug-in project,write action class and action xml as always you
do; <action name="list" class="LIST"> Class property upside map to its OSGi service’s property
– <property name="command" value="ADMINLOGIN"/>
Publish action class as OSGi service in ds style or spring-OSGi style;
Export the package where your action classes and action resource files in;
Register action xml file to extension point; <extension point=“cn.org.osgi.webwork.actionextension"> <action configFile="cn/org/osgi/bulletin/list/action/xwork.xml"/> </extension>
Start the application,then u can visit the action
23/4/1123/4/11 1818 OSGi China User Group: http://www.osgi.org.cn 致力于致力于 OSGiOSGi 的推广和发的推广和发展展
Use with WebworkSummary
the difference between use with webwork and use with webwork-OSGi
– the action class property is not the action class true name,but is the osgi service command property the action class published;
– the action xml file is not write to a singlepoint xwork.xml,but register to webwork-OSGi based on extension point;
23/4/1123/4/11 1919 OSGi China User Group: http://www.osgi.org.cn 致力于致力于 OSGiOSGi 的推广和发的推广和发展展
Use with WebworkThe implemention of Webwork-OSGi
Write own action xml file configuration provider class– so webwork-OSGi can dynamic load and unload action xml fil
e outside webwork-OSGi bundle;
Write own ObjectFactory to load action and other class
– so webwork-OSGi can load action class instance from OSGi service registration and then realize intergration with spring-OSGi;
– Other class loading as webwork always do
Change webwork action xml file configuration provider and ObjectFactory
23/4/1123/4/11 2020 OSGi China User Group: http://www.osgi.org.cn 致力于致力于 OSGiOSGi 的推广和发的推广和发展展
Use with WebworkThe weakpoint of Webwork-OSGi
Maybe we need write a webwork-OSGi bundle so when webwork update,we can update quickly;
Not support servlet filter configuration,but this is httpservice problem
23/4/1123/4/11 2121 OSGi China User Group: http://www.osgi.org.cn 致力于致力于 OSGiOSGi 的推广和发的推广和发展展
Intergration key factorsClassloader factor
Can use OSGi Dynamic-ImportPackage and Export-Package to solve this factor.
Resource loader factor Can use extension point to realize load resource dyna
mically and so resource can be placed in module style.
The most important factor:”modularity” & “Plug and Play”
23/4/1123/4/11 2222 OSGi China User Group: http://www.osgi.org.cn 致力于致力于 OSGiOSGi 的推广和发的推广和发展展
Agenda Use OSGi with popular framework Deploy exist system to OSGi The feature of OSGi application OSGi application design best practices OSGi application develop best practices Resources
23/4/1123/4/11 2323 OSGi China User Group: http://www.osgi.org.cn 致力于致力于 OSGiOSGi 的推广和发的推广和发展展
Deploy exist system to OSGiUse bnd tool to do this
http://www.aqute.biz/Code/Bnd http://www.aqute.biz/Code/BndCn
Step Separate project packages in module style logically; Define module need import package and export pack
age; Write bnd file for per module; Run bnd tool then get the module jar file; Deploy the module jar file to OSGi framework
23/4/1123/4/11 2424 OSGi China User Group: http://www.osgi.org.cn 致力于致力于 OSGiOSGi 的推广和发的推广和发展展
Agenda Use OSGi with popular framework Deploy exist system to OSGi The feature of OSGi application OSGi application design best practices OSGi application develop best practices Resources
23/4/1123/4/11 2525 OSGi China User Group: http://www.osgi.org.cn 致力于致力于 OSGiOSGi 的推广和发的推广和发展展
The feature of OSGi applicationStrict and clear modularity
Quickly know the module dependency; Quickly know the module exported function; Quickly know how the module can be extensioned;
Reusable Build company bundle respository
Dynamic “Plug and Play”
Extensionable
23/4/1123/4/11 2626 OSGi China User Group: http://www.osgi.org.cn 致力于致力于 OSGiOSGi 的推广和发的推广和发展展
Agenda Use OSGi with popular framework Deploy exist system to OSGi The feature of OSGi application OSGi application design best practices OSGi application develop best practices Resources
23/4/1123/4/11 2727 OSGi China User Group: http://www.osgi.org.cn 致力于致力于 OSGiOSGi 的推广和发的推广和发展展
OSGi app design best practicesClear and strict define module;
Module’s Export Function; Module’s Dependency; Module’s Extension Point;
Interface-oriented and SOCM; Bundles compose of components,components comm
unicate each other with OSGi service; All service publish in interface type;
Split Interface & Implemention into separate bundles;
23/4/1123/4/11 2828 OSGi China User Group: http://www.osgi.org.cn 致力于致力于 OSGiOSGi 的推广和发的推广和发展展
Agenda Use OSGi with popular framework Deploy exist system to OSGi The feature of OSGi application OSGi application design best practices OSGi application develop best practices Resources
23/4/1123/4/11 2929 OSGi China User Group: http://www.osgi.org.cn 致力于致力于 OSGiOSGi 的推广和发的推广和发展展
OSGi app develop best practicesKeep the dynamic feature
Don’t suppose the dependence service usable; Handle the dynamic change such as extension added
/event published/service unavaible;
If the service is used only inside bundle,then don’t publish it as OSGi service;
Don’t make static dependency to other bundles;
23/4/1123/4/11 3030 OSGi China User Group: http://www.osgi.org.cn 致力于致力于 OSGiOSGi 的推广和发的推广和发展展
Agenda Use OSGi with popular framework Deploy exist system to OSGi The feature of OSGi application OSGi application design best practices OSGi application develop best practices Resources
23/4/1123/4/11 3131 OSGi China User Group: http://www.osgi.org.cn 致力于致力于 OSGiOSGi 的推广和发的推广和发展展
ResourcesOSGi R4 Specifications 《 OSGi 实战》 Opendoc 《 OSGi 进阶》 Opendoc http://www.osgi.org http://www.osgi.org.cn http://www.aqute.biz http://blog.bluedavy.cn
Click to edit company slogan .
OSGi China User Group http://www.osgi.org.cn