Re: Vertx SPI

2024-03-30 Thread Steinar Bang
> Steinar Bang :

> Michael Elbaz :

> Note that if you are piggy-backing karaf feature generation on your OSGi
> bundles, then you can add feature run time dependencies like the one
> about, by adding it as a compile scope (the default) maven dependency in
> the pom.

> (provided and test dependencies aren't
> added to the karaf feature)

I.e instead of having a provided in the pom and a
mvn: URL in the feature, just use compile (or no 
at all) and the mvn: URL will be generated.

(SPI-Fly isn't one you need at compile time so probably a bad example...?)




Re: Vertx SPI

2024-03-30 Thread Steinar Bang
> Michael Elbaz :

> Ok i finally made this work ! (was so paintfull) Thanks for the help !
> what i was missed is installing this one =>
> mvn:org.apache.aries.spifly/org.apache.aries.spifly.dynamic.bundle/1.3.7

Glad you got it working!

Note that if you are piggy-backing karaf feature generation on your OSGi
bundles, then you can add feature run time dependencies like the one
about, by adding it as a compile scope (the default) maven dependency in
the pom.

(provided and test dependencies aren't
added to the karaf feature)



Re: Vertx SPI

2024-03-27 Thread Michael Elbaz

Ok i finally made this work ! (was so paintfull) Thanks for the help !

what i was missed is installing this one => 
mvn:org.apache.aries.spifly/org.apache.aries.spifly.dynamic.bundle/1.3.7


Le 26/03/2024 à 21:17, Steinar Bang a écrit :

Cesar Garcia :

Hello,
Definitely for that problem it helps:
https://aries.apache.org/documentation/modules/spi-fly.html
You must clearly define in your poms which export services with
"SPI-Provider: *" or import services with "SPI-Consumer: *", this is done
in your pom.xml file.

Ah! Yes, of course!

This is my PR to TwelveMonkeys:
  https://github.com/haraldk/TwelveMonkeys/pull/814
with the following correction:
  https://github.com/haraldk/TwelveMonkeys/pull/856

Anyway: what the PR does is to make the jars be OSGi bundle and add
Provide-Capability headers to all bundles exposing SPI services.

These services are then picked up and instantiated by SPI-Fly (and made
into OSGi services in the service registry).

So you need to do the same thing to the jar files providing hash code
plugins.

Sorry, I forgot!





Re: Vertx SPI

2024-03-26 Thread Michael Elbaz

The producer Bundle A pom build




org.apache.felix
maven-bundle-plugin
5.1.9
true



${project.artifactId}
${project.version}

javax.net*,
javax.security*,
javax.crypto*,


io.vertx.*,
io.reactivex.*,
io.netty.*,
org.reactivestreams.*,
org.apache.qpid.*,
com.fasterxml.*,

  
  
 <_exportcontents/>



*;scope=compile;inline=false
*

osgi.serviceloader;
osgi.serviceloader=io.vertx.ext.auth.HashingAlgorithm







The consumer Bundle B pom build




org.apache.felix
maven-bundle-plugin
5.1.9
true


*








Le 26/03/2024 à 21:12, Cesar Garcia a écrit :

Hello,

It could be something like this

The Producer, Bundle A

             
                 org.apache.felix
 maven-bundle-plugin
                 5.1.9
                 true
                 
                     
 ${project.artifactId}
 ${project.version}
 
com.ceos.grpc.server*;version=${project.version}
 *
* **
                     
                 
             

The consumer, Bundle B

             
                 org.apache.felix
 maven-bundle-plugin
                 5.1.9
                 true
                 
                     
 ${project.artifactId}
 ${project.version}
 
com.ceos.grpc.client*;version=${project.version}
*                         
 org.apache.karaf.shell*;version="[4,5)",
                             *
                         
 **
 com.ceos.grpc.client.command
                     
                 
             

In this case, Bundle B consumes all the services exported by Bundle A 
using SPI-Fly.


If you still have problems, you can indicate in the pom that all 
internal packages are exported. After compilation you should be able 
to see it in the MANIFEST-INF.


I hope it helps in something,

Kind regards,

El mar, 26 mar 2024 a las 15:21, Michael Elbaz 
() escribió:


Hello Achim Hello Cesar,

It's little bit more tricky i have two bundle jar the first one is
just a bundle with all vertx thing inside, that export vertx
package to Karaf
And the second bundle is simple regular OSGI bundle wich call some
vertx http server, so the point is inside the vertx bundle there
is one dependencie (transitive dependencie) vertx-auth-common
that do some SPI and another one that try to use this class so
eveything happen in this jar/bundle (the vertx one) i don't
understand in this case if the TCCL is in my second jar ? and if
not how i need to do to allow vertx discovering this SPI classes ?
(i off course can't modifie the transitive jar dependencies)

Thanks :)

Le 26/03/2024 à 14:07, Cesar Garcia a écrit :

Hello,

Definitely for that problem it helps:

https://aries.apache.org/documentation/modules/spi-fly.html

You must clearly define in your poms which export services with
"SPI-Provider: *" or import services with "SPI-Consumer: *", this
is done in your pom.xml file.

My grain of sand,

Greetings

El mar, 26 mar 2024 a las 6:48, Michael Elbaz
() escribió:

Hello i use vertx (wraping as a bundle) inside karaf i'm
facing a
problem because vertx-auth-common use SPI mecanism internally
to load
some classes

(https://github.com/eclipse-vertx/vertx-auth/blob/4.5.6/vertx-auth-common/src/main/resources/META-INF/services/io.vertx.ext.auth.HashingAlgorithm)

internally is use ServiceLoader.load but during runtime the
classes are
not found is probably related to TCCL, i was trying apache
aries Spy Fly
stuff with no success how i need to do this working thanks



-- 
*CEOS Automatización, C.A.*

*GALPON SERVICIO INDUSTRIALES Y NAVALES FA, C.A.,*
*PISO 1, OFICINA 2, AV. RAUL LEONI, SECTOR GUAMACHITO,*
*FRENTE A LA ASOCIACION DE GANADEROS,BARCELONA,EDO. ANZOATEGUI
*
*Ing. César García*
*Cel: +58 414-760.98.95
*
*Hotline Técnica SIEMENS: 0800 1005080
*
*Email: support.aan.automat...@siemens.com
*





--
*CEOS Automatización, C.A.*
*GALPON SERVICIO INDUSTRIALES Y NAVALES FA, C.A.,*
*PISO 1, OFICINA 2, AV. RAUL LEONI, SECTOR GUAMACHITO,*
*FRENTE A LA ASOCIACION DE GANADEROS,BARCELONA,EDO. ANZOATEGUI
*
*Ing. César 

Re: Vertx SPI

2024-03-26 Thread Steinar Bang
> Cesar Garcia :

> Hello,
> Definitely for that problem it helps:

> https://aries.apache.org/documentation/modules/spi-fly.html

> You must clearly define in your poms which export services with
> "SPI-Provider: *" or import services with "SPI-Consumer: *", this is done
> in your pom.xml file.

Ah! Yes, of course!

This is my PR to TwelveMonkeys:
 https://github.com/haraldk/TwelveMonkeys/pull/814
with the following correction:
 https://github.com/haraldk/TwelveMonkeys/pull/856

Anyway: what the PR does is to make the jars be OSGi bundle and add
Provide-Capability headers to all bundles exposing SPI services.

These services are then picked up and instantiated by SPI-Fly (and made
into OSGi services in the service registry).

So you need to do the same thing to the jar files providing hash code
plugins.

Sorry, I forgot!



Re: Vertx SPI

2024-03-26 Thread Michael Elbaz

Hello Achim Hello Cesar,

It's little bit more tricky i have two bundle jar the first one is just 
a bundle with all vertx thing inside, that export vertx package to Karaf
And the second bundle is simple regular OSGI bundle wich call some vertx 
http server, so the point is inside the vertx bundle there is one 
dependencie (transitive dependencie) vertx-auth-common
that do some SPI and another one that try to use this class so eveything 
happen in this jar/bundle (the vertx one) i don't understand in this 
case if the TCCL is in my second jar ? and if not how i need to do to 
allow vertx discovering this SPI classes ? (i off course can't modifie 
the transitive jar dependencies)


Thanks :)

Le 26/03/2024 à 14:07, Cesar Garcia a écrit :

Hello,

Definitely for that problem it helps:

https://aries.apache.org/documentation/modules/spi-fly.html

You must clearly define in your poms which export services with 
"SPI-Provider: *" or import services with "SPI-Consumer: *", this is 
done in your pom.xml file.


My grain of sand,

Greetings

El mar, 26 mar 2024 a las 6:48, Michael Elbaz 
() escribió:


Hello i use vertx (wraping as a bundle) inside karaf i'm facing a
problem because vertx-auth-common use SPI mecanism internally to load
some classes

(https://github.com/eclipse-vertx/vertx-auth/blob/4.5.6/vertx-auth-common/src/main/resources/META-INF/services/io.vertx.ext.auth.HashingAlgorithm)

internally is use ServiceLoader.load but during runtime the
classes are
not found is probably related to TCCL, i was trying apache aries
Spy Fly
stuff with no success how i need to do this working thanks



--
*CEOS Automatización, C.A.*
*GALPON SERVICIO INDUSTRIALES Y NAVALES FA, C.A.,*
*PISO 1, OFICINA 2, AV. RAUL LEONI, SECTOR GUAMACHITO,*
*FRENTE A LA ASOCIACION DE GANADEROS,BARCELONA,EDO. ANZOATEGUI
*
*Ing. César García*
*Cel: +58 414-760.98.95
*
*Hotline Técnica SIEMENS: 0800 1005080
*
*Email: support.aan.automat...@siemens.com
*



Re: Vertx SPI

2024-03-26 Thread Cesar Garcia
Hello,

Definitely for that problem it helps:

https://aries.apache.org/documentation/modules/spi-fly.html

You must clearly define in your poms which export services with
"SPI-Provider: *" or import services with "SPI-Consumer: *", this is done
in your pom.xml file.

My grain of sand,

Greetings

El mar, 26 mar 2024 a las 6:48, Michael Elbaz ()
escribió:

> Hello i use vertx (wraping as a bundle) inside karaf i'm facing a
> problem because vertx-auth-common use SPI mecanism internally to load
> some classes
> (
> https://github.com/eclipse-vertx/vertx-auth/blob/4.5.6/vertx-auth-common/src/main/resources/META-INF/services/io.vertx.ext.auth.HashingAlgorithm)
>
> internally is use ServiceLoader.load but during runtime the classes are
> not found is probably related to TCCL, i was trying apache aries Spy Fly
> stuff with no success how i need to do this working thanks
>


-- 
*CEOS Automatización, C.A.*
*GALPON SERVICIO INDUSTRIALES Y NAVALES FA, C.A.,*
*PISO 1, OFICINA 2, AV. RAUL LEONI, SECTOR GUAMACHITO,*

*FRENTE A LA ASOCIACION DE GANADEROS,BARCELONA,EDO. ANZOATEGUI*
*Ing. César García*

*Cel: +58 414-760.98.95*

*Hotline Técnica SIEMENS: 0800 1005080*

*Email: support.aan.automat...@siemens.com
*


Re: Vertx SPI

2024-03-26 Thread Achim Nierbeck
Hi Michael,

it's been quite a while since I've been playing around with karaf and
vert.x from principle it should still work though.
Maybe you find some help here:
https://github.com/ANierbeck/Karaf-Vertx/tree/master

I also used the spi-fly bundle to have some SPI stuff working.
https://github.com/ANierbeck/Karaf-Vertx/blob/master/Vertx-Feature/src/main/feature/feature.xml

maybe it will point you into the right direction, it's not with the latest
version.

regards, Achim


Am Di., 26. März 2024 um 12:46 Uhr schrieb Michael Elbaz <
michaelel...@outlook.fr>:

> First i do that:
>
>  bundle:install -s
> mvn:org.apache.aries.spifly/org.apache.aries.spifly.dynamic.bundle/1.3.7
>
> 
> *
> 
> osgi.extender; filter:="(osgi.extender=osgi.serviceloader.processor)",
> osgi.serviceloader; 
> filter:="(osgi.serviceloader=io.vertx.ext.auth.HashingAlgorithm)";
> cardinality:=multiple,
> 
> 
>
> but this is not working, but even if i register a DS service the
> java.util.ServiceLoader#load(java.lang.Class) will be able to find this
> service ? (i think it was my first no success try) or maybe i don't
> understand you
>
> Le 26/03/2024 à 12:39, Steinar Bang a écrit :
>
> Michael Elbaz  :
>
> Thanks answering me but still not working i didn't even have a clue of
> wich bundle need to be modified the one from wich the code is called i
> suppose any other proposition ?
>
> Well I don't know vertex-auth-common, but I think it is likely that it
> has some sort of service registry, i.e. some class with a static method
> or something that registers the services?
>
> If so, then you can try a variant of my TwelveMonkeys trick, which is:
>  1. Use SPI-fly to load the services for the hashers you want to use
>  2. Create a DS component that gathers the services and registers them
> with vertex-auth-common's service registry
>
> This will be a little more complex than ImageIO, since ImageIO is part
> of the Java runtime, and vertex-auth-common (probably) isn't.
>
> But it should work if vertex-auth-common is an OSGi bundle that exports
> the package containing the service registry.
>
> Then you can just use that registry where you need it and (hopefully)
> the class should be found
>
> (Note the "hopefully" part above...:-) )
>
>
>
>

-- 

Apache Member
Apache Karaf  Committer & PMC
OPS4J Pax Web  Committer &
Project Lead
blog 
Co-Author of Apache Karaf Cookbook 


Re: Vertx SPI

2024-03-26 Thread Michael Elbaz

First i do that:

 bundle:install -s 
mvn:org.apache.aries.spifly/org.apache.aries.spifly.dynamic.bundle/1.3.7



*

osgi.extender; filter:="(osgi.extender=osgi.serviceloader.processor)",
osgi.serviceloader; 
filter:="(osgi.serviceloader=io.vertx.ext.auth.HashingAlgorithm)";
cardinality:=multiple,



but this is not working, but even if i register a DS service the 
java.util.ServiceLoader#load(java.lang.Class) will be able to find 
this service ? (i think it was my first no success try) or maybe i don't 
understand you


Le 26/03/2024 à 12:39, Steinar Bang a écrit :

Michael Elbaz:

Thanks answering me but still not working i didn't even have a clue of
wich bundle need to be modified the one from wich the code is called i
suppose any other proposition ?

Well I don't know vertex-auth-common, but I think it is likely that it
has some sort of service registry, i.e. some class with a static method
or something that registers the services?

If so, then you can try a variant of my TwelveMonkeys trick, which is:
  1. Use SPI-fly to load the services for the hashers you want to use
  2. Create a DS component that gathers the services and registers them
 with vertex-auth-common's service registry

This will be a little more complex than ImageIO, since ImageIO is part
of the Java runtime, and vertex-auth-common (probably) isn't.

But it should work if vertex-auth-common is an OSGi bundle that exports
the package containing the service registry.

Then you can just use that registry where you need it and (hopefully)
the class should be found

(Note the "hopefully" part above...:-) )



Re: Vertx SPI

2024-03-26 Thread Steinar Bang
> Michael Elbaz :

> Thanks answering me but still not working i didn't even have a clue of
> wich bundle need to be modified the one from wich the code is called i
> suppose any other proposition ?

Well I don't know vertex-auth-common, but I think it is likely that it
has some sort of service registry, i.e. some class with a static method
or something that registers the services?

If so, then you can try a variant of my TwelveMonkeys trick, which is:
 1. Use SPI-fly to load the services for the hashers you want to use
 2. Create a DS component that gathers the services and registers them
with vertex-auth-common's service registry

This will be a little more complex than ImageIO, since ImageIO is part
of the Java runtime, and vertex-auth-common (probably) isn't.

But it should work if vertex-auth-common is an OSGi bundle that exports
the package containing the service registry.

Then you can just use that registry where you need it and (hopefully)
the class should be found

(Note the "hopefully" part above...:-) )



