Modularizing URLStreamHandlerFactory
Paul Sandoz
paul.sandoz at oracle.com
Mon Jun 18 01:49:40 PDT 2012
On Jun 18, 2012, at 3:20 AM, David Holmes wrote:
> On 16/06/2012 7:17 AM, Jesse Glick wrote:
>> Something to consider - in a big application it is not uncommon to have
>> multiple URL handlers implemented in various places. Yet the JRE only
>> lets you set a single URLStreamHandlerFactory for the whole JVM. So for
>> the application to be modular, you need to write a proxy factory which
>> accepts modular registrations, but that impedes interoperability since
>> you must define a proprietary interface for this.
>>
>> It would be nicer for a modular JRE to allow URL handler factories to be
>> registered as services. OSGi and the NetBeans module system both do
>> something like this.
>>
>> Similar arguments could perhaps be made for other pluggable singletons
>> in the current Java platform API (UncaughtExceptionHandler, FileNameMap,
>
> When we added UncaughtExceptionHandler we recognized the desirability to have a "per app" default rather than only having the global default, but there was/is no "application context" to define-in or extract-from the UEH. I don't see how a modular JRE has changed that at all?
A modular JRE might not change that but a module *system* can. The "application context" is the configuration, the thing that is pre-calculated (currently at install time) for an application module (one that uses the "class" clause e.g. "class foo.Main").
> Even if you say the UEH is a service, what is the scope/context of that service?
>
Per configuration. The module dependencies of the application are resolved into a list of resolved modules, then the resolved modules are linked to produce a configuration. If a module declared "requires service <S>", i.e. is a service consumer module, then any modules that declare "provides service <S> with <I>" that are present in the library, i.e. service provider modules, get pulled in as dependencies when resolving.
> Further, what additional class support do services drag into the runtime? Are these classes that are already in the base module?
>
It would depend on the service provider modules that are installed in the library.
IIUC UncaughtExceptionHandler this is a use-case of where only one service instance should be selected as the UncaughtExceptionHandler. Arguably if there are two or more such service instances it could be considered an application configuration error.
Paul.
More information about the jigsaw-dev
mailing list