假设我有一个包含类X的OSGI Bundle . 假设这个类包含对特定服务的OSGI引用 . 像这样的东西:
ServiceReference[] references = context.getServiceReferences (serviceSpecification,someFilter);
有没有办法可以动态识别引用所连接的服务规范?有没有办法识别服务过滤器(上面的第二个参数)?
例如,像这样:
System.out.println(references[0].getServiceSpecification);
System.out.println(references[0].getServiceFilter);
我需要在bundle之外的代码中找出这些值 .
Work done so far:
我使用iPOJO通过创建bundle的iPOJO组件实例获取引用属性,然后获取其属性描述,如下所示:
ComponentInstance componentInstance = factory.createComponentInstance(configuration);
instanceDescription= (PrimitiveInstanceDescription) componentInstance.getInstanceDescription();
PropertyDescription[] propertyDescription = instanceDescription.getProperties();
我可以使用上面的 propertyDescription
获取引用名称,类型,值,但该值作为对象返回,我无法得到我需要的内容 . 有人可以帮忙吗?谢谢 .
1 回答
请看Service Hooks . 使用Service Hooks,您可以挂钩服务注册表操作并观察服务的发现 .