You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@karaf.apache.org by Steinar Bang <sb...@dod.no> on 2023/09/12 18:50:12 UTC

Re: Need help with and (OSGi-fication of TwelweMonkeys)

An update on this thread:
 1. I have created a github issue for TwelveMonkeys for making
    TwelveMonkeys be an OSGi bundle
     https://github.com/haraldk/TwelveMonkeys/issues/794
 2. I have created a fork of TwelveMonkeys
     https://github.com/steinarb/TwelveMonkeys
 3. I have created a branch on my fork of TwelveMonkeys, where I have
     https://github.com/steinarb/TwelveMonkeys/tree/make-jar-files-be-osgi-bundles
    a. Added an maven-bundle-plugin config in the <pluginManagement>
        https://github.com/steinarb/TwelveMonkeys/blob/aef177031eaf2d4193c11628a2acb33e00a055c9/pom.xml#L221
    b. Added Import-Package and Export-Package headers to the MANIFEST.MF
       of all jar files, and made the jar files into OSGi bundles
        https://github.com/steinarb/TwelveMonkeys/commit/aef177031eaf2d4193c11628a2acb33e00a055c9
    c. Added <Provide-Capability> and <Require-Capability> to one of the
       TwelveMonkeys imageio plugins
        https://github.com/steinarb/TwelveMonkeys/blob/10cd149662e2ec4a051202bf9d6370d81ca9c8c8/imageio/imageio-jpeg/pom.xml#L38
 4. I have created a test application that has a rudimentary react GUI
    that lets you updload a JPEG URL and that image is downloaded into
    the backend and the comment, if any, is extracted using imageio
     https://github.com/steinarb/twelvemonkeys-karaf-demo
 5. Instructions for how to build and run twelvemonkeys-karaf-demo in
    the README
 6. I have created a branch on that application where I'm trying to use
    SPI from Aries SPI-fly to inject twelvemonkeys imageio into imageio
    (so far without luck)
     https://github.com/steinarb/twelvemonkeys-karaf-demo/tree/use-twelvemonkeys-imageio



Re: Need help with and (OSGi-fication of TwelweMonkeys)

Posted by Steinar Bang <sb...@dod.no>.
>>>>> Steinar Bang <sb...@dod.no>:

> I now have some success: I created a DS component that listens for the
> OSGi services created by Aries spyfly, from the Twelvemonkeys SPI
> services, and registers the injected services with the imageio
> ServiceRegistry. 
[snip!]
> But since the spifly docs say: "Additionally services found in META-INF/services are registered in the OSGi Service Registry."
> I decided to try a DS component that injects all Twelvemonkeys SPI
> services as OSGi services and use them to register the service in the
> imageio service registry:
>  https://github.com/steinarb/twelvemonkeys-karaf-demo/blob/master/src/main/java/no/priv/bang/demos/frontendkarafdemo/ImageioSpiRegistration.java#L12

I would very much like some feedback/comments on this approach.

E.g. is this a misuse of @Component, since it doesn't expose a service,
it never really goes active, but just exists to capture ImageIO SPI
services in the OSGi registry, and pass the services on to the ImageIO
ServiceRegistry?

Is there some SPIfly way that would have worked without creating a
component? (I couldn't find any from looking at the Spifly source code)

And should the @Component have some different annotations or annotation
parameters than the ones I've used?

And what about unregistrations and SPI lifecycle managment? Can an
osgi.serviceloader capability be unloaded? And does that unloading mean
that it should be unregistered from the ImageIO ServiceRegistry?

Thanks!


- Steinar


Re: Need help with and (OSGi-fication of TwelweMonkeys)

Posted by Steinar Bang <sb...@dod.no>.
>>>>> Steinar Bang <sb...@dod.no>:

> Aries Spifly was logging very little, so it was hard to debug.
> Figuring out where the log level should be upped, turned out to be
> surprisingly easy, however...
>  https://github.com/apache/karaf/blob/main/assemblies/features/base/src/main/resources/resources/etc/org.ops4j.pax.logging.cfg#L51

I now have some success: I created a DS component that listens for the
OSGi services created by Aries spyfly, from the Twelvemonkeys SPI
services, and registers the injected services with the imageio
ServiceRegistry. 

The full strory follows:

Logging told me that the SPI services were found by spifly:
 https://gist.github.com/steinarb/6dd2b87cca74f483c560abd3f05868e2#file-karaf-log-L408

However imageio still picked the built-in com.sun.imageio.plugins.jpeg.JPEGImageReader
to read a JPEG (JFIF) file:
 https://gist.github.com/steinarb/6dd2b87cca74f483c560abd3f05868e2#file-karaf-log-L478

It turns out there is no magic in Aries Spifly that makes it find the
SPI registry that listens for SPI services and register the service
there.

I tried using the Spifly-specific MANIFEST.MF header SPI-Consumer to
specify a class and method to consume the SPI services.
 https://aries.apache.org/documentation/modules/spi-fly.html#specificconf

But I would need to go via two method calls to get to the one I need, ie.
 IIORegistry.getDefaultInstance().registerServiceProvider(service);

I tried doing it like this, but that didn't work
 SPI-Consumer: javax.imageio.spi.IIORegistry#getDefaultInstance#registerServiceProvider
and, not surprising, because I think the Spifly SPI-Consumer code only
provides for calling a method on a class.

If there had been a static method that could be called to register an
imageio service I think maybe the SPI-Consumer MANIFEST.MF header would
have worked...?

But since the spifly docs say: "Additionally services found in META-INF/services are registered in the OSGi Service Registry."
I decided to try a DS component that injects all Twelvemonkeys SPI
services as OSGi services and use them to register the service in the
imageio service registry:
 https://github.com/steinarb/twelvemonkeys-karaf-demo/blob/master/src/main/java/no/priv/bang/demos/frontendkarafdemo/ImageioSpiRegistration.java#L12

And that worked. https://gist.github.com/steinarb/abb91df9447d00f73963f366fcc01771#file-karaf-log-L491

I don't know if this is the correct way to do imageio SPI service
registration, but it worked, so this is what I'm rolling with for now.


Re: Need help with and (OSGi-fication of TwelweMonkeys)

Posted by Steinar Bang <sb...@dod.no>.
Aries Spifly was logging very little, so it was hard to debug.

Figuring out where the log level should be upped, turned out to be
surprisingly easy, however...
 https://github.com/apache/karaf/blob/main/assemblies/features/base/src/main/resources/resources/etc/org.ops4j.pax.logging.cfg#L51

So thanks to JB and Grzegorz and the rest of the karaf team for making
things this easy! :-)