ServiceLoader.load() alternative

Jaroslav Tulach jaroslav.tulach at oracle.com
Thu Oct 18 06:42:07 PDT 2012


Dne Čt 18. října 2012 00:06:33, Hendy Irawan napsal(a):
> Hi Jigsaw,
> 
> After reading openjdk-jigsaw-modular-services.pdf. Given the issues with
> static methods like ServiceLoader.load(), particular in dynamic
> environments (OSGi) and even more in scoped frameworks (like OSGi regions),
> is it planned to offer a new recommended approach for locating services?
> 
> Instead of ServiceLoader.load(), the mechanism to locate a service would be
> in a ServiceLookup interface, that can be provided to the consumer via
> injection or other means... (or perhaps via static calls for simple cases).
> This will be useful for testing, mocking, reusability, and also dynamic
> frameworks like OSGi. ServiceLookup can be scoped to a specific region, and
> the implementation can even change during runtime (e.g. by proxying).
> 
> Even better if an async version of ServiceLookup is provided, or a sync
> version with a timeout. This will allow expanded use of ServiceLookup for
> distributed environments, or stricter timing requirements.
> 
> ServiceLoader.load() will then be deprecated, or at least given a note that
> it only supports a subset of the Jigsaw service capabilities. New
> implementors should use ServiceLookup interface.
> 
> Is this feasible?

It is hard to resist a temptation to share the NetBeans experience:
http://bits.netbeans.org/dev/javadoc/org-openide-util-lookup/
The essential difference to ServiceLoader seems to be the fact that 
Lookup.getDefault is pluggable, e.g. people can implement its own behavior to 
suite their needs - we have implementation that bridges to OSGi's service 
registry, for example.

-jt





More information about the jigsaw-dev mailing list