Hi Noctarius!
thanks for keeping participating in the discussion - they do exactly
what onami-spi does:
>From Mycila doc:
+---------------------+
binder.bind(AgentPlugin[].class)
.toProvider(ServiceLoaderProvider.of(AgentPlugin.class).withClassLoader(ClassLoader.class))
.in(Cached20Seconds.class);
This binding creates in a cached scope for 20 seconds a list of
AgentPlugin instances on the classpath, loaded by the JDK
ServiceLoader (META-INF/services/...). When loaded, each service will
be injected with its dependencies.
+---------------------+
that is equivalent of what the Onami-SPI ServiceLoaderModule does:
+---------------------+
Injector injector = createInjector( new ServiceLoaderModule()
{
@Override
protected void configure()
{
bindService( FooService.class ).loadingAllService();
}
} );
+---------------------+
(Onami supports ClassLoader specification as well)
Nice, but that has a huge limitation, since bound service
implementation are not qualified.
Thanks!
-Simo
http://people.apache.org/~simonetripodi/
http://simonetripodi.livejournal.com/
http://twitter.com/simonetripodi
http://www.99soft.org/
On Sun, Jan 13, 2013 at 11:21 AM, Christoph Engelbert
<[email protected]> wrote:
> Hey Simone
> here's a nice article about that:
> http://blog.mycila.com/2009/10/jdk-serviceloader-as-google-guice.html
> or: https://code.google.com/p/mycila/wiki/MycilaGuice#Service_Loader
>
> Chris
>
> Am 13.01.2013 10:55, schrieb Simone Tripodi:
>> Salut Eric,
>>
>> thanks a lot for your thoughts, much more than appreciated! This
>> helped me understanding that adding some extra metadata in
>> META-INF/services files is not the right direction to address that
>> problem :)
>>
>> Let's recap: what I wanted to add to guice, in the SPI module, is the
>> ability to binding services implementation by discovering them via the
>> "ServiceLoader".
>> So, let's suppose we have the following service:
>>
>> package org.acme.api;
>> public interface CreditCardProcessor {
>> void doSomething();
>> }
>>
>> contained in acme-api.jar
>>
>> then, we do have a PayPal implementation:
>>
>> package org.acme.paypal;
>> public class PayPalCreditCardProcessor
>> implements CreditCardProcessor
>> {
>> public void doSomething()
>> {...}
>> }
>>
>> defined in acme-paypal.jar, and then a MasterCard implementation:
>>
>> package org.acme.mastercard;
>> public class MasterCardCreditCardProcessor
>> implements CreditCardProcessor
>> {
>> public void doSomething()
>> {...}
>> }
>>
>> defined in acme-mastercard.jar.
>>
>> Now, the idea is binding all these implementation automagically,
>> without scanning the classpath (which is something covered by
>> onami-autobind), but using the ServiceLoader approach. So, let's
>> immagine acme-paypal.jar content as:
>>
>> acme-paypal.jar
>> -------------------------------------------------------------------------------
>> org/acme/paypal/PayPalCreditCardProcessor.class
>> META-INF/services/org.acme.api.CreditCardProcessor
>>
>> where org.acme.api.CreditCardProcessor contains
>>
>> META-INF/services/org.acme.api.CreditCardProcessor
>> -------------------------------------------------------------------------------
>> org.acme.paypal.PayPalCreditCardProcessor
>>
>> it is now easy to immagine the same scenario for the acme-mastercard.jar
>> file.
>>
>> Let's suppose that our classpath is in the form of
>>
>> acme-api.jar:acme-paypal.jar:acme-mastercard.jar
>>
>> what I would like to obtain, for next version od SPI, is
>>
>> bind(CreditCardProcessor.class)
>> .annotatedWith(?!?!??!)
>> .to(PayPalCreditCardProcessor.class);
>> bind(CreditCardProcessor.class)
>> .annotatedWith(?!?!??!)
>> .to(MasterCardCreditCardProcessor.class);
>>
>> The missing part are, as you can notice, the binding annotations,
>> because I am looking for a way to specify qualifiers...
>>
>> Component configuration is out of scope for that extension.
>>
>> Do you have any suggestion on how to discover binding annotations as well?
>>
>> TIA, have a nice weekend!
>> -Simo
>>
>> http://people.apache.org/~simonetripodi/
>> http://simonetripodi.livejournal.com/
>> http://twitter.com/simonetripodi
>> http://www.99soft.org/
>