《深入理解OSGi:Equinox原理、应用与最佳实践》一3.5 系统Bundle

3.5 系统Bundle

OSGi框架本身也会以一个Bundle的形式向其他Bundle提供资源、Package和服务,比如已经在书中多次出现的Bundle、BundleContext、FrameworkListener等接口,以及后面将会介绍的EventAdmin、PackageAdmin等服务都是由系统Bundle提供的。OSGi规范规定了系统Bundle的Bundle ID固定为0,Bundle的getLocation()方法返回固定字符串“System Bundle”,这些特征使得任何Bundle都可以很方便地从BundleContex.getBundle(0)或BundleContex.getBundle("System Bundle")方法中获取到系统Bundle的对象实例。
在OSGi容器中,系统Bundle可以认为是一定存在的,每一个Bundle都默认依赖这个系统Bundle。下面列出了Equinox框架的系统Bundle的元数据信息。

osgi> headers 0
Bundle headers:
 Bundle-Activator = org.eclipse.osgi.framework.internal.core.SystemBundleActivator
 Bundle-Copyright = Copyright (c) 2003, 2004 IBM Corporation and others. All rights reserved. This program and the accompanying materials  are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html
 Bundle-Description = OSGi System Bundle
 Bundle-DocUrl = http://www.eclipse.org
 Bundle-Localization = systembundle
 Bundle-ManifestVersion = 2
 Bundle-Name = OSGi System Bundle
 Bundle-RequiredExecutionEnvironment = J2SE-1.5,OSGi/Minimum-1.2
 Bundle-SymbolicName = org.eclipse.osgi; singleton:=true
 Bundle-Vendor = Eclipse.org - Equinox
 Bundle-Version = 3.8.0.qualifier
 Eclipse-BundleShape = jar
 Eclipse-ExtensibleAPI = true
 Eclipse-SystemBundle = true
 Export-Package = org.eclipse.osgi.event;version="1.0",
……//版面关系省略其他Package
 Export-Service = org.osgi.service.packageadmin.PackageAdmin,org.osgi.service.permissionadmin.PermissionAdmin,org.osgi.service.startlevel.StartLevel,org.eclipse.osgi.service.debug.DebugOptions
 Main-Class = org.eclipse.core.runtime.adaptor.EclipseStarter
 Manifest-Version = 1.0

系统Bundle与OSGi框架密不可分,由于它的特殊性,其生命周期变化过程也与普通Bundle有所区别。以下是OSGi规范对系统Bundle生命周期几个过程执行的动作规定。
启动过程:Bundle的start()方法为空操作,因为OSGi框架一启动,系统Bundle就已经启动。
停止过程:Bundle的stop()方法会立即返回并在另外一条线程中关闭OSGi框架。
更新过程:Bundle的update()方法会立即返回并在另外一条线程中重启OSGi框架。
卸载过程:系统Bundle无法卸载,如果执行了Bundle的uninstall()方法,那么框架会抛出一个BundleException异常。
系统Bundle的启动级别固定为0,这个启动级别是无法使用StartLevel接口中的set-BundleStartLevel()进行修改的;如果这样做了,那么OSGi框架将会抛出一个Illegal-ArgumentException异常。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值