Example code in JDK8 requiring change for modular function
paul.sandoz at oracle.com
Mon May 7 01:52:57 PDT 2012
On May 7, 2012, at 10:39 AM, Alan Bateman wrote:
> On 07/05/2012 09:06, Paul Sandoz wrote:
>>> Implementation-wise it will require the base module to have "requires optional service java.nio.file.spi.FileTypeDetector" in its module declaration and the ServiceLoader usage changed as the legacy system class loader notion doesn't make sense when running with modules.
>> FWIW i verified that is the case today in Jigsaw. Do the generated module-info.java files contain all known providers, or is there still some work to do here?
> Non-static dependencies are a bit fragile at this point, and will be until we check in the module-info sources. For now it requires making sure that jdk/make/modules/jdk.depconfig is up to date. In this case the issue is that it's in jdk.depconfig as:
> java.nio.file.Files$DefaultFileTypeDetectorHolder -> META-INF/services/java.nio.file.spi.FileTypeDetector
> but that's not the right inner class name anymore. Apologies about that, I fixed lots of these when adding the services support but I missed this one.
If you have not already fixed it by the time you read this email i can do it.
>> The main concern i have with this example is the caching of the service provider implementations. It is something we will have to revisit.
> This specific case was never intended to be dynamic, it's specified to maintain a system-wide list of file type detectors. But as you bring up caching then one observation is that as the user of the service is linked with the service providers at configuration time then caching by the user of ServiceLoader isn't going to change the performance, meaning there isn't really any need for this code to cache the providers when running with modules. I guess the concern you have is the container managed application that comes with their own file type detector, that scenario would require consideration.
So this is good example of where we could have two code paths based on a boolean check if running in module mode or not.
More information about the jigsaw-dev