OSGI 捆绑包和组件之间有什么区别?
开始使用 osgi,我想知道捆绑包和组件之间的概念差异是什么。以及何时使用其中的哪一个。欢迎任何指点。
编辑:
组件和捆绑包提供不同的接口,因此它们可能不可互换
getting started with osgi, i wonder what's the conceptual diffence between bundles and components. And when to use which of them. Any pointers are welcome.
EDIT:
Components and Bundles provide different interfaces and therefore they are probably not interchangeable
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
组件是:
简而言之:
一个 Bundle 只能拥有一个激活器(需要一个
BundleContext
),并且可以拥有任意数量的活动组件。这意味着您最终可能会尝试将一个激活器中几个松散相关的关注点放入一个类中。
这就是为什么管理 声明式服务的那些组件,通过 SCR (“服务组件运行时”是一个“扩展包”,实现新的和改进的 OSGi R4.2 DS - 声明式服务 - 规范)。
自 OSGi 4.2 以来尤其如此,因为现在将 DS 组件编写为 POJO 变得更加容易:
activate
和deactivate
方法不再需要采用ComponentContext
参数。另请参阅惰性声明式服务。注意:
它可以帮助在 OSGi 上下文中替换这些术语并查看“我们如何到达那里”(Neil Bartlett 的优秀博客文章)
以下是一些相关摘录,其中“模块”最终是 OSGi 捆绑包(管理声明服务的组件) ):
模块分离
模块访问级别
出口和进口的粒度
封装接线
版本
打包模块和元数据
后期绑定
A component is:
In short:
A bundle can have only one activator (needing a
BundleContext
), and can have as many active components as you want.That means you may end up trying to fit in one activator several loosely-related concerns into a single class.
That is why it may be easier to manage those components by Declarative Services, through the SCR (the "Service Component Runtime" which is an "extender bundle" implementing the new and improved OSGi R4.2 DS - Declarative Service - specification).
This is especially true since OSGi 4.2 because it is now much easier to write DS components as POJOs: the
activate
anddeactivate
methods are no longer required to take aComponentContext
parameter. See also Lazy Declarative Service.Note:
It can help to replace those terms in the context of OSGi and look at "how we got there" (excellent blog post by Neil Bartlett)
Here are some relevant extracts, where the "modules" end up being the OSGi Bundles (managing Components which declare Services):
Module Separation
Module Access level
Granularity of Exports and Imports
Package Wiring
Versions
Packaging Modules and Metadata
Late Binding
在 OSGi 术语中,“组件”就像一个运行时服务。每个组件都有一个实现类,并且可以选择实现一个公共接口,有效地提供这种“服务”。 OSGi 的这个方面有时被比作服务注册表模式。
根据定义,OSGi 中的组件是由捆绑包提供的。捆绑包可以包含/提供多个组件。虽然捆绑包本身可能不提供服务,但组件/声明性服务可用于使 OSGi 更加面向服务。您没有义务使用组件/服务。
In OSGi terminology a "component" is like a run-time service. Each component has an implementation class, and can optionally implement a public interface, effectively providing this "service". This aspect of OSGi is sometimes likened to a service registry pattern.
Components in OSGi are, by definition, provided by a bundle. A bundle may contain/provide multiple components. While by itself a bundle may not provide a service, components/declarative services are used to make OSGi more service oriented. You are under no obligation to use components/services.