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] Solutions for https://github.com/eclipse/microprofile/issues/33 #265

Closed
wants to merge 1 commit into from

Conversation

rotty3000
Copy link

@rotty3000 rotty3000 commented Aug 30, 2018

@arthurdm
Copy link
Member

@rotty3000 - is there a change needed to OASFactoryResolver at all?

@arthurdm
Copy link
Member

hey @tjwatson and @Emily-Jiang - can you please help me review this PR? I am not really sure what it does =)

@tjwatson
Copy link
Member

@Emily-Jiang I need to discuss this with you. We consume the micro-profile jars into OpenLiberty (which has an OSGi based runtime) but I am pretty sure we do not want to require the osgi.serviceloader usage in OpenLiberty do we?

@tjwatson
Copy link
Member

Especially since we do setup a TCCL which the ServiceLoader would use to lookup services and would probably want to continue that behavior, while the osgi.serviceloader will do some weaving tricks to change the call sights of the ServiceLoader.load calls to do something with OSGi services.

@rotty3000
Copy link
Author

rotty3000 commented Oct 22, 2018 via email

@rotty3000
Copy link
Author

rotty3000 commented Oct 22, 2018 via email

@tjwatson
Copy link
Member

That does sound broken, but also unrelated to this PR. I assume you have a separate issue about proper import ranges?

@tjwatson
Copy link
Member

Service loader mediator is an OSGi spec which open Liberty could implement any way they like. Are you suggesting that everyone else suffer for Open Liberty's implementation details?

Not at all, I'm having an open discussion about the additional requirements this dependency on an OSGi specification will have on MicroProfile (while trying not to be dramatic with all the suffering that will occur :)

@rotty3000
Copy link
Author

rotty3000 commented Oct 23, 2018 via email

@rotty3000
Copy link
Author

Specifically related to Service Loader Mediator, MicroProfile APIs would only be enhanced by following a standard specifically designed for adapting the use of ServiceLoader in OSGi as opposed to leaving it unaddressed, essentially forcing consumers to fork the artifact which has further negative ramifications on the perception of OSGi.

@tjwatson
Copy link
Member

This IS related to this PR in that I've attempted to correct package import versions in all the linked PRs as part of the effort to make them good OSGi citizens.

OK, but this particular PR does not address the import issues. I want avoid conflating the import resolution issue with the service loader mediator discussion.

Specifically related to Service Loader Mediator, MicroProfile APIs would only be enhanced by following a standard specifically designed for adapting the use of ServiceLoader in OSGi as opposed to leaving it unaddressed, essentially forcing consumers to fork the artifact which has further negative ramifications on the perception of OSGi.

