uses is useless ?
forax at univ-mlv.fr
forax at univ-mlv.fr
Wed Nov 16 10:25:49 UTC 2016
----- Mail original -----
> De: "Alan Bateman" <Alan.Bateman at oracle.com>
> À: "Remi Forax" <forax at univ-mlv.fr>
> Cc: "jigsaw-dev" <jigsaw-dev at openjdk.java.net>
> Envoyé: Mercredi 16 Novembre 2016 11:09:40
> Objet: Re: uses is useless ?
> 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.
The whole point of uses is to enable a kind of static analysis on the service dependencies,
if 'uses' is not required, if you can easily bypass it or it doesn't provide useful information,
then it should be removed from the spec.
>> 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.
>> * 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.
Yes, jlink doesn't do that, but my tool on top of jlink does it :)
But as i said above, if the information given by 'uses' do not allow to do static analysis like finding the root modules (services included), it perhaps means that 'uses' doesn't worth its own weight.
More information about the jpms-spec-observers