使用 Spring DM 添加 ServiceListener
我想知道是否可以
public void start(BundleContext context)
{
String filter = "filter for my specific service";
context.addServiceListener(new MyServiceListener(), filter);
}
用 Spring DM 做同样的事情。 我找到了 添加监听器以进行生命周期管理。 但这与所注册的服务的生命周期有关。 我需要的是了解注册/取消注册特定服务接口的任何服务的生命周期。
需要知道这一点的捆绑包实际上不创建服务,但将使用它。 由于该服务的多个实例会在运行时发生变化,因此我不能简单地在 Spring 配置中创建服务引用。
I am wondering if it possible to do the equivalent of
public void start(BundleContext context)
{
String filter = "filter for my specific service";
context.addServiceListener(new MyServiceListener(), filter);
}
with Spring DM. I have found reference material for adding listeners for lifecycle management. But this relates to the lifecycle of the service being registered. What I need is to be made aware of the lifecycle of any service that is registered/unregistered of a specific service interface.
The bundle that needs to know this is not actually creating the service, but will be using it. Since there will multiple instances of this service that will change at runtime, I cannot simply create a service reference in my Spring configuration.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Spring DM 支持引用服务集合。 不幸的是,作为一个新用户,我无法发布链接,但 Spring DM 1.2 文档的 7.2.2 节中描述了此功能。 当服务添加到服务注册表或从服务注册表中删除时,Spring DM 会在运行时自动更新此集合的内容。
当您声明对服务的引用时,无论是作为单个引用还是服务集合,您还可以声明一个侦听器 bean,该侦听器 bean 将在服务来来去去时收到通知。 这记录在第 7.2.3 节中。
我建议使用服务列表或服务集,并使用侦听器 bean,以便您收到集合内容更改的通知。
Spring DM includes support for referencing a collection of services. Unfortunately, as a new user, I can't post links, but this functionality is described in section 7.2.2 of the Spring DM 1.2 documentation. Spring DM automatically updates the contents of this collection at runtime as services are added to and removed from the service registry.
When you declare a reference upon a service, be it as a single reference, or a collection of services, you can also declare a listener bean that will be notified as services come and go. This is documented in section 7.2.3.
I'd recommend making use a List or Set of services, and using a listener bean so that you're notified of changes to the collection's contents.