Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[POC] Add support for Java Service Loader in the OSGi core framework
As discussed in the last spec call it would be very handy if the OSGi core framework would allow native support for Java Service Loader (SPI) without to require any special handling or metadata like ServiceLoader Mediator (SLM) that currently require bytecode weaving. It is commonly used and a constant source of problems when used inside OSGi and beside SLM there are even other workarounds like the OSGi ResourceLoader especially in JakartaEE but this requires some brittle handling in the code of the bundle itself. It is therefore the aim to actually have a simple and native integration in the OSGi core framework making use of how the SPI works and the internal knowledge of the OSGi Framework implementation that is usually not accessible to the outside. This demonstrates such implementation in the following way: - Whenever resources are requested that starts with "META-INF/services/" then it is detected by the framework - The interface/class of the SPI is extracted and loaded by the bundle, and then checked if any other bundle is currently wired to this (e.g. by import package) - For all such bundles it is checking for the same resource to be present and return them as if they where part of the same bundle - Additionally all classnames mentioned in such resources are recorded and linked to such bundle - If later a classload occurs and nothing is found in the bundle itself as a last resort it checks this mapping if a SPI class has to be loaded from the foreign bundle All this works without having both bundles to declare anything special or knwo of each other, the only connection is a compatible SPI type and the presence of the corresponding "META-INF/services/" and a SPI lookup performed.
- Loading branch information