Dump services webrev
Jesse Glick
jesse.glick at oracle.com
Fri May 25 09:02:32 PDT 2012
On 05/25/2012 06:35 AM, Alan Bateman wrote:
> if com.sun.net.httpserver.HttpServerProvider is set to the name of a provider then we could use ServiceLoader to iterate through the providers
Another possibility would be for ServiceLoader to check for a system property with the same (binary) name as the service; if set, and corresponding to the (binary) name
of one of the providers, load that one and that one only. Would offer an easy compatibility path for some legacy code. But maybe this should be left to the caller to handle.
> requires optional service sun.java2d.pipe.RenderingEngine;
> provides service sun.java2d.pipe.RenderingEngine with sun.java2d.jules.JulesRenderingEngine;
> provides service sun.java2d.pipe.RenderingEngine with sun.java2d.pisces.PiscesRenderingEngine;
If a module provides the service it requires (in fact provides two variants), surely the "optional" keyword is unnecessary?
later:
> there was also the suggestion that the "provides service" should allow a static factory method to be specified
This is very handy, and a good idea if you are dropping the legacy META-INF/services/* format anyway. This avoids the need to create new subclasses for minor variants of
a service.
You could also allow static final fields - typically the service provider is a singleton with no instance state so there is no real overhead associated with a field. This
could be especially convenient in conjunction with lambdas:
provides service java.nio.file.spi.FileTypeDetector with my.Utils.DETECTOR;
...
package my;
public class Utils {
public static final FileTypeDetector DETECTOR = (f) -> f.endsWith(".myext") ? "text/mine" : null;
}
Paul Sandoz wrote:
> in Jersey we forked ServiceLoader and i modified it to "keep on trucking" if a service could not be instantiated
Same in NetBeans; logs a warning and continues with no impact on the caller. Catching ServiceConfigurationError in each caller would be be a pain, and since it is
unchecked it would be easily forgotten, and if forgotten it is unlikely to be noticed during development and come up only in production systems. In Jigsaw the module
system should catch most potential problems (e.g. misspelled service name) statically, but the service constructor/factory could still throw an exception I suppose.
More information about the jigsaw-dev
mailing list