Interface Provider<T>
- Type Parameters:
T- The service interface created by this provider.
- All Known Subinterfaces:
DocumentAnnotatorProvider, TextEmbedderProvider
public interface Provider<T>
Creates instances of one service interface from a
ProviderSpec.
Every service interface has an SPI of its own that extends this interface, for example
DocumentAnnotatorProvider extends Provider<DocumentAnnotator>. Implementations are
listed in META-INF/services/<SPI fully qualified name>, need a public no-argument
constructor and are resolved through Providers.
Implementations must be stateless and thread-safe. The constructor, the static initializer of
the implementation class, isAvailable() and supports(ProviderSpec) must not
load models or initialize native libraries: they run while providers are looked up, before a
caller has chosen one.
- Since:
- 3.0.0
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptioncreate(ProviderSpec spec) Creates a new instance.default booleanChecks whether this provider can be used in the running process, for example whether an optional dependency is on the class path.name()default intpriority()booleansupports(ProviderSpec spec) Checks whether this provider can create an instance for a spec, based on the spec alone.
-
Method Details
-
name
String name()- Returns:
- The case-sensitive name of this provider: at most 64 characters of ASCII letters,
digits,
.,_or-, since it is used as a configuration value. A provider with another name is skipped when providers are looked up. Providers of one SPI may share a name;priority()ranks them.
-
priority
default int priority()- Returns:
- The rank of this provider among providers that support the same spec, larger
wins. The default is
0.
-
isAvailable
default boolean isAvailable()Checks whether this provider can be used in the running process, for example whether an optional dependency is on the class path. Check a class by class literal and catchLinkageErrorinstead of loading it by name, which also keeps a native image free of reflection metadata. The check runs on every resolution, so it must not block.- Returns:
trueif this provider can be used. The default istrue.
-
supports
Checks whether this provider can create an instance for a spec, based on the spec alone. The check runs on every resolution, so it must not block.- Parameters:
spec- The spec to check. Must not benull.- Returns:
trueifcreate(ProviderSpec)acceptsspec.- Throws:
IllegalArgumentException- Thrown ifspecisnull.
-
create
Creates a new instance. The caller owns it and closes it if it is closeable. The location of the spec is unvalidated input of the caller: a provider that opens it decides itself which schemes and which directories it accepts.- Parameters:
spec- The spec to create an instance for. Must not benull.- Returns:
- The new instance. Never
null. - Throws:
IllegalArgumentException- Thrown ifspecisnullor not supported.IOException- Thrown if a resource named byspeccould not be read.
-