Dump services webrev
paul.sandoz at oracle.com
Fri May 25 06:32:04 PDT 2012
On May 25, 2012, at 2:26 PM, Alan Bateman wrote:
> On 25/05/2012 12:27, Paul Sandoz wrote:
>>> It's come up on discussions here before too. Clearly setting the property to some implementation type that is not visible isn't going to work. However as the service providers will be installed as modules then the property mechanism could potentially be used to choose the provider. So in this case if com.sun.net.httpserver.HttpServerProvider is set to the name of a provider then we could use ServiceLoader to iterate through the providers to fine one with this name.
>> I can see why that might be useful, but i find the use of system properties rather hacky, in this context it's seems like out of band information of an application.
>> If there was a way that an entry point could also make a preference on services providers that could formalize things a little better.
> We've tentatively talked here about having some means to configure the order, or minimally which service provider is returned first. It comes up with aliases too. So I would say this is an open question.
> Many of these APIs specify a system property to select the implementation so we will minimally need this to continue to work when running with a class path (as you have done). When running with modules then there may still be an need to override things, even if we have configured the preferred provider for the application. Several examples come to mind but one is performance testing where you need to specify the provider on a per-run basis.
>> Also, as we have discussed there are a class of services that are factories. Sometimes it is OK to have more than one present with selection of one loosely defined, other times it only makes sense to have at most one and a configuration error could result (e.g. multiple vendor implementations).
>> If we could change "requires service" to, for example "@Factory requires service" or 'requires factory", then it opens up the possibility to output warnings and errors.
> At this time then the configuration can ensure that at least one provider is installed but there isn't any way to require only one or at most one.
I am guessing annotations in module-info.java files are not supported (yet perhaps...) making it trickier to prototype.
> On another thread here (maybe more than one thread) there was also the suggestion that the "provides service" should allow a static factory method to be specified and that method method would return a reference to the provider.
BTW in Jersey we forked ServiceLoader and i modified it to "keep on trucking" if a service could not be instantiated.
> It remains to be seen how much is done with services, ServiceLoader, etc. as it's whole project in itself.
Indeed, and there was me thinking "this looks like a manageable chunk of stuff to get started on".
Still, given all our discussions on this i can see some useful ways we can make some forward progression.
More information about the jigsaw-dev