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

[OSGi] Opting in to Service Loader Mediator #1568

Open
fipro78 opened this issue Mar 27, 2024 · 3 comments
Open

[OSGi] Opting in to Service Loader Mediator #1568

fipro78 opened this issue Mar 27, 2024 · 3 comments

Comments

@fipro78
Copy link
Contributor

fipro78 commented Mar 27, 2024

The design of Eclipse Collections is to have the API and the implementation in separate bundles. Internally the Java ServiceLoader API is used. This means the API uses Services that are provided by the implementation. The ServiceLoader API by default only works if consumer and provider are using the same classloader. Therefore it does not work in an OSGi context.

To make Eclipse Collections work in an OSGi context like Eclipse, an additional artifact is created and published via p2 update site, which combines API and IMPL in a single bundle, which solves the ServiceLoader classloader issue.

For a while now it is possible to consume dependencies directly from Maven in an Eclipse Target Platform. Also there are OSGi projects that are not based on Eclipse, that might want to consume Eclipse Collections but can't use a p2 update site.

If you try to use Eclipse Collections API and Implementation from Maven in an OSGi project, you will see the following exception at runtime:

java.lang.IllegalStateException: Could not find any implementations of MutableListFactory. Check that eclipse-collections.jar is on the classpath and that its META-INF/services directory is intact.

It is possible to use Eclipse Collections API and IMPL from Maven in an OSGi project, if the Service Loader Mediator is used. You then need to add for example SPI Fly to the runtime, which is the reference implementation of the Service Loader Mediator Specification.

To make it work, the API and the IMPL bundles need to be registered to be processed by the Service Loader Mediator. With the current setup this can only be done by setting system properties, e.g. the following setting in a .bndrun file:

-runproperties: \
    org.apache.aries.spifly.auto.consumers=org.eclipse.collections.api,\
    org.apache.aries.spifly.auto.providers=org.eclipse.collections.impl

To avoid additional configurations for the runtime, the bundles could also opting in by requiring the Service Loader Mediator in the manifest.

The API needs:

Require-Capability:                                         
  osgi.extender;
    filter:="(&(osgi.extender=osgi.serviceloader.processor)
             (version>=1.0)(!(version>=2.0)))"

The IMPL needs:

Require-Capability:                                         
    osgi.extender; 
        filter:="(&(osgi.extender=osgi.serviceloader.registrar)
                 (version>=1.0)(!(version>=2.0)))"
fipro78 pushed a commit to fipro78/eclipse-collections that referenced this issue Mar 27, 2024
fipro78 added a commit to fipro78/eclipse-collections that referenced this issue Mar 27, 2024
fipro78 added a commit to fipro78/eclipse-collections that referenced this issue Mar 27, 2024
Switched back to Automatic-Module-Name to fix only one topic at a time
fipro78 added a commit to fipro78/eclipse-collections that referenced this issue Apr 4, 2024
fipro78 added a commit to fipro78/eclipse-collections that referenced this issue Apr 4, 2024
fipro78 added a commit to fipro78/eclipse-collections that referenced this issue Apr 4, 2024
@kavyabala23
Copy link

Hi, may I work on this issue?

@fipro78
Copy link
Contributor Author

fipro78 commented Apr 18, 2024

I have already provided a PR for this issue. Not sure what you want to do now.

@kavyabala23
Copy link

Oh ok, please let me know if you find out.

fipro78 added a commit to fipro78/eclipse-collections that referenced this issue May 23, 2024
fipro78 added a commit to fipro78/eclipse-collections that referenced this issue May 23, 2024
fipro78 added a commit to fipro78/eclipse-collections that referenced this issue May 23, 2024
fipro78 added a commit to fipro78/eclipse-collections that referenced this issue May 23, 2024
fipro78 added a commit to fipro78/eclipse-collections that referenced this issue May 23, 2024
fipro78 added a commit to fipro78/eclipse-collections that referenced this issue May 24, 2024
fipro78 added a commit to fipro78/eclipse-collections that referenced this issue May 24, 2024
fipro78 added a commit to fipro78/eclipse-collections that referenced this issue May 24, 2024
fipro78 added a commit to fipro78/eclipse-collections that referenced this issue May 24, 2024
fipro78 added a commit to fipro78/eclipse-collections that referenced this issue May 24, 2024
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

2 participants