用于API和实现的单独OSGI捆绑软件是否常见? [英] Is separate OSGI bundles for api and implementation common practice?

查看:84
本文介绍了用于API和实现的单独OSGI捆绑软件是否常见?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有依赖项的类,我想在不重新启动依赖项的情况下进行热部署.该类有一个接口,但是只有一个具体的实现.

I have a class with dependencies which I want to hot deploy without restarting the dependencies. The class has an interface but there's only one concrete implementation.

最初,我创建了一个带有导出接口的捆绑包,并使用未导出的激活器和实现类注册了实现.但是,如果我更新捆绑软件,则在调用PackageAdmin#refreshPackages时,更新后将重启使用注册服务的捆绑软件(使用fileinstall时这是自动的).

Initially I created a single bundle with exported the interface and registered the implementation using activator and implementation classes which were not exported. However, if I update the bundle, bundles which use the registered service get restarted after the update when PackageAdmin#refreshPackages is called (this is automatic when using fileinstall).

我通过创建单独的api包来解决此问题.

I have fixed this by creating a separate api bundle.

这是实现这一目标的最好方法吗?

Is this the best way to achieve this?

您是否将有一个捆绑包,可导出其api并将实现包含在同一捆绑包中.据我所知,任何赠礼包都将导出其所有类或不输出任何类.我想念什么?

Would you ever have a bundle which exports its api and includes the implementation in the same bundle. As far as I can see any give bundle would either export all its classes or no classes. What am I missing?

推荐答案

将API包与其在OSGi中的实现分开是绝对的最佳实践.如果执行此操作,则任何使用该API的捆绑包都仅需要从该API捆绑包中导入类,这可以使您在运行时更改实现而无需重新启动相关的捆绑包.

It is definitely a best practice to separate API bundles from their implementations in OSGi. If you do this, then any bundle that uses the API only needs to import classes from the API bundle, which can allow you to change implementations at runtime without restarting your dependent bundles.

理想情况下,您的实现捆绑包将实现接口,并将实现导出为API提供的接口上的服务.这样,客户端捆绑包无需参考实现捆绑包即可使用该服务.

Ideally your implementation bundle would implement the interface and export implementation as a service on the API provided interface. This allows the client bundles to utilize the service without referencing the implementation bundle.

这篇关于用于API和实现的单独OSGI捆绑软件是否常见?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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