Dynamic loading of FileSystemProvider instances
Alan Bateman
Alan.Bateman at oracle.com
Mon Jun 6 11:40:04 PDT 2011
Christian Schlichtherle wrote:
> Hi Alan,
>
> we recently discussed that I have a need to determine the NIO.2
> FileSystemProvider instances at run time.
I think that discussion was more that there isn't a method to add to the
list of installed providers at runtime (the list returned by
FileSystemProvider.installedProviders is created at startup and there
isn't a method to register/add to it). You can of course use
ServiceLoader.load(FileSystemProvider.class, loader) to locate
additional providers yourself.
> Because this is not possible, you
> suggested I should introduce one VFS scheme for my TrueZIP
> TFileSystemProvider.
That suggestion wasn't exactly related but rather that if you are
developing a virtual file system then you need to choose a (singular)
URI scheme in order to deploy as a provider. That provider can of course
delegate to other providers, which I think is what you are doing.
> For example, the NIO.2 Path URI "tzp:/archive.zip"
> should get identified by my TrueZIP TFilesystemProvider and internally
> rewritten to the TrueZIP FsPath URI "zip:file:/archive.zip!/".
>
> While this is certainly possible, it still limits my implementation: The
> issue is that I need to determine a TrueZIP FsMountPoint URI for rewriting
> the NIO.2 Path URI. In the example above, this is "file:/". However, on
> Windows, it could be "file:/C:/" or "file:/D:/" or whatever. In TrueZIP, it
> could even be "http://somehost/" or "http://someotherhost/base/" or
> whatever. It could even be an entirely different scheme, depending on the
> file system driver.
>
> To overcome this, I need a way to determine the NIO.2 FileSystemProvider
> instances at run time. To make minimal impact on the current NIO.2 API, I
> suggest the following quick draft:
>
> <code>
> package java.nio.file.spi;
>
> public interface FileSystemProviderCatalogue extends
> Iterable<FileSystemProvider> {
> }
> </code>
>
> You could then simply use java.util.ServiceLoader to locate
> FileSystemProviderCatalogue instances on the run time class path while I
> could happily implement the iterator to figure the TFileSystemProvider
> instances I need.
>
I don't think I fully understand it. If there are providers on the class
path then they should be returned by the
FileSystemProvider.installedProviders method.
-Alan
More information about the nio-discuss
mailing list