is there a way to view registered services in an OSGi application?

久未见 提交于 2019-12-10 12:32:51

问题


I have an OSGi application running Equinox. I'd like to see the services that are provided by the application. How can I do this?


回答1:


It depends whether you mean interactively, using an OSGi shell, or programmatically from your application.

Interactively

You can use the Equinox console. See 'services'. To only see the services you have deployed you need to use an LDAP filter. Here's an example:

(objectClass=my.package.name.*)

Also see @Neil Bartlett's answer which might be easier as you can just constrain by bundle id (assuming you know it, but that's easy to find).

Programatically

Use the ServiceTracker approach. Neil also wrote all about this, so make sure to give him your upvotes too :)




回答2:


From the gogo shell type:

inspect cap service

That will show all services registered by all bundles. If you want to show services for a specific bundle then type:

inspect cap service <id>

Where <id> is the numeric bundle ID of the bundle you are interested in.




回答3:


By far, and I mean by far, the best way to see your services and thousands details more is using Apache Felix Webconsole and then installing XRay. You might want to read my first and second blog about this bundle.




回答4:


If you are looking to just start a particular service that is already registered, but not started and would like to start it dynamically, you could get the bundle using:

Bundle bundle = Platform.getBundle("com.example.com.class");

//Then start the bundle

bundle.start();

//Check for the services references

ServiceReference<IExampleService> serviceReference = b.getBundleContext().getServiceReference(IExampleService.class);



回答5:


According to the [API docs][1] you can call getContext().getAllServiceReferences(clazz, filter) method to get a list of all services that were registered under the specified class and match the specified filter expression. Passing null on both parameters will get all services.



来源:https://stackoverflow.com/questions/11848839/is-there-a-way-to-view-registered-services-in-an-osgi-application

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!