introduce osgi bluedavy 1.0 2007-10-28
TRANSCRIPT
![Page 1: Introduce OSGi BlueDavy 1.0 2007-10-28](https://reader036.vdocuments.pub/reader036/viewer/2022062313/56649c785503460f9492d121/html5/thumbnails/1.jpg)
Introduce OSGi
BlueDavyhttp://www.osgi.org.cnhttp://blog.bluedavy.cn
1.02007-10-28
![Page 2: Introduce OSGi BlueDavy 1.0 2007-10-28](https://reader036.vdocuments.pub/reader036/viewer/2022062313/56649c785503460f9492d121/html5/thumbnails/2.jpg)
23/4/1823/4/18 22 OSGi China User Group: http://www.osgi.org.cn 致力于致力于 OSGiOSGi 的推广和发的推广和发展展
Agenda Play OSGi Who use OSGi What is OSGi OSGi R4 Implemention How to develop OSGi app OSGi Resources
![Page 3: Introduce OSGi BlueDavy 1.0 2007-10-28](https://reader036.vdocuments.pub/reader036/viewer/2022062313/56649c785503460f9492d121/html5/thumbnails/3.jpg)
23/4/1823/4/18 33 OSGi China User Group: http://www.osgi.org.cn 致力于致力于 OSGiOSGi 的推广和发的推广和发展展
Play OSGi Let’s see a short demo
First we see an bulletin application,but only have bulletin list function;
We want to add new bulletin,so we find newbulletin module from module respository,then install & start it,now we can add new bulletin;
We see the feature of OSGi application modularity dynamic,”Plug and Play” extensionable these features are supported by OSGi,the meaning is that you d
on’t need realize those features yourself,what you need do is just use it
![Page 4: Introduce OSGi BlueDavy 1.0 2007-10-28](https://reader036.vdocuments.pub/reader036/viewer/2022062313/56649c785503460f9492d121/html5/thumbnails/4.jpg)
23/4/1823/4/18 44 OSGi China User Group: http://www.osgi.org.cn 致力于致力于 OSGiOSGi 的推广和发的推广和发展展
Agenda Play OSGi Who use OSGi What is OSGi OSGi R4 Implemention How to develop OSGi app OSGi Resources
![Page 5: Introduce OSGi BlueDavy 1.0 2007-10-28](https://reader036.vdocuments.pub/reader036/viewer/2022062313/56649c785503460f9492d121/html5/thumbnails/5.jpg)
23/4/1823/4/18 55 OSGi China User Group: http://www.osgi.org.cn 致力于致力于 OSGiOSGi 的推广和发的推广和发展展
Who use OSGi IBM
Websphere RSA
BEA microServices,All BEA product will be based on microServices
Eclipse Apache
Struts 2 Spring
Spring-OSGi Simens,Nokia,BMW,Cisco etc. SAP,Oracle,IONA etc. are interested in OSGi,and be OS
Gi EEG member
![Page 6: Introduce OSGi BlueDavy 1.0 2007-10-28](https://reader036.vdocuments.pub/reader036/viewer/2022062313/56649c785503460f9492d121/html5/thumbnails/6.jpg)
23/4/1823/4/18 66 OSGi China User Group: http://www.osgi.org.cn 致力于致力于 OSGiOSGi 的推广和发的推广和发展展
Agenda Play OSGi Who use OSGi What is OSGi OSGi R4 Implemention How to develop OSGi app OSGi Resources
![Page 7: Introduce OSGi BlueDavy 1.0 2007-10-28](https://reader036.vdocuments.pub/reader036/viewer/2022062313/56649c785503460f9492d121/html5/thumbnails/7.jpg)
23/4/1823/4/18 77 OSGi China User Group: http://www.osgi.org.cn 致力于致力于 OSGiOSGi 的推广和发的推广和发展展
What is OSGiDynamic Module System For JavaJSR232 JSR291Universal MiddlewareBest practice guide and support for building mod
ularity/dynamic/extensionable system Modularity with rule; Dynamic support for module,OSGi service,configurati
on; Extension support with OSGi service.
![Page 8: Introduce OSGi BlueDavy 1.0 2007-10-28](https://reader036.vdocuments.pub/reader036/viewer/2022062313/56649c785503460f9492d121/html5/thumbnails/8.jpg)
23/4/1823/4/18 88 OSGi China User Group: http://www.osgi.org.cn 致力于致力于 OSGiOSGi 的推广和发的推广和发展展
OSGi Basic Concepts Modularity
Define module in OSGi; Publish functions for other
modules; Use functions provided
by other modules.
BundleBundle
JAVA
Operating System
Hardware
OSGi Framework
Serviceregistry
packagespackages
![Page 9: Introduce OSGi BlueDavy 1.0 2007-10-28](https://reader036.vdocuments.pub/reader036/viewer/2022062313/56649c785503460f9492d121/html5/thumbnails/9.jpg)
23/4/1823/4/18 99 OSGi China User Group: http://www.osgi.org.cn 致力于致力于 OSGiOSGi 的推广和发的推广和发展展
Define module in OSGiIn OSGi module compose of one or more bundle
s;Bundle is a normal jar file,the difference is its Ma
nifest.mf file,OSGi add some specical header info property to declarative bundle,such as: bundle-version,export-package,import-package
![Page 10: Introduce OSGi BlueDavy 1.0 2007-10-28](https://reader036.vdocuments.pub/reader036/viewer/2022062313/56649c785503460f9492d121/html5/thumbnails/10.jpg)
23/4/1823/4/18 1010 OSGi China User Group: http://www.osgi.org.cn 致力于致力于 OSGiOSGi 的推广和发的推广和发展展
Publish functions for other bundlesadd export-package header info to provide pack
age for other bundles to use,such as cn.org.osgi.ppt.service;
add Fragment-Host header info to provide all resources for host bundle to use;
publish OSGi service for other bundles; Use BundleContext.registerService to register normal
java interface as OSGi service; Write xml with rule to declarative normal java class as
OSGi component,and provide service interface for other bundles,such as:
![Page 11: Introduce OSGi BlueDavy 1.0 2007-10-28](https://reader036.vdocuments.pub/reader036/viewer/2022062313/56649c785503460f9492d121/html5/thumbnails/11.jpg)
23/4/1823/4/18 1111 OSGi China User Group: http://www.osgi.org.cn 致力于致力于 OSGiOSGi 的推广和发的推广和发展展
Use functions provided by other modules
add import-package header info to import packages provided by other bundles,then you can use the java class in those packages;
add require-bundle header info to use all export packages and resources provider by bundle;
use OSGi service provided by other bundles; Use BundleContext.getService to get OSGi service pr
ovided by other bundles; Write xml with rule to declarative normal java class as
OSGi component,and inject OSGi service provided by other bundles,such as:
![Page 12: Introduce OSGi BlueDavy 1.0 2007-10-28](https://reader036.vdocuments.pub/reader036/viewer/2022062313/56649c785503460f9492d121/html5/thumbnails/12.jpg)
23/4/1823/4/18 1212 OSGi China User Group: http://www.osgi.org.cn 致力于致力于 OSGiOSGi 的推广和发的推广和发展展
OSGi Basic Concepts Dynamic
Bundle lifecycle OSGi component lifecycle Handle the dynamic
– when bundle lifecycle changed;– when OSGi component lifecycle changed;– when configuration changed;– when framework changed;– when custom event published;
![Page 13: Introduce OSGi BlueDavy 1.0 2007-10-28](https://reader036.vdocuments.pub/reader036/viewer/2022062313/56649c785503460f9492d121/html5/thumbnails/13.jpg)
23/4/1823/4/18 1313 OSGi China User Group: http://www.osgi.org.cn 致力于致力于 OSGiOSGi 的推广和发的推广和发展展
Bundle lifecycleOSGi provide an API for manageing bundles life
cycle (Install/Resolve/Start/Stop/Refresh/Update/Uninstall),so OSGi framework RI will control bundle lifecycle self;
INSTALLED
RESOLVED
UNINSTALLED
ACTIVE
STOPPING
STARTING
start
stop
![Page 14: Introduce OSGi BlueDavy 1.0 2007-10-28](https://reader036.vdocuments.pub/reader036/viewer/2022062313/56649c785503460f9492d121/html5/thumbnails/14.jpg)
23/4/1823/4/18 1414 OSGi China User Group: http://www.osgi.org.cn 致力于致力于 OSGiOSGi 的推广和发的推广和发展展
OSGi component lifecycle Component that provide no service;
when all need OSGi services(exclued optional service) are usable,the component will be actived;
Component that provide services; when all need OSGi services(exclued optional service) are usable; other component call this OSGi service implemention.
![Page 15: Introduce OSGi BlueDavy 1.0 2007-10-28](https://reader036.vdocuments.pub/reader036/viewer/2022062313/56649c785503460f9492d121/html5/thumbnails/15.jpg)
23/4/1823/4/18 1515 OSGi China User Group: http://www.osgi.org.cn 致力于致力于 OSGiOSGi 的推广和发的推广和发展展
Handle the dynamic when bundle lifecycle changed;
OSGi component lifecycle will change automatically; OSGi will handle bundle lifecycle dynamic self;
when OSGi component lifecycle changed; OSGi service tracker can be used to monitor OSGi service; Declarative Services use bind-method,unbind-method to notify the dyna
mic of OSGi service. when configuration changed;
Configuration Admin Service automatically notify the configuration change.
when framework changed; FrameworkEventListener can be implemented to monitor framework.
when custom event published; EventAdmin Service can to used to publish & handle custom event.
![Page 16: Introduce OSGi BlueDavy 1.0 2007-10-28](https://reader036.vdocuments.pub/reader036/viewer/2022062313/56649c785503460f9492d121/html5/thumbnails/16.jpg)
23/4/1823/4/18 1616 OSGi China User Group: http://www.osgi.org.cn 致力于致力于 OSGiOSGi 的推广和发的推广和发展展
OSGi Basic Concepts Extensionable
Service filter supported by OSGi can be used to extension function;
Multi service reference supported by OSGi can be used to extension function;
Extension point provided by Equinox can be used to extension function.
![Page 17: Introduce OSGi BlueDavy 1.0 2007-10-28](https://reader036.vdocuments.pub/reader036/viewer/2022062313/56649c785503460f9492d121/html5/thumbnails/17.jpg)
23/4/1823/4/18 1717 OSGi China User Group: http://www.osgi.org.cn 致力于致力于 OSGiOSGi 的推广和发的推广和发展展
Agenda Play OSGi Who use OSGi What is OSGi OSGi R4 Implemention How to develop OSGi app OSGi Resources
![Page 18: Introduce OSGi BlueDavy 1.0 2007-10-28](https://reader036.vdocuments.pub/reader036/viewer/2022062313/56649c785503460f9492d121/html5/thumbnails/18.jpg)
23/4/1823/4/18 1818 OSGi China User Group: http://www.osgi.org.cn 致力于致力于 OSGiOSGi 的推广和发的推广和发展展
OSGi R4 Implemention Equinox
Realized by Eclipse team; As the OSGi R4 RI; http://www.eclipse.org/equinox. Used by Eclipse RCP & Eclipse other products.
Felix Realized by Apache Team; http://felix.apache.org.
![Page 19: Introduce OSGi BlueDavy 1.0 2007-10-28](https://reader036.vdocuments.pub/reader036/viewer/2022062313/56649c785503460f9492d121/html5/thumbnails/19.jpg)
23/4/1823/4/18 1919 OSGi China User Group: http://www.osgi.org.cn 致力于致力于 OSGiOSGi 的推广和发的推广和发展展
Agenda Play OSGi Who use OSGi What is OSGi OSGi R4 Implemention How to develop OSGi app OSGi Resources
![Page 20: Introduce OSGi BlueDavy 1.0 2007-10-28](https://reader036.vdocuments.pub/reader036/viewer/2022062313/56649c785503460f9492d121/html5/thumbnails/20.jpg)
23/4/1823/4/18 2020 OSGi China User Group: http://www.osgi.org.cn 致力于致力于 OSGiOSGi 的推广和发的推广和发展展
How to develop OSGi app Get started Write your first bundle Deploy & Manage first bundle Publish and use OSGi Service FAQ
![Page 21: Introduce OSGi BlueDavy 1.0 2007-10-28](https://reader036.vdocuments.pub/reader036/viewer/2022062313/56649c785503460f9492d121/html5/thumbnails/21.jpg)
23/4/1823/4/18 2121 OSGi China User Group: http://www.osgi.org.cn 致力于致力于 OSGiOSGi 的推广和发的推广和发展展
Get started Download Eclipse from www.eclipse.org Download Equinox bundles from
www.eclipse.org/equinox most bundles exist in eclipse
![Page 22: Introduce OSGi BlueDavy 1.0 2007-10-28](https://reader036.vdocuments.pub/reader036/viewer/2022062313/56649c785503460f9492d121/html5/thumbnails/22.jpg)
23/4/1823/4/18 2222 OSGi China User Group: http://www.osgi.org.cn 致力于致力于 OSGiOSGi 的推广和发的推广和发展展
Write your first bundle New plugin-project,select this plug-in is targeted
to run with an OSGi framework in project wizard page;
![Page 23: Introduce OSGi BlueDavy 1.0 2007-10-28](https://reader036.vdocuments.pub/reader036/viewer/2022062313/56649c785503460f9492d121/html5/thumbnails/23.jpg)
23/4/1823/4/18 2323 OSGi China User Group: http://www.osgi.org.cn 致力于致力于 OSGiOSGi 的推广和发的推广和发展展
Write your first bundle Then enter the plug-in content page Write associate info,then click finish to create th
e project.
![Page 24: Introduce OSGi BlueDavy 1.0 2007-10-28](https://reader036.vdocuments.pub/reader036/viewer/2022062313/56649c785503460f9492d121/html5/thumbnails/24.jpg)
23/4/1823/4/18 2424 OSGi China User Group: http://www.osgi.org.cn 致力于致力于 OSGiOSGi 的推广和发的推广和发展展
Write your first bundle Write activator class
Say ‘hello’ when bundle started; Say ‘byebye’ when bundle stopped;
![Page 25: Introduce OSGi BlueDavy 1.0 2007-10-28](https://reader036.vdocuments.pub/reader036/viewer/2022062313/56649c785503460f9492d121/html5/thumbnails/25.jpg)
23/4/1823/4/18 2525 OSGi China User Group: http://www.osgi.org.cn 致力于致力于 OSGiOSGi 的推广和发的推广和发展展
Deploy & Manage first bundle Deploy in eclipse Deploy outside alone Manage bundle in console
![Page 26: Introduce OSGi BlueDavy 1.0 2007-10-28](https://reader036.vdocuments.pub/reader036/viewer/2022062313/56649c785503460f9492d121/html5/thumbnails/26.jpg)
23/4/1823/4/18 2626 OSGi China User Group: http://www.osgi.org.cn 致力于致力于 OSGiOSGi 的推广和发的推广和发展展
Deploy in eclipseOpen run dialog,new in Equinox OSGi Framewo
rk, select Workspace Plug-ins and org.eclipse.osgi in Target platform;
![Page 27: Introduce OSGi BlueDavy 1.0 2007-10-28](https://reader036.vdocuments.pub/reader036/viewer/2022062313/56649c785503460f9492d121/html5/thumbnails/27.jpg)
23/4/1823/4/18 2727 OSGi China User Group: http://www.osgi.org.cn 致力于致力于 OSGiOSGi 的推广和发的推广和发展展
Deploy in eclipseClick Run button,then you can see this in consol
e;
![Page 28: Introduce OSGi BlueDavy 1.0 2007-10-28](https://reader036.vdocuments.pub/reader036/viewer/2022062313/56649c785503460f9492d121/html5/thumbnails/28.jpg)
23/4/1823/4/18 2828 OSGi China User Group: http://www.osgi.org.cn 致力于致力于 OSGiOSGi 的推广和发的推广和发展展
Deploy outside alone Create equinox framework app outside alone first;
create Equinox directory,then create configuration,plugins directory in Equinox directory;
put org.eclipse.osgi.jar & org.eclipse.osgi.services.jar to plugins directory;
create config.ini in configuration directory,content in config.ini like this:
osgi.noShutdown=trueosgi.bundles=org.eclipse.osgi.services_3.1.100.v20060601.jar@startosgi.bundles.defaultStartLevel=4osgi.configuration.cascaded=falseeclipse.ignoreApp=true
create run.bat in Equinox directory,content in run.bat(windows) like this:@echo offjava -jar plugins/org.eclipse.osgi_3.2.1.R32x_v20060919.jar -configuration configuration -console
![Page 29: Introduce OSGi BlueDavy 1.0 2007-10-28](https://reader036.vdocuments.pub/reader036/viewer/2022062313/56649c785503460f9492d121/html5/thumbnails/29.jpg)
23/4/1823/4/18 2929 OSGi China User Group: http://www.osgi.org.cn 致力于致力于 OSGiOSGi 的推广和发的推广和发展展
Deploy outside aloneStart equinox framework and install first bundle i
n OSGi console; install first bundle use directory mode;
– Input command like this in OSGi console:
install file:/D:\work\workspace\OSGi-Bulletin\FirstBundle
install first bundle use jar file; – package first bundle into jar file;
– Export the project as deployable plug-ins and fragments
– Input command like this in OSGi conosle:
install file:/D:\Opendoc\Equinox\plugins\FirstBundle_1.0.0.jar
![Page 30: Introduce OSGi BlueDavy 1.0 2007-10-28](https://reader036.vdocuments.pub/reader036/viewer/2022062313/56649c785503460f9492d121/html5/thumbnails/30.jpg)
23/4/1823/4/18 3030 OSGi China User Group: http://www.osgi.org.cn 致力于致力于 OSGiOSGi 的推广和发的推广和发展展
Manage bundle in consoleuse ss to find bundle id
use start,stop,update,uninstall to manage bundle with bundle id start 2 (start bundle) stop 2 (stop bundle) update 2 (update bundle on the fly) uninstall 2 (uninstall bundle)
![Page 31: Introduce OSGi BlueDavy 1.0 2007-10-28](https://reader036.vdocuments.pub/reader036/viewer/2022062313/56649c785503460f9492d121/html5/thumbnails/31.jpg)
23/4/1823/4/18 3131 OSGi China User Group: http://www.osgi.org.cn 致力于致力于 OSGiOSGi 的推广和发的推广和发展展
Publish OSGi Service Use OSGi declarative services to publish and use OSGi Service,the
n when you run OSGi application,you need install Equinox DS plugin;
Create ServiceBundle to publish OSGi service; Create cn.org.osgi.ppt.service.HelloService Interface; Create cn.org.osgi.ppt.component.HelloComponent to implemention Hel
loService; Publish HelloService as OSGi service using DS component xml;
<component name="HelloComponent"><implementation class="cn.org.osgi.ppt.component.HelloComponent"/><service>
<provide interface="cn.org.osgi.ppt.service.HelloService"/></service>
</component> Add component.xml to MANIFEST.MF Service-Component property Export package cn.org.osgi.ppt.service
![Page 32: Introduce OSGi BlueDavy 1.0 2007-10-28](https://reader036.vdocuments.pub/reader036/viewer/2022062313/56649c785503460f9492d121/html5/thumbnails/32.jpg)
23/4/1823/4/18 3232 OSGi China User Group: http://www.osgi.org.cn 致力于致力于 OSGiOSGi 的推广和发的推广和发展展
Use OSGi Service Add cn.org.osgi.ppt.service to import-package; Use HelloService in firstbundle with two kind methods;
context.getService method– In Activator class: ServiceReference serviceRef=context.getServiceReference(HelloService.class.getName()); if(serviceRef!=null){ HelloService service=(HelloService) context.getService(serviceRef); service.say("Activator"); }
Declarative Services method– create cn.org.osgi.ppt.firstbundle.FirstComponent class with inject service method:
public void setService(HelloService service){this.service=service;}
public void unsetService(HelloService service){if(this.service!=service) return;this.service=null;System.out.println("HelloService 不可用 ");}
– write ds component xml to inject OSGi service;– Add component.xml to MANIFEST.MF Service-Component property
![Page 33: Introduce OSGi BlueDavy 1.0 2007-10-28](https://reader036.vdocuments.pub/reader036/viewer/2022062313/56649c785503460f9492d121/html5/thumbnails/33.jpg)
23/4/1823/4/18 3333 OSGi China User Group: http://www.osgi.org.cn 致力于致力于 OSGiOSGi 的推广和发的推广和发展展
Agenda Play OSGi Who use OSGi What is OSGi OSGi R4 Implemention How to develop OSGi app OSGi Resources
![Page 34: Introduce OSGi BlueDavy 1.0 2007-10-28](https://reader036.vdocuments.pub/reader036/viewer/2022062313/56649c785503460f9492d121/html5/thumbnails/34.jpg)
23/4/1823/4/18 3434 OSGi China User Group: http://www.osgi.org.cn 致力于致力于 OSGiOSGi 的推广和发的推广和发展展
OSGi Resources OSGi R4 Specifications
《OSGi实战》Opendoc 《OSGi进阶》Opendoc http://www.osgi.org http://www.osgi.org.cn http://www.aqute.biz http://blog.bluedavy.cn
![Page 35: Introduce OSGi BlueDavy 1.0 2007-10-28](https://reader036.vdocuments.pub/reader036/viewer/2022062313/56649c785503460f9492d121/html5/thumbnails/35.jpg)
Click to edit company slogan .
OSGi China User Group