[enRoute] Where is the Service Mediator?

57 views
Skip to first unread message

David Leangen

unread,
Nov 18, 2016, 5:39:20 AM11/18/16
to bndtool...@googlegroups.com

Hi,

(Hope this is still the place to ask questions about enRoute…)

I could be asking a naive question because I have never had to use this before, but (assuming it is in the enRoute Distro) which bundle contains the ServiceMediator implementation?

I am trying to load Java Money, and from what I understand, I need to use this service.


Thanks!
=David


David Bosschaert

unread,
Nov 18, 2016, 6:28:04 AM11/18/16
to bndtool...@googlegroups.com
Hi David,

Not sure if this is what you're looking for, but http://aries.apache.org/modules/spi-fly.html is an implementation of the ServiceLoader Mediator specification

HTH,

David

=David


--
You received this message because you are subscribed to the Google Groups "bndtools-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bndtools-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

David Leangen

unread,
Nov 19, 2016, 1:58:17 AM11/19/16
to bndtool...@googlegroups.com

Hi!

So I am able to resolve Java Money at compile time.

After adding the required dependencies to one of my repositories, I “augmented” the bundle in my enroute-distro.bnd file like this:

-augment.jx_mn: \
org.javamoney.moneta.core; \
requirement: "osgi.extender;filter:='(osgi.extender=osgi.serviceloader.registrar)'"; \
capability:= "osgi.serviceloader;osgi.serviceloader=javax.money.spi.ServiceProvider"

In my consumer bundle, I added this to the manifest:

Require-Capability: \
osgi.extender;\
filter:="(osgi.extender=osgi.serviceloader.processor)",\
    osgi.serviceloader;\
filter:="(osgi.serviceloader=javax.money.spi.ServiceProvider)";\
cardinality:=multiple

However, at runtime, I get this:

  Unresolved requirement: Require-Capability: osgi.serviceloader; filter:="(osgi.serviceloader=javax.money.spi.ServiceProvider)"; cardinality:="multiple"


What to do?

I think this may have been explained to me already, but why does something that resolves fine at compile time not resolve at runtime if all the same bundles are made available? Is it possible that the “augment” above does not work at runtime? In that case, what would be the best course of action?


Cheers,
=David



On Nov 19, 2016, at 9:03 AM, David Leangen <david....@bioscene.co.jp> wrote:


Ok, thanks! Yes, this is indeed putting me on the right track. Just trying to understand it and get it set up now.

If anybody has Java Money set up using a different method, would be great to hear about it. :-)


Cheers,
=David



On Nov 18, 2016, at 8:27 PM, David Bosschaert <david.bo...@gmail.com> wrote:

Hi David,

Not sure if this is what you're looking for, but http://aries.apache.org/modules/spi-fly.html is an implementation of the ServiceLoader Mediator specification

HTH,

David
On 18 November 2016 at 10:39, David Leangen <david....@gmail.com> wrote:

Hi,

(Hope this is still the place to ask questions about enRoute…)

I could be asking a naive question because I have never had to use this before, but (assuming it is in the enRoute Distro) which bundle contains the ServiceMediator implementation?

I am trying to load Java Money, and from what I understand, I need to use this service.


Thanks!
�vid



--
You received this message because you are subscribed to the Google Groups "bndtools-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bndtools-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups "bndtools-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bndtools-user...@googlegroups.com.

Neil Bartlett

unread,
Nov 19, 2016, 3:53:21 AM11/19/16
to bndtool...@googlegroups.com
On 19 Nov 2016, at 06:58, David Leangen <david....@gmail.com> wrote:


Hi!

So I am able to resolve Java Money at compile time.

After adding the required dependencies to one of my repositories, I “augmented” the bundle in my enroute-distro.bnd file like this:

-augment.jx_mn: \
org.javamoney.moneta.core; \
requirement: "osgi.extender;filter:='(osgi.extender=osgi.serviceloader.registrar)'"; \
capability:= "osgi.serviceloader;osgi.serviceloader=javax.money.spi.ServiceProvider"

In my consumer bundle, I added this to the manifest:

Require-Capability: \
osgi.extender;\
filter:="(osgi.extender=osgi.serviceloader.processor)",\
    osgi.serviceloader;\
filter:="(osgi.serviceloader=javax.money.spi.ServiceProvider)";\
cardinality:=multiple

However, at runtime, I get this:

  Unresolved requirement: Require-Capability: osgi.serviceloader; filter:="(osgi.serviceloader=javax.money.spi.ServiceProvider)"; cardinality:="multiple"


What to do?

I think this may have been explained to me already, but why does something that resolves fine at compile time not resolve at runtime if all the same bundles are made available? Is it possible that the “augment” above does not work at runtime? In that case, what would be the best course of action?


That’s exactly the case. Augments are used by the Bndtools resolver but not seen by the OSGi Framework resolver.

Probably the best thing to do is add an effective directive to the Req-Cap in your bundle. For example if you add “effective:=active” then the requirement is ignored by the OSGi Framework. But it is still used by the Bndtools resolver, as long as you have "-resolve.effective: active” in your bndrun file.

Regards,
Neil

David Leangen

unread,
Nov 19, 2016, 6:17:10 AM11/19/16
to bndtool...@googlegroups.com

Probably the best thing to do is add an effective directive to the Req-Cap in your bundle. For example if you add “effective:=active” then the requirement is ignored by the OSGi Framework. But it is still used by the Bndtools resolver, as long as you have "-resolve.effective: active” in your bndrun file.

Thanks Neil, that did the trick! Everything resolves, and it appears that the byte code weaving magic is happening when I run the code.

My knowledge of ServiceLoader is very shallow. I am still not able to load Java Money.

In the consumer bundle, this is where I attempt to force the loading:

        ServiceLoader<ServiceProvider> ldr = ServiceLoader.load(ServiceProvider.class);
        for (ServiceProvider spiObject : ldr) {
            CurrencyProviderSpi cp = spiObject.getService( CurrencyProviderSpi.class );
            if( cp != null )
                cp.toString(); // Did this work?????
        }

When I run the code, ldr does something, but it does not find any ServiceProvider implementations. I tried this on some of the SPIs like CurrencyProviderSpi as well, but that didn’t work, either.

Any pointers would be great!


Cheers,
=David


David Leangen

unread,
Nov 22, 2016, 6:13:20 PM11/22/16
to bndtool...@googlegroups.com

In case any future species digs around to find out why the Earth was destroyed in 2017, and wishes to use Java Money in OSGi, just thought I would add a post-note here.



For some reason I could not find the secret combination to make this work using the ServiceMediator. I am sure there is a simple explanation but I ran out of patience.

In the end, I packaged up the API and impl bundles into a single distribution bundle, and made every package public. This ended up being a simpler and more compact approach, since I could reduce 6 bundles (api + impl + 4 deps relating to Service Mediator) down to 1 single bundle.


Cheers,
=David
Reply all
Reply to author
Forward
0 new messages