-
-
Notifications
You must be signed in to change notification settings - Fork 76
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
Make cache2k-api and cache2k-core OSGi compatible #83
Comments
Which OSGI SPI implementation did you use? Apache Aries? |
You can find the OSGi bundle and tests used for cache2k 1.4 and 1.6 here: I didn't experiment with Aries. Maybe the bnd SPI annotations are worth a try: |
Bnd tools will just generate the manifest entries for you (Require-Capability, Provide-Capability), but you will still need a implementation for the OSGi ServiceLoader Mediator specification, which is not supported out of the box on most OSGI frameworkx (Felix, Equinox). The only implementation I know is Apache Aries Spy-Fly. This is also the reason why ServiceLoader are not very "popular" in the OSGI world, since they need additional installed bundles and trying to solve the same problems as OSGI, only worse. That's the reason why most of the people I know working with OSGI try to avoid them. I've took a quick look at the code, but since caching is not my sweet spot, I don't know if all the things are required the way they are currently implemented (e.g. ServiceLoader in static initalizer). Problem is, that some of them don't play nice with OSGI the way they current are if you really want to have api/core as own bundles (with own classloaders) |
@roggenbrot Thanks for you input!
That's not the intention. Basically, api, core, and the extensions jmx, xml, jcache, micrometer would all have the same lifetime, and are singletons.
With the service loader its possible to enable a feature automatically when the jar is present. When To play well with JPMS/JigSaw I separated config and JMX, so cache2k-core only depends on core java. The service loader is used in the static initializer for Graal support. Graal executes the static initializer during image build and saves a heap image as well. Options I see at the moment:
I think its best to wait until somebody really wants to use cache2k version 2 in their OSGi project and then see about their requirements. |
Another idea: Since the cache2k modules are more fine grain then a bundle, maybe it would be more natural that every OSGi project builds a specific cache2k bundle with the needed features. And here we would just provide a template/example for that. |
Mmmm ok. I'm not familar with Graal or AOT. But the static initializer makes a OSGI service approach more or less impossible. I've created a fork and changed the code to use services instead of service loader in OSGI environments. It's just a quick rewrite and a lot of things are missing (Thread safety, Null safety .....) and i haven't run any tests but I think it should work this way. master...roggenbrot:83-osgi-compatibility
Should it be possible for others to implement their own If this should be possible, have you ever thought about what should happen if there are more then one registered Sometimes multiple versions of the same jar/bundles are deployed in OSGI environments and imported via semantic version imports. Sometimes it's quiet handy to use a newer version of a library in one bundle without refactoring other bundles, that still depends on the old version (or without package the newer version into the jar.) So in OSGI environments it's possible to have multiple Or what about multiple implementations of I'm not familiar with |
@roggenbrot Cool, thanks for the example code!
About the separate API, you find some thoughts here: Once there is a need for different providers, we can think how to resolve conflicts. "The API finds core provider" seems pretty straight forward. Probably, the extensions get tricky.
For |
BTW: I needed to let that sit for a while. I decided now that a feature, like JMX support, needs to be enabled explicitly, which means there is no automatism when the jar is present. So I can get rid of most service loader usage in the extension jars. |
In the event of reorganizing the jar files (#80), it would make sense to have proper OSGi bundle information on the api and impl jar. The problem is that the API needs to find its implementation. I did some experiments via the SPI mediator OSGi support, but not luck.
For OSGi users
cache2k-osgi-all
was available which bundled together the API and application classes. With development of 2.0 I am dropping this, to avoid the additional jars claiming the same packages.Maybe someone with OSGi experience can take a look?
The text was updated successfully, but these errors were encountered: