Re: Lookups and positions

Steven Yi <[email protected]>
Newsgroups gmane.comp.java.netbeans.modules.openide.devel
Message-ID <CANtcCs5nc2OVJxyiwtEqAEvtjGGP6-SY5-Kdz8gEAd-NWXvqDw@mail.gmail.com>
Hi Javier,

I ran the example and got:

Interface2:
1) Class2
2) Class1
Interface1:
1) Class1

I am on Windows, Java 1.8.0_72, 64-bit.

Regarding the position attribute, I interpreted it as the service
ordering having to do with Java's builtin ServiceLoader class [1],
rather than with NB's default Lookup. There's an additional issue in
the documentation in Lookup.getDefault() [2]:

"Static method to obtain the global lookup in the whole system. The
actual returned implementation can be different in different systems,
but the default one is based on
Lookups.metaInfServices(java.lang.ClassLoader) with the context
classloader of the first caller. Each system is adviced to honor this
and include some form of metaInfServices implementation in the
returned lookup as usage of META-INF/services is a JDK standard."

I haven't looked into it, but perhaps it's the case that you are on a
different platform than Windows, and on Windows getDefault() provides
a lookup that is based on metaInfServices, while on your platform it
uses another Lookup?  (Just a guess.)

I also tried this code:

ServiceLoader<Interface2> services = ServiceLoader.load(Interface2.class);
    count = 0;
        System.out.println(Interface2.class.getSimpleName() + ": ");
    for(Interface2 i2 : services) {
            System.out.println(++count + ") " + i2.getClass().getSimpleName());
    }

Which also gave the expected results for Interface2 here.

Steven


[1] - https://docs.oracle.com/javase/8/docs/api/java/util/ServiceLoader.html
[2] - http://bits.netbeans.org/8.0/javadoc/org-openide-util-lookup/org/openide/util/Lookup.html#getDefault%28%29

On Mon, Mar 28, 2016 at 4:23 PM, Javier Ortiz <[email protected]> wrote:
> Just pushed changes so it should work out of the box.
>
> Yes it does if you use the position attribute as stated here.
>
> Thanks for the feedback.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.