Re: Vertx SPI

2024-03-26 Thread Michael Elbaz
Thanks answering me but still not working i didn't even have a clue of 
wich bundle need to be modified the one from wich the code is called i 
suppose any other proposition ?


Le 26/03/2024 à 12:07, Steinar Bang a écrit :

Michael Elbaz :

Hello i use vertx (wraping as a bundle) inside karaf i'm facing a
problem because vertx-auth-common use SPI mecanism internally to load
some classes
(https://github.com/eclipse-vertx/vertx-auth/blob/4.5.6/vertx-auth-common/src/main/resources/META-INF/services/io.vertx.ext.auth.HashingAlgorithm)
internally is use ServiceLoader.load but during runtime the classes
are not found is probably related to TCCL, i was trying apache aries
Spy Fly stuff with no success how i need to do this working thanks

FWIW SPI-fly and SPI is something I've used, but it is a place where
I've never been quite clear about why and how it works.

One place I use it is with my Liquibase karaf feature
  
https://github.com/steinarb/liquibase-karaf-feature?tab=readme-ov-file#using-liquibase-from-osgi-bundles

Requiring services only needs to be done once for each karaf instance
(i.e. once for each Java VM running), I think...? Maybe...?

The requirements haven't been consistent across the applications using
liquibase even though they are very similar..

Another place I've used it is when using the TwelveMonkeys Image
manipulation library, which plugs into the SPI-based ImageIO support of
the Java runtime.

Here I used a DS (Declarative Services) component to load TwelveMonkeys
and catch the TwelveMonkeys services and register them with ImageIO.
  
https://github.com/steinarb/oldalbum/blob/master/oldalbum.backend.imageio/pom.xml#L115
  
https://github.com/steinarb/oldalbum/blob/master/oldalbum.backend.imageio/src/main/java/no/priv/bang/oldalbum/backend/imageio/ImageioSpiRegistration.java#L17

After this (in my own head: clever) trick, the ImageIO API of the runtime
works as it would outside of OSGi, but with the TwelveMonkeys plugins in
place of the default image manipulation code.

So, not really help, but at least two working examples of the use of
SPI-fly... :-)


