You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by al...@apache.org on 2021/08/09 06:40:46 UTC
[dubbo] branch 3.0 updated: Compact with adaptive extensions when
ApplicationModel is null (#8454)
This is an automated email from the ASF dual-hosted git repository.
albumenj pushed a commit to branch 3.0
in repository https://gitbox.apache.org/repos/asf/dubbo.git
The following commit(s) were added to refs/heads/3.0 by this push:
new 0a07eae Compact with adaptive extensions when ApplicationModel is null (#8454)
0a07eae is described below
commit 0a07eaee651a263fd05c1b173b29ed220539d4dd
Author: Albumen Kevin <jh...@gmail.com>
AuthorDate: Mon Aug 9 14:40:31 2021 +0800
Compact with adaptive extensions when ApplicationModel is null (#8454)
---
.../dubbo/common/extension/ExtensionLoader.java | 65 +++++++++++-----------
1 file changed, 32 insertions(+), 33 deletions(-)
diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/extension/ExtensionLoader.java b/dubbo-common/src/main/java/org/apache/dubbo/common/extension/ExtensionLoader.java
index 14ac2d8..d2beedc 100644
--- a/dubbo-common/src/main/java/org/apache/dubbo/common/extension/ExtensionLoader.java
+++ b/dubbo-common/src/main/java/org/apache/dubbo/common/extension/ExtensionLoader.java
@@ -136,8 +136,8 @@ public class ExtensionLoader<T> {
*/
private static LoadingStrategy[] loadLoadingStrategies() {
return stream(load(LoadingStrategy.class).spliterator(), false)
- .sorted()
- .toArray(LoadingStrategy[]::new);
+ .sorted()
+ .toArray(LoadingStrategy[]::new);
}
/**
@@ -171,7 +171,7 @@ public class ExtensionLoader<T> {
}
if (!withExtensionAnnotation(type)) {
throw new IllegalArgumentException("Extension type (" + type +
- ") is not an extension, because it is NOT annotated with @" + SPI.class.getSimpleName() + "!");
+ ") is not an extension, because it is NOT annotated with @" + SPI.class.getSimpleName() + "!");
}
ExtensionLoader<T> loader = (ExtensionLoader<T>) EXTENSION_LOADERS.get(type);
@@ -309,11 +309,11 @@ public class ExtensionLoader<T> {
}
// traverse all cached extensions
- cachedActivateGroups.forEach((name, activateGroup)->{
+ cachedActivateGroups.forEach((name, activateGroup) -> {
if (isMatchGroup(group, activateGroup)
- && !names.contains(name)
- && !names.contains(REMOVE_VALUE_PREFIX + name)
- && isActive(cachedActivateValues.get(name), url)) {
+ && !names.contains(name)
+ && !names.contains(REMOVE_VALUE_PREFIX + name)
+ && isActive(cachedActivateValues.get(name), url)) {
activateExtensionsMap.put(getExtensionClass(name), getExtension(name));
}
@@ -378,7 +378,7 @@ public class ExtensionLoader<T> {
if (StringUtils.isEmpty(group)) {
return true;
}
- if(CollectionUtils.isNotEmpty(groups)){
+ if (CollectionUtils.isNotEmpty(groups)) {
return groups.contains(group);
}
return false;
@@ -567,11 +567,11 @@ public class ExtensionLoader<T> {
if (!type.isAssignableFrom(clazz)) {
throw new IllegalStateException("Input type " +
- clazz + " doesn't implement the Extension " + type);
+ clazz + " doesn't implement the Extension " + type);
}
if (clazz.isInterface()) {
throw new IllegalStateException("Input type " +
- clazz + " can't be interface!");
+ clazz + " can't be interface!");
}
if (!clazz.isAnnotationPresent(Adaptive.class)) {
@@ -580,7 +580,7 @@ public class ExtensionLoader<T> {
}
if (cachedClasses.get().containsKey(name)) {
throw new IllegalStateException("Extension name " +
- name + " already exists (Extension " + type + ")!");
+ name + " already exists (Extension " + type + ")!");
}
cachedNames.put(clazz, name);
@@ -608,11 +608,11 @@ public class ExtensionLoader<T> {
if (!type.isAssignableFrom(clazz)) {
throw new IllegalStateException("Input type " +
- clazz + " doesn't implement Extension " + type);
+ clazz + " doesn't implement Extension " + type);
}
if (clazz.isInterface()) {
throw new IllegalStateException("Input type " +
- clazz + " can't be interface!");
+ clazz + " can't be interface!");
}
if (!clazz.isAnnotationPresent(Adaptive.class)) {
@@ -621,7 +621,7 @@ public class ExtensionLoader<T> {
}
if (!cachedClasses.get().containsKey(name)) {
throw new IllegalStateException("Extension name " +
- name + " doesn't exist (Extension " + type + ")!");
+ name + " doesn't exist (Extension " + type + ")!");
}
cachedNames.put(clazz, name);
@@ -643,8 +643,8 @@ public class ExtensionLoader<T> {
if (instance == null) {
if (createAdaptiveInstanceError != null) {
throw new IllegalStateException("Failed to create adaptive instance: " +
- createAdaptiveInstanceError.toString(),
- createAdaptiveInstanceError);
+ createAdaptiveInstanceError.toString(),
+ createAdaptiveInstanceError);
}
synchronized (cachedAdaptiveInstance) {
@@ -716,7 +716,7 @@ public class ExtensionLoader<T> {
for (Class<?> wrapperClass : wrapperClassesList) {
Wrapper wrapper = wrapperClass.getAnnotation(Wrapper.class);
if (wrapper == null
- || (ArrayUtils.contains(wrapper.matches(), name) && !ArrayUtils.contains(wrapper.mismatches(), name))) {
+ || (ArrayUtils.contains(wrapper.matches(), name) && !ArrayUtils.contains(wrapper.mismatches(), name))) {
instance = injectExtension((T) wrapperClass.getConstructor(type).newInstance(instance));
}
}
@@ -727,7 +727,7 @@ public class ExtensionLoader<T> {
return instance;
} catch (Throwable t) {
throw new IllegalStateException("Extension instance (name: " + name + ", class: " +
- type + ") couldn't be instantiated: " + t.getMessage(), t);
+ type + ") couldn't be instantiated: " + t.getMessage(), t);
}
}
@@ -765,7 +765,7 @@ public class ExtensionLoader<T> {
}
} catch (Exception e) {
logger.error("Failed to inject via method " + method.getName()
- + " of interface " + type.getName() + ": " + e.getMessage(), e);
+ + " of interface " + type.getName() + ": " + e.getMessage(), e);
}
}
@@ -802,8 +802,8 @@ public class ExtensionLoader<T> {
*/
private boolean isSetter(Method method) {
return method.getName().startsWith("set")
- && method.getParameterTypes().length == 1
- && Modifier.isPublic(method.getModifiers());
+ && method.getParameterTypes().length == 1
+ && Modifier.isPublic(method.getModifiers());
}
private Class<?> getExtensionClass(String name) {
@@ -860,7 +860,7 @@ public class ExtensionLoader<T> {
String[] names = NAME_SEPARATOR.split(value);
if (names.length > 1) {
throw new IllegalStateException("More than 1 default extension name on extension " + type.getName()
- + ": " + Arrays.toString(names));
+ + ": " + Arrays.toString(names));
}
if (names.length == 1) {
cachedDefaultName = names[0];
@@ -903,7 +903,7 @@ public class ExtensionLoader<T> {
}
} catch (Throwable t) {
logger.error("Exception occurred when loading extension class (interface: " +
- type + ", description file: " + fileName + ").", t);
+ type + ", description file: " + fileName + ").", t);
}
}
@@ -941,7 +941,7 @@ public class ExtensionLoader<T> {
}
} catch (Throwable t) {
logger.error("Exception occurred when loading extension class (interface: " +
- type + ", class file: " + resourceURL + ") in " + resourceURL, t);
+ type + ", class file: " + resourceURL + ") in " + resourceURL, t);
}
}
@@ -960,8 +960,8 @@ public class ExtensionLoader<T> {
boolean overridden) throws NoSuchMethodException {
if (!type.isAssignableFrom(clazz)) {
throw new IllegalStateException("Error occurred when loading extension class (interface: " +
- type + ", class line: " + clazz.getName() + "), class "
- + clazz.getName() + " is not subtype of interface.");
+ type + ", class line: " + clazz.getName() + "), class "
+ + clazz.getName() + " is not subtype of interface.");
}
if (clazz.isAnnotationPresent(Adaptive.class)) {
cacheAdaptiveClass(clazz, overridden);
@@ -1038,8 +1038,8 @@ public class ExtensionLoader<T> {
cachedAdaptiveClass = clazz;
} else if (!cachedAdaptiveClass.equals(clazz)) {
throw new IllegalStateException("More than 1 adaptive class found: "
- + cachedAdaptiveClass.getName()
- + ", " + clazz.getName());
+ + cachedAdaptiveClass.getName()
+ + ", " + clazz.getName());
}
}
@@ -1102,13 +1102,12 @@ public class ExtensionLoader<T> {
private Class<?> createAdaptiveExtensionClass() {
ClassLoader classLoader = findClassLoader();
- if (ApplicationModel.getEnvironment().getConfiguration().getBoolean(NATIVE, false)) {
- try {
+ try {
+ if (ApplicationModel.getEnvironment().getConfiguration().getBoolean(NATIVE, false)) {
return classLoader.loadClass(type.getName() + "$Adaptive");
- } catch (ClassNotFoundException e) {
- //ignore
- e.printStackTrace();
}
+ } catch (Throwable ignore) {
+
}
String code = new AdaptiveClassCodeGenerator(type, cachedDefaultName).generate();
org.apache.dubbo.common.compiler.Compiler compiler = ExtensionLoader.getExtensionLoader(org.apache.dubbo.common.compiler.Compiler.class).getAdaptiveExtension();