Enhanced ServiceLoader?

mark.reinhold at oracle.com mark.reinhold at oracle.com
Mon Mar 16 20:51:06 UTC 2015


2015/3/9 8:23 -0700, Tim Boudreau <niftiness at gmail.com>:
> mark.reinhold at oracle.com:
>> Tim Boudreau <niftiness at gmail.com>:
>>> NetBeans did the ordering hints for years by enhancing META-INF/services
>>> files with magic comments, e.g.
>>>
>>> #position 1000
>>> com.foo.Bar
>>>
>>> It would be good if ServiceLoader could grow enough heft to handle that
>>> role - not necessarily identically - but the feature satisfies a proven
>>> need.
>> 
>> How is this any different than an @Ordered annotation?
> 
> It isn't, other than that as a performance optimization, you don't have to
> load the class to determine its order.
> 
>> Doesn't it still assume that the author of a module somehow has global
>> knowledge of how that module will be used in every possible scenario?
> 
> It assumes the author of a module has at least *partial* knowledge of how
> that module will be used in its *intended* scenario:
> 
> ...

I understand your argument, but I'm still not convinced that we should
enhance ServiceLoader to support a feature like this.  It can make sense
in a large collection of closely-related modules (e.g., NetBeans), but
in a scenario like that an agent with (near-)global knowledge can use
selective binding to arrange providers in the correct order.  If, by
contrast, I'm just publishing a service provider for general use then
I'm really not going to have much of a clue as to how to assign an order
metric.

In the general case this seems like one of those "attractive nuisance"
features that will be used correctly by some developers yet incorrectly
by most.

In any case, as I said earlier I think this is more of a design issue
than something we need to consider for the requirements.

- Mark


More information about the jpms-spec-experts mailing list