OSGi ConfigAdmin 服务删除

OSGi ConfigAdmin service deletion

我正在使用多个 osgi 实例 components/services。 这些 osgi 组件配置有配置策略 = required,并通过 ConfigurationAdmin 添加或删除配置来实例化和删除。 此外,我使用 "sets" 个服务实例,并且每个集合都通过其配置配置为仅使用来自同一集合的服务实例作为参考 (ref.target=(id="123")).

问题: 在某些时候,应该删除一组。但是,当通过 ConfigAdmin 从一组中删除配置对象时,另一组的一些服务也会停用。它们会立即重新激活,但会丢失所有服务引用并且无法使用。

我不明白他们为什么要停用。

编辑

服务通常是这样定义的:

@Component(policy = ConfigurationPolicy.REQUIRE)
@Service
public class AServiceImpl implements AService {

    @Reference(target = "(service.pid=*)")
    BService bService;

    ...
}

BServiceImpl 也使用所需的配置策略。

因为来自 felix scr 的这个文档片段,所以在注释中设置了目标:

A service target filter to select specific services to be made available. In order to be able to overwrite the value of this value by a configuration property, this parameter must be declared. If the parameter is not declared, the respective declaration attribute will not be generated

实例化新服务 "set" 时,将对集合中的每个服务执行这些步骤:

每项服务

Configuration serviceConfiguration = configurationAdmin.createFactoryConfiguration(serviceInterfaceName, null);

每项服务的每个引用

Properties serviceProperties.put(ref + ".target", "(" + PID + "=" + pid + ")");
...
serviceConfiguration.update(dict);

我在 bindXXX() 方法中记录了引用的配置 属性 pid,过滤器似乎可以工作。我总是得到 pid 相同的引用。

我会尽快在 github 上添加一个 运行 示例。

EDIT2

我添加了一个示例来演示该行为。我创建了两个 "sets" 服务,调用服务函数并在函数完成后删除服务集。删除服务集一时服务集二重新激活。

代码示例 https://github.com/andineupert/osgi-configadmin-example.git

我终于意识到这是由声明式服务的旧 Equinox 实现引起的。我切换到 org.apache.felix.scr 2.0.4,现在它运行良好。