使用DS的OSGi中的动态目标查询 [英] Dynamic target queries in OSGi with DS

查看:73
本文介绍了使用DS的OSGi中的动态目标查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在DS中使用引用时,我可以指定一个目标,该目标将使我能够缩小所需的服务实例的范围.问题在于所有示例都显示了必须在代码时完成的静态查询.有没有办法进行动态查询(也许可以从Configuration Admin中提取属性)?

When I use a reference in DS I can specify a target that will allow me to narrow down which service instance I want. The problem is that all the examples show static queries that must be done at code time. Is there a way to do a dynamic query (maybe pull in a property from Configuration Admin)?

如果DS不支持此功能,是否还有另一个OSGi依赖项注入框架(蓝图,iPojo等)将支持此功能?

If DS does not support this is there another OSGi dependency injection framework (blueprint, iPojo, etc) that will support this?

推荐答案

您始终可以使用引用的target属性来执行第一级过滤器.如果您的bind方法具有签名

You can always use the target attribute of the reference to peform a first level filter. The if your bind method has the signature

void <method-name>(<parameter-type>, Map);

然后,您可以在包含服务属性的地图上运行任何动态过滤器.如果过滤器不匹配,则可以暂时忽略该组件.

Then you can run any dynamic filter over the Map which contains the services properties. If the filter does not match, you can ignore that component (for the time being.)

或者,由于组件的配置可以包含引用的目标过滤器,因此您可以修改组件的配置以更改目标过滤器.

In the alternate, since the component's configuration can contain the reference's target filter, you can modify the component's configuration to alter the target filter.

这篇关于使用DS的OSGi中的动态目标查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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