dubbo related SPI

SPI : The full name is (Service Provider Interface), which is a service provider discovery mechanism built into the JDK. At present, many frameworks use it for service extension discovery. In short, it is a mechanism for dynamically replacing discovery. For example, if there is an interface, you want to dynamically add implementation to it when you start the runtime. Just add an implementation, and then describe the newly added implementation to the JDK (by changing a configuration text file)

com.alibaba.dubbo.container.Main is the main class for service startup. An ExtensionLoader<Container> object is defined in the object, which will be obtained from the /META-INF/dubbo/internal/com.alibaba.dubbo.container.Container configuration file Container and start.

Reference: ExtensionLoader is the internal SPI implementation of dubbo, many objects are generated by this class, the more common Filter, etc., and supports custom Filter. Therefore, in dubbo, the functions that need to be extended are generally annotated with @SPI on the interface.

@SPI("netty")
public interface Transporter {...}

@SPI
public interface Filter {...}

@SPI("javassist")
public interface ProxyFactory {...}

@SPI("spring")
public interface Container {...}

 In the code, ExtensionLoader.getExtensionLoader(Transporter.class).getAdaptiveExtension() is often used to obtain the required object, and getExtensionClasses() is used to obtain the corresponding Class. During the calling process, the loadExtensionClasses()->loadFile() method is to obtain the interface instance Corresponding to Class, and will read the default implementation class on the interface. Load Class through reflection.

Class<?> clazz = Class.forName(line, true, classLoader);

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326693288&siteId=291194637