- Steinar





Re: Vertx SPI

2024-03-26 Thread Steinar Bang
> Michael Elbaz :

> Hello i use vertx (wraping as a bundle) inside karaf i'm facing a
> problem because vertx-auth-common use SPI mecanism internally to load
> some classes
> (https://github.com/eclipse-vertx/vertx-auth/blob/4.5.6/vertx-auth-common/src/main/resources/META-INF/services/io.vertx.ext.auth.HashingAlgorithm)
> internally is use ServiceLoader.load but during runtime the classes
> are not found is probably related to TCCL, i was trying apache aries
> Spy Fly stuff with no success how i need to do this working thanks

FWIW SPI-fly and SPI is something I've used, but it is a place where
I've never been quite clear about why and how it works.

One place I use it is with my Liquibase karaf feature
 
https://github.com/steinarb/liquibase-karaf-feature?tab=readme-ov-file#using-liquibase-from-osgi-bundles

Requiring services only needs to be done once for each karaf instance
(i.e. once for each Java VM running), I think...? Maybe...?

The requirements haven't been consistent across the applications using
liquibase even though they are very similar..

Another place I've used it is when using the TwelveMonkeys Image
manipulation library, which plugs into the SPI-based ImageIO support of
the Java runtime.

Here I used a DS (Declarative Services) component to load TwelveMonkeys
and catch the TwelveMonkeys services and register them with ImageIO.
 
https://github.com/steinarb/oldalbum/blob/master/oldalbum.backend.imageio/pom.xml#L115
 
https://github.com/steinarb/oldalbum/blob/master/oldalbum.backend.imageio/src/main/java/no/priv/bang/oldalbum/backend/imageio/ImageioSpiRegistration.java#L17

After this (in my own head: clever) trick, the ImageIO API of the runtime
works as it would outside of OSGi, but with the TwelveMonkeys plugins in
place of the default image manipulation code.

So, not really help, but at least two working examples of the use of
SPI-fly... :-)


- Steinar