My Java based project is currently running in an OSGi container, where other projects register their OSGi services for others to use. If I know a service is currently registered, I can simply query, with the 'BundleContext' builtin method:
getContext().getServiceReference(LogService.class.getName());
However, I'd like to be able to query for all OSGi services registered in the context at that moment. I've looked into the available methods for BundleContext
, but could not find anything there that would suit my needs. I am not looking to actual use the list of registered services to use the service object, but simply obtain the names of the registered services; I do not believe this would violate OSGi principles.
EDIT: I am not using Eclipse or Equinox in my dev environment.
EDIT: If accessing the OSGi services is not possible, or not recommended, with Java, I'd be open to just looking at the registered services via command line if that is possible.
According to the API docs you can call getAllServiceReferences(null, null)
method to get a list of all services:
getAllServiceReferences
ServiceReference<?>[] getAllServiceReferences(java.lang.String clazz,
java.lang.String filter)
throws InvalidSyntaxException
Returns an array of ServiceReference objects. The returned array of ServiceReference objects contains services that were registered under the specified class and match the specified filter expression.
Parameters:
- clazz - The class name with which the service was registered or null for all services.
- filter - The filter expression or null for all services.