extract method to cache default extension name (#3456)
authorwanghbxxxx <wanghbxxxx@gmail.com>
Wed, 13 Feb 2019 02:48:19 +0000 (10:48 +0800)
committerXiaoJie Li <lixiaojie@apache.org>
Wed, 13 Feb 2019 02:48:19 +0000 (10:48 +0800)
dubbo-common/src/main/java/org/apache/dubbo/common/extension/ExtensionLoader.java

index 36c7707..e47e19d 100644 (file)
@@ -624,6 +624,22 @@ public class ExtensionLoader<T> {
 \r
     // synchronized in getExtensionClasses\r
     private Map<String, Class<?>> loadExtensionClasses() {\r
+        cacheDefaultExtensionName();\r
+\r
+        Map<String, Class<?>> extensionClasses = new HashMap<>();\r
+        loadDirectory(extensionClasses, DUBBO_INTERNAL_DIRECTORY, type.getName());\r
+        loadDirectory(extensionClasses, DUBBO_INTERNAL_DIRECTORY, type.getName().replace("org.apache", "com.alibaba"));\r
+        loadDirectory(extensionClasses, DUBBO_DIRECTORY, type.getName());\r
+        loadDirectory(extensionClasses, DUBBO_DIRECTORY, type.getName().replace("org.apache", "com.alibaba"));\r
+        loadDirectory(extensionClasses, SERVICES_DIRECTORY, type.getName());\r
+        loadDirectory(extensionClasses, SERVICES_DIRECTORY, type.getName().replace("org.apache", "com.alibaba"));\r
+        return extensionClasses;\r
+    }\r
+\r
+    /**\r
+     * extract and cache default extension name if exists\r
+     */\r
+    private void cacheDefaultExtensionName() {\r
         final SPI defaultAnnotation = type.getAnnotation(SPI.class);\r
         if (defaultAnnotation != null) {\r
             String value = defaultAnnotation.value();\r
@@ -638,15 +654,6 @@ public class ExtensionLoader<T> {
                 }\r
             }\r
         }\r
-\r
-        Map<String, Class<?>> extensionClasses = new HashMap<String, Class<?>>();\r
-        loadDirectory(extensionClasses, DUBBO_INTERNAL_DIRECTORY, type.getName());\r
-        loadDirectory(extensionClasses, DUBBO_INTERNAL_DIRECTORY, type.getName().replace("org.apache", "com.alibaba"));\r
-        loadDirectory(extensionClasses, DUBBO_DIRECTORY, type.getName());\r
-        loadDirectory(extensionClasses, DUBBO_DIRECTORY, type.getName().replace("org.apache", "com.alibaba"));\r
-        loadDirectory(extensionClasses, SERVICES_DIRECTORY, type.getName());\r
-        loadDirectory(extensionClasses, SERVICES_DIRECTORY, type.getName().replace("org.apache", "com.alibaba"));\r
-        return extensionClasses;\r
     }\r
 \r
     private void loadDirectory(Map<String, Class<?>> extensionClasses, String dir, String type) {\r