Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide an OSGi standard way to enumerate ServiceLoader with FrameworkUtil #685

Open
laeubi opened this issue Feb 29, 2024 · 0 comments
Open

Comments

@laeubi
Copy link
Contributor

laeubi commented Feb 29, 2024

Currently there is not really an easy / convenient way to simply enumerate all service providers of all bundles, and as we all know this is maybe even bad and one should better use Service, DI and all kind of cool OSGi stuff.

On the other hand as a matter of fact there are uses of ServiceLoader around that will likely never migrate (most prominent JakartaEE) and technologies like ServiceLoader Mediator have there shortcomings as they require special configuration, care and knowledge of users (also know as "OSGi is to complex for us").

In JakartaEE on the other hand they are trying really hard to support all different kind of things (not only OSGi specific) and one think is they use (indirectly) a special bundle the osgi-resource-locator what has ResourceFinderImpl and a ServiceLoaderImpl that the simply scan all bundles for resources and classes.

This then is used inServiceLoader#lookupProviderInstances

I think it would be good do have something official in OSGi for such use case, that works the following

  • There is some static method e.g. FrameworkUtil#lookupProviderInstances
  • If running inside an OSGi Framework (e.g. getBundle of the caller return non null or using the bundle of the framework util) it performs a lookup in all active bundles
  • If not running inside OSGi it delegates to the default java meachnism

That way one would have some very low barrier way for mixed users to tell them to use this method and it will work inside OSGi and outside with just a small additional jar (osgi-core) and internally it can do what ever is the best for OSGi, no runtime classweaving or static weaving required, no "magic" osgiresourcelocator that is called by reflections and so on and no configuration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant