类 SpiLoader<S>
SPI is short for Service Provider Interface.
Service is represented by a single type, that is, a single interface or an abstract class. Provider is implementations of Service, that is, some classes which implement the interface or extends the abstract class.
For Service type: Must interface or abstract class.
For Provider class: Must have a zero-argument constructor so that they can be instantiated during loading.
For Provider configuration file: 1. The file contains a list of fully-qualified binary names of concrete provider classes, one per line. 2. Space and tab characters surrounding each name, as well as blank lines, are ignored. 3. The comment line character is #, all characters following it are ignored.
SpiLoader provide common functions, such as:
- Load all Provider instance unsorted/sorted list.
- Load highest/lowest order priority instance.
- Load first-found or default instance.
- Load instance by alias name or provider class.
- 从以下版本开始:
- 1.4.0
- 作者:
- Eric Zhao, cdfive
- 另请参阅:
-
方法概要
修饰符和类型方法说明voidload()Load the Provider class from Provider configuration fileLoad default Provider instance Provider class with @Spi(isDefault = true)Load the first-found Provider instanceLoad the first-found Provider instance,if not found, return default Provider instanceLoad highest order priority instance, order value is defined in class'sSpiannotationloadInstance(Class<? extends S> clazz) Load instance by specific class typeloadInstance(String aliasName) Load instance by aliasName of Provider classLoad all Provider instances of the specified ServiceLoad all Provider instances of the specified Service, sorted by order value in class'sSpiannotationLoad lowest order priority instance, order value is defined in class'sSpiannotationstatic <T> SpiLoader<T>Create SpiLoader instance via Service class Cached by className, and load from cache firsttoString()
-
方法详细资料
-
of
Create SpiLoader instance via Service class Cached by className, and load from cache first- 类型参数:
T- Service type- 参数:
service- Service class- 返回:
- SpiLoader instance
-
loadInstanceList
Load all Provider instances of the specified Service- 返回:
- Provider instances list
-
loadInstanceListSorted
Load all Provider instances of the specified Service, sorted by order value in class'sSpiannotation- 返回:
- Sorted Provider instances list
-
loadHighestPriorityInstance
Load highest order priority instance, order value is defined in class'sSpiannotation- 返回:
- Provider instance of highest order priority
-
loadLowestPriorityInstance
Load lowest order priority instance, order value is defined in class'sSpiannotation- 返回:
- Provider instance of lowest order priority
-
loadFirstInstance
Load the first-found Provider instance- 返回:
- Provider instance of first-found specific
-
loadFirstInstanceOrDefault
Load the first-found Provider instance,if not found, return default Provider instance- 返回:
- Provider instance
-
loadDefaultInstance
Load default Provider instance Provider class with @Spi(isDefault = true)- 返回:
- default Provider instance
-
loadInstance
Load instance by specific class type- 参数:
clazz- class type- 返回:
- Provider instance
-
loadInstance
Load instance by aliasName of Provider class- 参数:
aliasName- aliasName of Provider class- 返回:
- Provider instance
-
load
public void load()Load the Provider class from Provider configuration file -
toString
-