OSGi组件和服务有什么区别 [英] What is the difference between OSGi Components and Services

查看:127
本文介绍了OSGi组件和服务有什么区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在OSGi下,组件与服务之间的主要区别是什么? 据我了解,所有服务都必须是组件,但并非所有组件都必须是服务.

Under OSGi, what are the main differences between Components vs Services? As I understand it, all Services must be Components, but not all Components must be services.

在示例用例中,使用一种优势会带来什么好处?

What are the benefits of using one over the other with sample use cases?

推荐答案

组件"的形式化定义少于服务.

"Components" are less formally defined than services.

服务是在OSGi服务注册表中注册的任何对象,可以使用其接口名称进行查找.唯一的先决条件是服务应实现某个接口……任何接口.例如,我可以在java.lang.Runnable接口下注册一个可运行对象,客户端可以使用该接口名称进行查找.

A service is any object that is registered in the OSGi Service Registry and can be looked up using its interface name(s). The only prerequisite is that a service should implement some interface... any interface. For example I could register a runnable object under the java.lang.Runnable interface, and clients could look it up using that interface name.

组件"往往是其生命周期受管理的对象,通常由诸如声明性服务(DS),蓝图或iPOJO之类的组件框架来管理.请参阅OSGi社区Wiki上的此页面,以获取有关可用的不同组件框架的讨论.

A "component" tends to be an object whose lifecycle is managed, usually by a component framework such as Declarative Services (DS), Blueprint or iPOJO. See this page on the OSGi Community Wiki for a discussion of the different component frameworks available.

一个组件可以具有以下任何一项功能,可以组合使用或单独使用:

A component may have any of the following features, in combination or alone:

  • 一个组件可以开始停止;尽管这也是一个非正式术语,但这将被视为活动"组件.不需要启动或停止的组件称为被动组件.
  • 组件可以发布本身作为OSGi服务.
  • 组件可以绑定到消费 OSGi服务.
  • A component may be started and stopped; this would be considered an "active" component, though that is also an informal term. A component that doesn't need to be started or stopped is called passive.
  • A component may publish itself as an OSGi service.
  • A component may bind to or consume OSGi services.

通常,使用组件框架是使用OSGi服务的最简单方法,因为该框架将管理与您要使用的服务的绑定.例如,您可以说您的组件依赖"特定服务,在这种情况下,仅当该服务可用时才创建和激活该组件,并且当该服务不可用时也将销毁该组件.

In general, using a component framework is the easiest way to work with OSGi services because the framework will manage the binding to the services that you want to consume. For example you could say that your component "depends on" a particular service, in which case the component will only be created and activated when that service is available -- and also it will be destroyed when the service becomes unavailable.

这篇关于OSGi组件和服务有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