7.1 Introduction
Bundles can export packages to other bundles. This exporting creates a dependency between the bundle exporting a package and the bundle using the package. When the exporting bundle is uninstalled or updated, a decision must be taken regarding any shared packages.
The Package Admin service provides an interface to let the Management Agent make this decision.
Bundles能输出包到其他bundles,这个输出将会在输出bundle与引入bundle间发生一个依赖关系,当输出bundle被卸载或更新时,对相关的共享包必须做出一个决定(相应动作)。包管理服务提供了一个接口让Management Agent来做这个决定。
7.1.1 Essentials
• Information – The Package Admin service must provide the sharing status of all packages. This should include information about the importing bundles and exporting bundle.
• Policy – The Package Admin service must allow a management agent to provide a policy for package sharing when bundles are updated and uninstalled.
• Minimal update – Only bundles that depend on the package that needs to be resolved should have to be restarted when packages are forced to be refreshed.
• Information – 包管理服务必须提供所有包的共享状态,这应该包括输出bundle和引入bundle的相关信息。
• Minimal update – 依赖于需要被解析的包的bundles应该在这些包被强制刷新的时候被重启
7.1.2 Entities
• PackageAdmin – The interface that provides access to the internal Framework package sharing mechanism.
• ExportedPackage – The interface provides package information and its sharing status.
• RequiredBundle – The interfaces provides information about the bindings of required bundles.
• Management Agent – A bundle that is provided by the Operator to implement an Operator specific policy.
• PackageAdmin – 接口,提供了对框架内部包共享机制的访问。
• ExportedPackage – 接口,提供包的信息和包的共享状态。
• RequiredBundle – 接口,提供required bundles的绑定相关的信息
• Management Agent – 一个bundle,由操作人员提供,用于实现操作人员指定的策略。
7.1.3 Operation
The Framework’s system bundle should provide a Package Admin service for the Management Agent. The Package Admin service must be registered under the org.osgi.service.packageadmin.PackageAdmin interface by the system bundle. It provides access to the internal structures of the Framework related to package sharing, fragments and required bundles. This is an optional singleton service, so at most one Package Admin service must be
registered at any moment in time.
框架的系统bundle应该为Management Agent提供一个包管理服务,包管理服务必须由系统bundle注册在org.osgi.service.packageadmin.PackageAdmin的接口名下,它提供对框架内部结构中关于包共享,片段和required bundles的访问。这是一个可选的单例服务,因此最多只有一个包管理服务被注册。
The Framework must always leave the package sharing intact for packages exported by a bundle that is uninstalled or updated. A Management Agent can then choose to force the framework to refresh these packages using the Package Admin service. A policy of always using the most current packages exported by installed bundles can be implemented with a Management Agent that watches Framework events for bundles being uninstalled or updated, and then refreshes the packages of those bundles using the Package Admin service.
一个卸载或更新的bundle输出的包,框架必须总是保证这些包没有被使用,这时Management Agent就可以使用包管理服务选择强制框架刷新这些包。总是使用安装bundle输出的通用包的策略可以被一个监听卸载或更新bundle的框架事件的Management Agent实现,然后使用包管理服务刷新那些bundles的包。
7.2 Package Admin
The Package Admin service is intended to allow a Management Agent to define the policy for managing package sharing. It provides methods for examining the status of the shared packages. It also allows the Management Agent to refresh the packages and stop and restart bundles as necessary.
包管理服务允许一个Management Agent定义管理包共享的策略,它提供了检查共享包的状态的方法,也允许Management Agent刷新包,并在需要的时候停止和重启bundles
7.2.1 Package Sharing
The PackageAdmin class provides the following methods:
• getExportedPackage(String) – Returns an ExportedPackage object that provides information about the requested package. This information can be used to make the decision to refresh the package.
• getExportedPackages(Bundle) – Returns a list of ExportedPackage objects for each package that the given bundle exports.
• refreshPackages(Bundle[]) – The management agent may call this method to refresh the exported packages of the specified bundles. The actual work must happen asynchronously. The Framework must send a Framework.PACKAGES_REFRESHED when all packages have been refreshed.
• resolveBundles(Bundle[]) – The Framework must attempt to resolve the given bundles.
类PackageAdmin提供了一下方法:
• getExportedPackage(String) – 返回一个提供了与requested package相关的信息的ExportedPackage对象,这个信息可以决定是否需要刷新包。
• getExportedPackages(Bundle) – 返回一个ExportedPackage对象的列表,给定的bundle所输出的包
• refreshPackages(Bundle[]) – management agent可以调用这个方法去刷新指定的bundle输出的包,这个动作必须是同步的。当所有包都被刷新后,框架必须发出一个Framework.PACKAGES_REFRESHED事件。
• resolveBundles(Bundle[]) – 框架必须尝试解析给定的bundles
7.2.2 Bundle Information
There is only the Bundle interface in the Framework API while bundles can perform different roles in the Framework. The Package Admin service provides access to this structural information.
• getBundle(Class) – Answer the bundle with the class loader that loaded the given class.
• getBundles(String,String)– Find a the set of bundles with the given bundle symbolic name and that fall within the given version. If the version is null, all bundles with the given bundle symbolic name are returned.
• getBundleType(Bundle) – Answer the type of the bundle. This is a bitmap of the different types. The following type is defined:
• BUNDLE_TYPE_FRAGMENT– The bundle is a fragment.
bundles可以在框架中扮演不同的角色,但是这些bundle都在来自一个接口Bundle,包管理服务提供了对这个结构信息的访问:
• getBundle(Class) – 查找一个bundle,这个bundle的classloader加载了这个给定的类
• getBundles(String,String)– 查找一个bundle集合,通过给定的标记名和版本号,如果版本号是null,那么将返回给定的标记名的bundles
• getBundleType(Bundle) – 查询bundle的类型。定义了以下类型
• BUNDLE_TYPE_FRAGMENT–bundle是个片段
7.2.3 Fragments and Required Bundles
The Package Admin service provides access to the network that is created by by requiring bundles and hosting fragments.
• getFragments(Bundle) – Return an array of bundles that currently act as fragment to the given bundle. If there are no fragments attached, null must be returned.
• getHosts(Bundle) – Return the bundle that acts as host to this fragment bundle. The given bundle should be an attached fragment bundle, otherwise null is returned.
• getRequiredBundles(String) – Return an array of RequiredBundle objects that match the given name (or all of the given name is null). The RequiredBundle object provides structural information about a required bundle.
包管理服务提供了对由需求bundle和主片段形成的关系网的访问。
• getFragments(Bundle) – 返回一个bundles的集合,这个集合中的bundles是给定bundle的片段,如果没有片段,返回null
• getHosts(Bundle) – 返回给定bundle的宿主bundle。这个给定的bundle应该是个片段,否则返回null。
• getRequiredBundles(String) – 返回RequiredBundle对象的集合,这个集合匹配了给定的名字(bundle标记名),如果给定的名字是null,将返回所有required的bundles。每一个RequiredBundle对象提供了对一个required的bundle的结构信息的描述。
7.2.4 Exported Package
Information about the shared packages is provided by the ExportedPackage objects. These objects provide detailed information about the bundles that import and export the package. This information can be used by a Management Agent to guide its decisions.
与共享包相关的信息是由ExportedPackage对象提供的,这些ExportedPackage对象提供了引入包或输出包的bundles的细节信息,这些信息可以被Management Agent用于参考它的决定。
7.2.5 Refreshing Packages and Start Level Service
Bundles may be stopped and later started when the refreshPackages(Bundle[]) method is called. If the Start Level Service is present, the stopping and starting of bundles must not violate the start level constraints. This implies that bundles with a higher start level must be stopped before bundles with a lower start level are stopped. Vice versa, bundles should not be started
before all the bundles with a lower start level are started. See Startup Sequence on page 207.
当调用refreshPackages(Bundle[])方法时,bundles可能会先停止,然后又启动,如果设置了启动级别服务,那么bundles的停止和启动必须不能违反启动级别的限制,也就是说高启动级别的bundles必须比低启动级别的bundles先停止,低启动级别的bundles比高启动级别的bundles先启动。
posted on 2008-04-29 15:11
Phrancol Yang 阅读(855)
评论(0) 编辑 收藏 所属分类:
OSGI