Pil0tXia commented on code in PR #4131:
URL: https://github.com/apache/eventmesh/pull/4131#discussion_r1308310611


##########
eventmesh-spi/src/main/java/org/apache/eventmesh/spi/EventMeshExtensionFactory.java:
##########
@@ -56,52 +57,72 @@ private EventMeshExtensionFactory() {
     }
 
     /**
-     * @param extensionType extension plugin class type
-     * @param extensionName extension instance name
-     * @param <T>           the type of the plugin
+     * Get an instance of an extension plugin.
+     *
+     * @param extensionClass extension plugin class type
+     * @param extensionName  extension instance name
+     * @param <T>            the type of the plugin
      * @return plugin instance
      */
-    public static <T> T getExtension(Class<T> extensionType, String 
extensionName) {
-        if (extensionType == null) {
-            throw new ExtensionException("extensionType is null");
+    public static <T> T getExtension(Class<T> extensionClass, String 
extensionName) {
+        if (extensionClass == null) {
+            throw new ExtensionException("extensionClass is null");
         }
         if (StringUtils.isEmpty(extensionName)) {
             throw new ExtensionException("extensionName is null");
         }
-        if (!extensionType.isInterface() || 
!extensionType.isAnnotationPresent(EventMeshSPI.class)) {
-            throw new ExtensionException(String.format("extensionType:%s is 
invalided", extensionType));
+        if (!extensionClass.isInterface() || 
!extensionClass.isAnnotationPresent(EventMeshSPI.class)) {
+            throw new ExtensionException(String.format("extensionClass:%s is 
invalided", extensionClass));
         }
-        EventMeshSPI eventMeshSPIAnnotation = 
extensionType.getAnnotation(EventMeshSPI.class);
+        EventMeshSPI eventMeshSPIAnnotation = 
extensionClass.getAnnotation(EventMeshSPI.class);
         if (eventMeshSPIAnnotation.isSingleton()) {
-            return getSingletonExtension(extensionType, extensionName);
+            return getSingletonExtension(extensionClass, 
eventMeshSPIAnnotation, extensionName);
         }
-        return getPrototypeExtension(extensionType, extensionName);
+        return getPrototypeExtension(extensionClass, extensionName);
     }
 
+    /**
+     * Get a singleton instance of an extension plugin.
+     *
+     * @param extensionClass the type of the extension plugin
+     * @param spi the type of the spi
+     * @param extensionInstanceName the name of the extension instance
+     * @param <T> the type of the extension plugin
+     * @return a singleton instance of the extension plugin
+     */
     @SuppressWarnings("unchecked")
-    private static <T> T getSingletonExtension(Class<T> extensionType, String 
extensionInstanceName) {
-        return (T) 
EXTENSION_INSTANCE_CACHE.computeIfAbsent(extensionInstanceName, name -> {
-            Class<T> extensionInstanceClass = 
getExtensionInstanceClass(extensionType, extensionInstanceName);
+    private static <T> T getSingletonExtension(Class<T> extensionClass, 
EventMeshSPI spi, String extensionInstanceName) {
+        return (T) EXTENSION_INSTANCE_CACHE.computeIfAbsent(new Extension(spi, 
extensionInstanceName), name -> {

Review Comment:
   @xwm1992 The main purpose of this PR is to change the cache key from String 
to an `Extension` class specified with its SPI annotation, in order to support 
**two extensions** loading in **one module**.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to