类 SpiLoader<S>

java.lang.Object
com.alibaba.csp.sentinel.spi.SpiLoader<S>

public final class SpiLoader<S> extends Object
A simple SPI loading facility (refactored since 1.8.1).

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
另请参阅:
  • 方法详细资料

    • of

      public static <T> SpiLoader<T> of(Class<T> service)
      Create SpiLoader instance via Service class Cached by className, and load from cache first
      类型参数:
      T - Service type
      参数:
      service - Service class
      返回:
      SpiLoader instance
    • loadInstanceList

      public List<S> loadInstanceList()
      Load all Provider instances of the specified Service
      返回:
      Provider instances list
    • loadInstanceListSorted

      public List<S> loadInstanceListSorted()
      Load all Provider instances of the specified Service, sorted by order value in class's Spi annotation
      返回:
      Sorted Provider instances list
    • loadHighestPriorityInstance

      public S loadHighestPriorityInstance()
      Load highest order priority instance, order value is defined in class's Spi annotation
      返回:
      Provider instance of highest order priority
    • loadLowestPriorityInstance

      public S loadLowestPriorityInstance()
      Load lowest order priority instance, order value is defined in class's Spi annotation
      返回:
      Provider instance of lowest order priority
    • loadFirstInstance

      public S loadFirstInstance()
      Load the first-found Provider instance
      返回:
      Provider instance of first-found specific
    • loadFirstInstanceOrDefault

      public S loadFirstInstanceOrDefault()
      Load the first-found Provider instance,if not found, return default Provider instance
      返回:
      Provider instance
    • loadDefaultInstance

      public S loadDefaultInstance()
      Load default Provider instance Provider class with @Spi(isDefault = true)
      返回:
      default Provider instance
    • loadInstance

      public S loadInstance(Class<? extends S> clazz)
      Load instance by specific class type
      参数:
      clazz - class type
      返回:
      Provider instance
    • loadInstance

      public S loadInstance(String aliasName)
      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

      public String toString()
      覆盖:
      toString 在类中 Object