Richard Zowalla created OPENNLP-1972:
----------------------------------------

             Summary: Add a generic provider SPI for service-loaded components
                 Key: OPENNLP-1972
                 URL: https://issues.apache.org/jira/browse/OPENNLP-1972
             Project: OpenNLP
          Issue Type: Improvement
            Reporter: Richard Zowalla


Adds to {{opennlp.tools.util.ext}} in opennlp\-api:
\* {{Provider}}: {{name\(\)}}, {{priority\(\)}}, {{isAvailable\(\)}}, 
{{supports\(ProviderSpec\)}}, {{create\(ProviderSpec\)}}.
\* {{Providers>}}: created with {{of\(spi\)}}, {{of\(spi, loader\)}} or 
{{of\(spi, loader, configuration\)}}; {{installed\(\)}}, {{byName\(name\)}}, 
{{supporting\(spec\)}}, {{select\(spec\)}}, {{configurationKey\(\)}}, 
{{disabledKey\(\)}}, {{allowedKey\(\)}}.
\* {{ProviderSpec}}: an optional URI location plus string options.
\* {{ProviderResolutionException}} with {{UnsatisfiedProviderException}} and 
{{AmbiguousProviderException}}.

Each service interface gets its own SPI sub\-interface and service file, so a 
lookup only instantiates providers of that service interface. {{select}} 
considers the available providers that support the spec; {{opennlp.provider.}} 
narrows them to one name, {{opennlp.provider..disabled}} vetoes names and 
provider classes and {{opennlp.provider..allowed}} restricts which provider 
classes may be instantiated at all; the highest priority wins and a tie is 
ambiguous. The keys are read from {{META\-INF/opennlp/providers.properties}} of 
the class loader used for the lookup, overridden by system properties, or from 
a source the application passes.

A provider that fails to load, has an invalid name or throws from {{name\(\)}} 
or {{priority\(\)}} is skipped while the providers are looked up; one that 
throws from {{isAvailable\(\)}} or {{supports\(\)}} is left out of that 
resolution. A class loader that cannot list or read its files fails the lookup 
with {{ProviderResolutionException}}.

The implementation is thread\-safe, keeps no static state so that an 
application server can undeploy an application, and uses no reflection, so a 
native image needs no metadata for the lookup itself \(OPENNLP\-1954\).

{{DocumentAnnotatorProvider}} is the first service interface, with 
{{StemmerAnnotatorProvider}} in opennlp\-runtime.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to