I should mention that up to now I have not really touched the MicroProfile implementation nor the specification (I'm not a committer of the project at Eclipse). If others with more concrete knowledge of the MicroProfile project agree that the approach of adding a hard dependency on the service loader mediator is the way to go for the spec'ed JARs then I am fine with that. I only can advise some caution here because I have been bitten in the past by libraries putting a hard dependency on service loader mediator. Ray, you should be familiar with such a case in Jetty, there is a part of Jetty that needs the mediator to function, but the Jetty bundles can live without the functionality. At least that is true for the use of Jetty by the Eclipse platform for the Http Service implementation. It seems each time we update Jetty versions for the Eclipse Platform we have to deal with another of these hard dependencies that really should be viewed as optional (but I know how your feel about optional requirements also).

I'm not even sure how the OSGI based runtimes that implement MicroProfile deal with these ServiceLoader calls. I had assumed MicroProfile defines a behavior for the TCCL and that makes it just work without the need for the mediator. But we really need the input from the likes of @Emily-Jiang or others to provide input on that.

@rotty3000
Copy link
Author

rotty3000 commented Oct 23, 2018

.. and I'm not just here to be a hard case unwilling to compromise. But each issue I've brought up is a real concern for any OSGi consumer. Personally I feel that the only way that Open Libery could possibly be using these things is by passing them through the system bundle as extra package exports, and doing the wiring to the provider manually. That, or they force bundle start ordering in order to wire the provider before any consumer touches the API which is the most likely scenario based on this code reference

https://github.com/eclipse/microprofile-config/blob/master/api/src/main/java/org/eclipse/microprofile/config/spi/ConfigProviderResolver.java#L166-L175

which I have to say... it's less than ideal. This effectively is a race condition between consumers and providers.

@rotty3000
Copy link
Author

I should add that Service Loader Mediator can totally handle the ordering issue by making sure it doesn't let the provider or consumer resolve (the required capabilities on either side) until it has performed whatever it needs to do. In fact Aries SpiFly actually provides a Framework Extension [1] fragment (which has no external dependencies) specifically designed to eliminate any start ordering concern between providers and consumers.

Furthermore, I am waving away the fact that microprofile-config's usage of ServiceLoader is not compatible with SpiFly at this time. but that's an entirely different issue that is a defect we need to address on the SpiFly side.

[1] https://search.maven.org/artifact/org.apache.aries.spifly/org.apache.aries.spifly.dynamic.framework.extension/1.0.14/bundle

@tjwatson
Copy link
Member

.. and I'm not just here to be a hard case unwilling to compromise. But each issue I've brought up is a real concern for any OSGi consumer. Personally I feel that the only way that Open Libery could possibly be using these things is by passing them through the system bundle as extra package exports, and doing the wiring to the impl manually. That, or they force bundle start ordering in order to wire the impl before any consumer touches the API which is the most likely scenario based on this code reference

https://github.com/eclipse/microprofile-config/blob/master/api/src/main/java/org/eclipse/microprofile/config/spi/ConfigProviderResolver.java#L166-L175

which I have to say... it's less than ideal. This effectively is a race condition between consumers and providers.

Will the proposal to only use service loader mediator for the SPI implementation load also include the removal of this setter method? If the use of service loader mediator is mandatory then this method is not really very useful since the bundle will never resolve without the mediator implementation. I can see this being a race condition for applications that are also based on OSGi and the application bundles live in the same space as the implementation and there is no control over application bundles activating in the mix of the implementation bundles. I imagine that is not the case for implementations of MicroProfile today where they likely have strict control over when application code will start to be executed. But at this point I am only guessing. Will need others to provide input.

@rotty3000
Copy link
Author

So after discussing this use case with others I think I've come up with a compromise; a weak SLM requirement.

A weak requirement allows:

  • build time resolving works; finds an implementation of SLM and a provider when a consumer is part of the requirements (whether initial or transitive)
  • optional at run time, so that if you didn't use a resolver to assemble AND you don't have SML implementation at runtime the bundles still resolve
  • run time wires are created because proper wiring of requirements at run time is essential

This is implemented by specifying the same requirement twice; once as effective:=active (for build resolving) and the other as resolution:=optional (for non-mandatory run-time resolving)

e.g.

    osgi.serviceloader;\
        filter:="(osgi.serviceloader=org.eclipse.microprofile.config.spi.ConfigProviderResolver)";\
        cardinality:=multiple;\
        resolution:=optional,\
    osgi.serviceloader;\
        filter:="(osgi.serviceloader=org.eclipse.microprofile.config.spi.ConfigProviderResolver)";\
        cardinality:=multiple;\
        effective:=active,\
    osgi.extender;\
        filter:="(osgi.extender=osgi.serviceloader.processor)";\
        resolution:=optional,\
    osgi.extender;\
        filter:="(osgi.extender=osgi.serviceloader.processor)",\
        effective:=active

OR since R7 + bnd-maven-plugin 4.1.0 using the bundle annotations which I can provide an example for in a bit.

@tjwatson
Copy link
Member

This approach seems reasonable to me.

@rotty3000
Copy link
Author

@tjwatson, how do you feel about stripping the versions off of the non-semantically versioned package imports and adding the appropriate portable java contract in their place? Again, the requirements could be made weak for the same reason as above.

@eclipse-microprofile-bot
Copy link
Contributor

Can one of the admins verify this patch?

@arthurdm
Copy link
Member

The umbrella MP issue (eclipse/microprofile#33) where this PR originated from was closed as won't do, so I am inclined to close this PR.

@jmini / @EricWittmann - any objections?

@rotty3000 rotty3000 closed this Mar 27, 2019
Azquelt pushed a commit to Azquelt/microprofile-open-api that referenced this pull request Mar 17, 2022
Azquelt pushed a commit to Azquelt/microprofile-open-api that referenced this pull request Mar 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants