ServiceLoader in the JDK
Paul Sandoz
paul.sandoz at oracle.com
Wed May 23 09:31:34 PDT 2012
Hi,
Here is some proposed changes in the JDK related to service loader (not tested yet! just want some easily feedback):
http://cr.openjdk.java.net/~psandoz/jigsaw/jdk-services/webrev/
I have attempted where possible to tidy things up to avoid an explicit reference to a class loader for common patterns hence the addition of the methods ServiceLoader.loadFromClass, ServiceLoader.loadFromSystem and ServiceLoader.loadFromCaller (when in module mode most ServiceLoader.load* method do the equivalent of the latter). The names could be better.
I also improved the dump-config to output local service provides and remote service suppliers (see below for an example).
Questionable areas:
- I left JMX alone. It is doing lots of funky stuff. Plus will likely require spec changes.
- com.sun.tools.jdi.VirtualMachineManagerImpl is loading providers (Connector and TransportService) from the class loader of those classes. This is probably not an issue. But i do wonder if it could be replaced with ServiceLoader.loadFromCaller().
- sun.tools.jconsole.JConsole uses a URL class loader (with a plugin path) from which services are loaded. I suppose one solution here would be something like:
if (Platform.isModuleMode()) {
// Use ServiceLoader.loadFromCaller(JConsolePlugin.class) and ignore the plugin path
} else {
// code as before
}
Does the "jconsole -pluginpath " option make much sense on module mode? Although in general I presume a URLClassLoader could be used like this in module mode (i have not verified). Perhaps we require a -L <module library path> option.
Paul.
ServiceTest $ jmod -L build/mlib dump-config mfoo
configuration roots = [mfoo at 1.0]
context +jdk.logging
module jdk.logging at 8-ea [/Users/sandoz/Projects/jdk8/jigsaw/build/macosx-x86_64/lib/modules]
view jdk.logging at 8-ea
local (79) ...
remote (74)
context +mfoo
module mfoo at 1.0
view mfoo at 1.0
local service providers (1)
com.sun.net.httpserver.spi.HttpServerProvider
foo.HP
local (3)
foo.Foo:mfoo at 1.0
foo.HP:mfoo at 1.0
foo.HP$1:mfoo at 1.0
remote (48)
context +jdk.httpserver
module jdk.httpserver at 8-ea [/Users/sandoz/Projects/jdk8/jigsaw/build/macosx-x86_64/lib/modules]
view jdk.httpserver at 8-ea
remote service suppliers (1)
com.sun.net.httpserver.spi.HttpServerProvider
+mfoo
local (69) ...
remote (51)
context +jdk.jaxp
module jdk.jaxp at 8-ea [/Users/sandoz/Projects/jdk8/jigsaw/build/macosx-x86_64/lib/modules]
view jdk.jaxp at 8-ea
view jdk.jaxp.internal at 8-ea
local (2335) ...
remote (46)
context +jdk.rmi
module jdk.rmi at 8-ea [/Users/sandoz/Projects/jdk8/jigsaw/build/macosx-x86_64/lib/modules]
view jdk.rmid at 8-ea
view jdk.rmi.internal at 8-ea
view jdk.rmiregistry at 8-ea
view jdk.rmi at 8-ea
local (243) ...
remote (79)
context +jdk.auth+jdk.base+jdk.desktop+jdk.jndi+jdk.prefs+jdk.tls+sun.charsets+sun.localedata
module sun.localedata at 8-ea [/Users/sandoz/Projects/jdk8/jigsaw/build/macosx-x86_64/lib/modules]
view sun.localedata at 8-ea
module jdk.tls at 8-ea [/Users/sandoz/Projects/jdk8/jigsaw/build/macosx-x86_64/lib/modules]
view jdk.tls.internal at 8-ea
view jdk.tls at 8-ea
module jdk.base at 8-ea [/Users/sandoz/Projects/jdk8/jigsaw/build/macosx-x86_64/lib/modules]
view jdk.base at 8-ea
view jdk.base.unsafe at 8-ea
view jdk.base.internal at 8-ea
view jdk.base.oracle at 8-ea
view jdk.jmod at 8-ea
module sun.charsets at 8-ea [/Users/sandoz/Projects/jdk8/jigsaw/build/macosx-x86_64/lib/modules]
view sun.charsets.internal at 8-ea
view sun.charsets at 8-ea
module jdk.prefs at 8-ea [/Users/sandoz/Projects/jdk8/jigsaw/build/macosx-x86_64/lib/modules]
view jdk.prefs at 8-ea
module jdk.jndi at 8-ea [/Users/sandoz/Projects/jdk8/jigsaw/build/macosx-x86_64/lib/modules]
view jdk.jndi.internal at 8-ea
view jdk.jndi at 8-ea
module jdk.auth at 8-ea [/Users/sandoz/Projects/jdk8/jigsaw/build/macosx-x86_64/lib/modules]
view jdk.auth.internal at 8-ea
view jdk.auth at 8-ea
module jdk.desktop at 8-ea [/Users/sandoz/Projects/jdk8/jigsaw/build/macosx-x86_64/lib/modules]
view jdk.desktop at 8-ea
view jdk.desktop.internal at 8-ea
local service providers (6)
sun.net.spi.nameservice.NameServiceDescriptor
sun.net.spi.nameservice.dns.DNSNameServiceDescriptor
javax.print.PrintServiceLookup
sun.print.UnixPrintServiceLookup
sun.java2d.cmm.PCMM
sun.java2d.cmm.lcms.LCMS
javax.print.StreamPrintServiceFactory
sun.print.PSStreamPrinterFactory
sun.java2d.pipe.RenderingEngine
sun.java2d.jules.JulesRenderingEngine
sun.java2d.pisces.PiscesRenderingEngine
java.nio.charset.spi.CharsetProvider
sun.nio.cs.ext.ExtendedCharsets
local (10920) ...
remote (46)
More information about the jigsaw-dev
mailing list