 鲜花( 0)  鸡蛋( 0)
|
OSGi是Open Service Gateway Initiative的简称,该组织建立于1999年,是一个非赢利机构,旨在建立一个开放的服务规范,为通过网络向设备提供服务建立开放的标准。
' c% H- `3 t" q6 E2 sOSGI 规范包括了构建开放的可交付网络服务的各方面,OSGI规范又包括了以下子规范。
! w( w& x% \! lFramework规范(OSGI核心,提供一个安全的可管理的Java Framework来部署可扩展的Java服务。)
) Y2 p# U2 S3 xPackage Admin Service规范(来管理不同的Bundle之间的引用关系。当Bundle更新或者反安装时判断是否有其他的服务正在使用当前的Bundle)
- Y; P! g2 Q# h& X% m/ L8 ~/ D5 \Start Level规范(定义了启动和停止一个OSGi Service Platform时,不同的Bundles的启动或者停止的先后顺序)
" B: I# r4 @ @, Q( F0 v7 jPermission Admin Service规范(Bundle是否许可执行另外的Bundle的代码)
4 d' e( G0 Y: q' ^2 T5 _5 wURL Handlers Service规范(怎样注册URL Schema,如何将java.io.InputStream对象转换为特定的Java对象)4 }0 L4 ?! W2 E9 i- H
Log Service规范 (以下略。。。)9 X! f0 V; o, T7 E: s
Configuration Admin Service规范" X4 ?2 ~* ^7 [ T; a
Device Access Specification% k/ o6 K& j* s0 E
User Admin Service Specification% \% N- v( k1 z: S& N1 W
IO Connector Service Specification: \3 @4 j% z3 t/ ^
Http Service Specification
5 P' `4 [! j, kPreference Service Specification* A: L! H- I Z% i) t6 S
Wire Admin Service Specification0 }, @0 j- F3 a3 ~ Y6 w) _
XML Parser Service Specification
- b5 P* q/ a* J, b# p3 W! c5 `Metatype Specification
1 O; Q; P3 X) c3 p: f! x0 vService Tracker Specification) Y' g2 ]% b' w/ d5 u
Measurment and State Specification3 P/ f4 b; ~7 J- _& F7 s
Position Specification2 P3 f- k ], M4 r/ B" g
Execution Environment Specfication# A0 i8 U1 \, J; P2 m
OSGI Framework8 y( X1 D3 L0 F( ~
Framework是OSGI Service Platform规范的核心组成部分。它提供了一个通用的、安全可管理的Java framework。通过这个Framework可以支持一种叫做bundles的Service application的部署和扩展。' A7 x7 N3 F0 c5 T& J: g# j/ M
OSGI兼容设备可以下载并且安装OSGI bundles,也可一当他们不再需要的时候删除。bundles安装后会注册一定数量的Services,并被由同一个Framework下的其他bundles使用。
/ y7 p% w' x |6 D3 V在一个动态扩展的的 OSGI环境中,Framework管理bundles的安装和更新。同时也管理bundles和Services之间的依赖关系。: Q t) a. o- `; h: g0 ~& z+ I
Framework提供给bundle开发者必须的资源来在Java平台上开发,为开发的bundles提供了代码动态加载的功能, 也使得开发者开发、部署一个大规模的Services变的很容易。
/ D) l) ~, B% B" d, ?$ V" U( j5 R其 次,Framework为Java bundle开发者提供了简明一致的编程模型。简化了开发部署的复杂性。这个编程模型允许开发者将自己的接口规范绑定到OSGI环境中的Service。 The selection of a specific implementation, optimized for a specific need or from a specific vendor, can thus be deferred to run-time./ {3 e% N/ U1 G, ]" o( k% ~7 z0 ~) O
一个一致的编程模型帮助开发者可以应付一些可估计的危急错误。Framework将会运行在不同的硬件环境上,但一致的接口确保软件组建可以运行在一致的服务接口上。" P2 C, a0 h( }. ^3 e# Y0 j* s
The Bundle Object
4 C9 O2 ?! v1 p0 c0 M3 Y: c对于每一个安装在OSGI Service Platform的bundle都有一个与之关联的bundle object。一个bundle对象用来管理bundle的生命周期。这项工作通常由Management Agent来做。7 ]9 \0 ^* y* B7 D! g2 ~
Bundle State
! s( ^7 U/ F1 S7 O& Bbundle有以下状态;* z% ^8 z/ _8 W; z1 w. _( e
INSTALLED – The bundle has been successfully installed. Native code clauses must have been validated.6 Y( t; }) ]2 |( C
RESOLVED – All Java classes that the bundle needs are available. This state indicates that the bundle is either ready to be started or has stopped.) B8 T. r/ |; a9 q# c6 O- W* |
STARTING – The bundle is being started, and the BundleActivato r. start method has been called and has not yet returned.
: Y) M4 m6 u; f" W- pSTOPPING – The bundle is being stopped, and the BundleActivato r. stop method has been called and has not yet returned.
: ]1 m9 |& @! N! J; i6 P1 OACTIVE – The bundle has successfully started and is running.
# ?8 j; e: R$ ^! r/ b$ ~UNINSTALLED – The bundle has been uninstalled. It cannot move into another state.* V5 G* ^% ~) a7 P. o6 _! P
eclipse 3.0并没有用OSGI替换掉原来的PlugIn机制。它只是做了与标准兼容的工作:给用户提供了一系列的API来访问,在这个过程中,就必须要做一些改 变(比如plugin registry和loading机制)来同OSGI标准完全兼容。最初的Plugin核心只支持静态的扩展,就是说,如果要改变一个已经存在的Plug 就必须重启core,也就是要退出Eclipse并重启。
/ O1 i# a9 J( b/ M6 P$ }9 @+ ~3 U有很多人问Eclipse为什么要兼容OSGI规范而不是其他的规范呢?9 w; F$ A' O, ` Q! E2 O! ^
在 Eclipse被捐赠出来以前,Eclipse由OTI来开发,其目标是开发一个嵌入式Java软件的开发平台。互联网上现在仍然由很多的连接指向 Visual Age Micro Edition (VAME). 这也是SWT被构思的一个原因,他们想将SWT使用在嵌入式设备中的用户界面。这种渊源关系解释了当时为什么选择OSGI规范。( T2 s9 w# x( N
另外一个原因是除了OSGI没有其他的规范。OSGI规范在轻量级服务架构应用方面被广泛的支持。而且OSGI被好多电信业的知名公司和一些其他行业的知名公司所支持。他们需要使用OSGI来同Sun的J2ME来抗衡。 |
|