使用Spring DM添加ServiceListener

时间:2023-01-13 07:57:43

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.

与Spring DM。我找到了用于添加生命周期管理的监听器的参考资料。但这与正在注册的服务的生命周期有关。我需要知道的是注册/取消注册特定服务接口的任何服务的生命周期。

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.

需要知道这一点的捆绑包实际上并不是在创建服务,而是会使用它。由于此服务的多个实例将在运行时更改,因此我不能简单地在Spring配置中创建服务引用。

1 个解决方案

#1


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.

Spring DM支持引用一组服务。不幸的是,作为一个新用户,我无法发布链接,但是这个功能在Spring DM 1.2文档的7.2.2节中有所描述。 Spring DM会在服务注册表中添加和删除服务时自动更新此集合的内容。

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.

当您在服务上声明引用时,无论是作为单个引用还是作为服务集合,您还可以声明一个侦听器bean,该服务器将随着服务的来去通知而被通知。这在第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.

我建议使用List或Set服务,并使用监听器bean,以便通知您对集合内容的更改。

#1


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.

Spring DM支持引用一组服务。不幸的是,作为一个新用户,我无法发布链接,但是这个功能在Spring DM 1.2文档的7.2.2节中有所描述。 Spring DM会在服务注册表中添加和删除服务时自动更新此集合的内容。

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.

当您在服务上声明引用时,无论是作为单个引用还是作为服务集合,您还可以声明一个侦听器bean,该服务器将随着服务的来去通知而被通知。这在第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.

我建议使用List或Set服务,并使用监听器bean,以便通知您对集合内容的更改。