ServiceLoader.load() alternative

Alan Bateman Alan.Bateman at oracle.com
Wed Oct 17 14:06:15 PDT 2012


On 17/10/2012 18:06, Hendy Irawan wrote:
> 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?
>
I would suggest coming back to this when the container support [1] is in 
place. It may be that the container support will require updates to 
ServiceLoader to allow the container arrange for additional service 
providers to be included in the relative configuration for the application.

-Alan

[1] 
http://openjdk.java.net/projects/jigsaw/doc/draft-java-module-system-requirements-12#_3



More information about the jigsaw-dev mailing list