uses is useless ?
Alan Bateman
Alan.Bateman at oracle.com
Wed Nov 16 10:09:40 UTC 2016
On 16/11/2016 09:48, Remi Forax wrote:
> Hi guys,
> sorry for the pun in the title.
>
> Last week end, i've taken a big codebase and try to retrofit it to use jigsaw,
> obviously the code has several (two in fact) cyclic dependencies and in both cases, i was able to break those cycles by changing the code to use services.
Good to hear this.
> In one case, i have wanted to write a small code that uses the ServiceLoader like DriverManager.drivers() to expose the service but if i do that,
> it's the module that contains that small code that has to declare the directive 'uses' inside its own module-info instead of being the code that effectively uses the service,
> which seems wrong to me *.
I assume you are looking for Module::addUses which is useful when
libraries are using ServiceLoader on behalf of someone else. In these
scenarios then someone needs to declare that the `uses` of course,
otherwise the service provider modules won't be resolved.
As regards the hygiene check in ServiceLoader then it is not strictly
needed but it has been very useful to identify cases where `uses` is
missing from the module declaration.
>
> So i think where missing an API point on ServiceLoader that allow to write a method that will ask for a directive uses on the behalf of the ServiceLoader.
>
> I think it's a good idea to leverage Lookup class here and add a method load(Class, Lookup) that load a service on the behalf to the lookup class and requires the module of the lookup class to declare a directive uses.
>
> cheers,
> Rémi
>
> * it's definitevly wrong because when i wanted to use jlink on the code to generate a kind of light version of the application, i was not able to know which modules was using the service to pass them as root modules to jlink.
>
jlink does not do service binding and you'll see in JEP 282 that there
is an open issue on whether to provide an option to help identify the
service provider modules to link into the image.
-Alan
More information about the jigsaw-dev
mailing list