You might want to look at the one in master. It probably needs the same thing done. However, it also uses modules which is quite a bit simpler since we don’t have to search for ClassLoaders.
If you look at ProviderUtil you will notice that the Provider interface specifies a “version” of the API. If the service doesn’t match that version it doesn’t get loaded. Although this isn’t an exact match it should illustrate how to implement what you want: 1. Define an interface for the service. It should include something like int getPriority(); 2. In the service implementation have the Priority value be hard-coded to a value. When you call ServiceLoader call the getPriority method and rank the located services in priority order. Ralph > On Mar 6, 2022, at 11:56 AM, Piotr P. Karwasz <[email protected]> wrote: > > On Sun, Mar 6, 2022 at 6:23 PM Ralph Goers <[email protected]> wrote: >> I wrote a ServiceLoaderUti. It is in log4j-api in master. However, it has >> shortcomings. >> ServliceLoader MUST be invoked in the appropriate JPMS module or it won’t >> find >> the correct declarations in module-info.java. So ServiceLoaderUtil requires >> a lambda >> where the ServiceLoader call must be performed. > > I might have sworn I looked for all references to `ServiceLoader` in > `master` too and I didn't find this one. :-( > > Anyway I sent what I need in `release-2.x` as: > > https://github.com/apache/logging-log4j2/pull/787 > > where I concentrated on two shortcomings of a simple `ServiceLoader#load`: > > 1. Resources found in the parent classloader of a web application > classloader can be useless (they extend a class in the parent > classloader, not the class requested), > 2. The order in which services are found is random, so for > applications that require a single service, we need a way to override > the choice provided by `ServiceLoader`. > > I'll refactor the PR to use the same method names and expand the > `master` version to provide the two features above. > > Piotr
