获取api的所有实现 [英] get all implementations of an api
问题描述
我已经编写了API捆绑包和一些实施服务.
I have written an API Bundle and some implementing services.
现在我想将它们用作插件,所以首先我需要列出我拥有的所有服务.
Now i want to use them as plugins, so first of all i need a list of all the services i have.
我正在像这样启动api:
I'm starting the api like this:
Framework m_fwk = new org.apache.felix.framework.FrameworkFactory().newFramework(null);
m_fwk.init();
AutoProcessor.process(null, m_fwk.getBundleContext());
m_fwk.start();
Bundle api = m_fwk.getBundleContext().installBundle(
"file:/foo/bar/api/target/api-1.0.jar");
api.start();
因此,现在已加载API.现在我需要知道哪些捆绑软件实现了此API,如何从框架中获取此信息?
So now the API is loaded. Now i need to know which bundles implements this API, how can i get this information from the framework?
推荐答案
您似乎只加载了一个API捆绑包,我想您想为实现安装其他捆绑包?然后,大多数人会聘请导演左右:
You only seem to load an API bundle, I guess you want to install other bundles for the implementations? Most people then load a director or so:
for ( File b : bundles.listFiles() ) {
ctx.installBundle( b.toURI().toURL() );
}
这些捆绑包中的每一个都应该看起来像(使用DS):
Each of these bundle should look like (using DS):
@Component
public class Impl implements API {
public whatever() { ... }
}
收集服务的捆绑软件如下所示:
The bundle collecting the services could look like:
@Component
public class Collector {
@Reference(type='*')
void addAPI( API api ) { ... }
void removeAPI( API api ) { ... }
}
这是通过DS的bnd注释完成的(有关示例,请参见bndtools).但是,您也可以在Blueprint,iPojo和许多其他帮助器中实现/收集服务.
This is done with the bnd annotations for DS (see bndtools for examples). However, you can also implement/collect the services in Blueprint, iPojo, and many other helpers.
这篇关于获取api的所有实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!