您好,欢迎来到花生壳b2b外贸网信息发布平台!
18951535724
  • 《深入理解OSGi:Equinox原理、应用与最佳实践》一3.5 系统Bundle

       2026-02-24 网络整理佚名1470
    核心提示:文章浏览阅读179次。本文介绍了OSGi框架中的系统Bundle,包括其特性、生命周期管理及元数据信息。系统Bundle是OSGi框架的基础组件,提供了核心服务和接口。

    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:equinox原理,应用与最佳实践

    在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生命周期几个过程执行的动作规定。

    深入理解osgi:equinox原理,应用与最佳实践

    启动过程:Bundle的start()方法为空操作,因为OSGi框架一启动,系统Bundle就已经启动。

    停止过程:Bundle的stop()方法会立即返回并在另外一条线程中关闭OSGi框架。

    更新过程:Bundle的update()方法会立即返回并在另外一条线程中重启OSGi框架。

    深入理解osgi:equinox原理,应用与最佳实践

    卸载过程:系统Bundle无法卸载,如果执行了Bundle的uninstall()方法,那么框架会抛出一个BundleException异常。

    系统Bundle的启动级别固定为0,这个启动级别是无法使用StartLevel接口中的set-BundleStartLevel()进行修改的;如果这样做了,那么OSGi框架将会抛出一个Illegal-ArgumentException异常。

     
    举报收藏 0打赏 0评论 0
    更多>相关评论
    暂时没有评论,来说点什么吧
    更多>同类百科知识
    推荐图文
    推荐百科知识