Order of Services was: Still driving off the cliff
Alan Bateman
Alan.Bateman at oracle.com
Sat Feb 25 09:17:07 PST 2012
On 23/02/2012 15:38, Jaroslav Tulach wrote:
>> ## Alan wrote on 23. 2. 2012 13:16:14 ##<
>> service. Clearly if someone installs another module that also provides a
>> SelectorProvider implementation then it's like installing into the
>> extensions directory in the current world; one will be chosen and
>> there's a way to override it. In the implementation then the order is
>> stable and doesn't change between runs.
> NetBeans solves problem this by positioning. The
> http://bits.netbeans.org/dev/javadoc/org-openide-util-
> lookup/org/openide/util/lookup/ServiceProvider.html
> annotation (that generates the META-INF/services/xyz file) has attribute
> position.
>
> ServiceLoader could be honor such position indicator and sort services
> accordingly.
I'm curious as to your experiences with this approach. In particular has
it been problematic for cases where the order needs to configured by the
user of the service providers? Also I wonder about cases where there are
multiple applications are loading the service providers and the order
needs to be different. In the JDK we have examples such as the
java.security file that list the security providers and the preference
order. There are other examples where the preference order is determine
by system properties. We don't have a general mechanism for ordering and
might be a bit beyond the scope of getting services deployed as modules
(still interesting to hear your experiences).
>
>> As I said, I think ServiceLoader has to change.
>> The load(Class) method is specified to use the
>> threadContextClassLoader but what if that has been set to null or
>> ClassLoader.getSystemClassLoader
> NetBeans solves[1] this problem by registering special Thread.cCL that can see
> classes from all enabled modules in the running VM. Thus by default using
> ServiceLoader.load finds all services provided by all enabled modules.
>
Sure, but my point was getting code that has it to null or
ClassLoader.getSystemClassLoader. In the current prototype the latter is
the module loader of the module for the main class and so may not be the
right loader. As DML suggested, it would require existing code to change
but how we handle such cases it still something that needs further
consideration in my view.
-Alan
More information about the jigsaw-dev
mailing list