Skip to content

Commit

Permalink
Merge remote-tracking branch 'hujun-github/3.2-develop' into 3.2-develop
Browse files Browse the repository at this point in the history
  • Loading branch information
hujun-w-2 committed May 25, 2023
2 parents 65533a7 + 06d9673 commit 43e9722
Show file tree
Hide file tree
Showing 41 changed files with 704 additions and 114 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.apache.dubbo.common.utils.CollectionUtils;
import org.apache.dubbo.common.utils.StringUtils;

import java.util.AbstractMap;
import java.util.Arrays;
import java.util.BitSet;
import java.util.Collection;
Expand Down Expand Up @@ -247,7 +248,7 @@ public static Map<String, Map<String, String>> initMethodParameters(Map<String,
* copy-on-write mode, urlParam reference will be changed after modify actions.
* If wishes to get the result after modify, please use {@link URLParamMap#getUrlParam()}
*/
public static class URLParamMap implements Map<String, String> {
public static class URLParamMap extends AbstractMap<String, String> {
private URLParam urlParam;

public URLParamMap(URLParam urlParam) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -359,11 +359,11 @@ private static Object realize1(Object pojo, Class<?> type, Type genericType, fin
Map<String, Type> mapGeneric = new HashMap<>(8);
mapGeneric.putAll(mapParent);
TypeVariable<? extends Class<?>>[] typeParameters = type.getTypeParameters();
if(genericType instanceof ParameterizedType && typeParameters.length > 0) {
ParameterizedType parameterizedType = (ParameterizedType)genericType;
if (genericType instanceof ParameterizedType && typeParameters.length > 0) {
ParameterizedType parameterizedType = (ParameterizedType) genericType;
Type[] actualTypeArguments = parameterizedType.getActualTypeArguments();
for (int i = 0; i < typeParameters.length; i++) {
if(!(actualTypeArguments[i] instanceof TypeVariable)) {
if (!(actualTypeArguments[i] instanceof TypeVariable)) {
mapGeneric.put(typeParameters[i].getTypeName(), actualTypeArguments[i]);
}
}
Expand Down Expand Up @@ -534,26 +534,23 @@ private static Object realize1(Object pojo, Class<?> type, Type genericType, fin
Object value = entry.getValue();
if (value != null) {
Method method = getSetterMethod(dest.getClass(), name, value.getClass());
Field field = getField(dest.getClass(), name);
Field field = getAndCacheField(dest.getClass(), name);
if (method != null) {
if (!method.isAccessible()) {
method.setAccessible(true);
}
Type containType = mapGeneric.get(field.getGenericType().getTypeName());
if(containType != null) {
if (containType != null) {
//is generic
if(containType instanceof ParameterizedType) {
value = realize1(value, (Class<?>) ((ParameterizedType)containType).getRawType(), containType, mapGeneric, history);
}
else if (containType instanceof Class){
if (containType instanceof ParameterizedType) {
value = realize1(value, (Class<?>) ((ParameterizedType) containType).getRawType(), containType, mapGeneric, history);
} else if (containType instanceof Class) {
value = realize1(value, (Class<?>) containType, containType, mapGeneric, history);
}
else {
} else {
Type ptype = method.getGenericParameterTypes()[0];
value = realize1(value, method.getParameterTypes()[0], ptype, mapGeneric, history);
}
}
else {
} else {
Type ptype = method.getGenericParameterTypes()[0];
value = realize1(value, method.getParameterTypes()[0], ptype, mapGeneric, history);
}
Expand Down Expand Up @@ -626,15 +623,15 @@ private static Object newThrowableInstance(Class<?> cls, String message) {
try {
Constructor<?> messagedConstructor = cls.getDeclaredConstructor(String.class);
return messagedConstructor.newInstance(message);
} catch (Throwable t) {
} catch (Exception t) {
return newInstance(cls);
}
}

private static Object newInstance(Class<?> cls) {
try {
return cls.getDeclaredConstructor().newInstance();
} catch (Throwable t) {
} catch (Exception t) {
Constructor<?>[] constructors = cls.getDeclaredConstructors();
/*
From Javadoc java.lang.Class#getDeclaredConstructors
Expand All @@ -653,7 +650,7 @@ declared by the class represented by this Class object.
constructor.setAccessible(true);
Object[] parameters = Arrays.stream(constructor.getParameterTypes()).map(PojoUtils::getDefaultValue).toArray();
return constructor.newInstance(parameters);
} catch (Throwable e) {
} catch (Exception e) {
lastError = e;
}
}
Expand Down Expand Up @@ -704,12 +701,24 @@ private static Method getSetterMethod(Class<?> cls, String property, Class<?> va
return method;
}

private static Field getField(Class<?> cls, String fieldName) {
Field result = null;
private static Field getAndCacheField(Class<?> cls, String fieldName) {
Field result;
if (CLASS_FIELD_CACHE.containsKey(cls) && CLASS_FIELD_CACHE.get(cls).containsKey(fieldName)) {
return CLASS_FIELD_CACHE.get(cls).get(fieldName);
}
for(Class<?> acls = cls; acls != null; acls = acls.getSuperclass()) {

result = getField(cls, fieldName);

if (result != null) {
ConcurrentMap<String, Field> fields = CLASS_FIELD_CACHE.computeIfAbsent(cls, k -> new ConcurrentHashMap<>());
fields.putIfAbsent(fieldName, result);
}
return result;
}

private static Field getField(Class<?> cls, String fieldName) {
Field result = null;
for (Class<?> acls = cls; acls != null; acls = acls.getSuperclass()) {
try {
result = acls.getDeclaredField(fieldName);
if (!Modifier.isPublic(result.getModifiers())) {
Expand All @@ -718,19 +727,14 @@ private static Field getField(Class<?> cls, String fieldName) {
} catch (NoSuchFieldException e) {
}
}
if(result == null) {
if (result == null && cls != null) {
for (Field field : cls.getFields()) {
if (fieldName.equals(field.getName()) && ReflectUtils.isPublicInstanceField(field)) {
result = field;
break;
}
}
}

if (result != null) {
ConcurrentMap<String, Field> fields = CLASS_FIELD_CACHE.computeIfAbsent(cls, k -> new ConcurrentHashMap<>());
fields.putIfAbsent(fieldName, result);
}
return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,15 @@ private void checkClass(Set<Type> markedClass, Class<?> clazz) {

addToAllow(clazz.getName());

if (ClassUtils.isSimpleType(clazz) || clazz.isPrimitive() || clazz.isArray()) {
return;
}
String className = clazz.getName();
if (className.startsWith("java.") || className.startsWith("javax.") || className.startsWith("com.sun.") ||
className.startsWith("sun.") || className.startsWith("jdk.")) {
return;
}

Class<?>[] interfaces = clazz.getInterfaces();
for (Class<?> interfaceClass : interfaces) {
checkClass(markedClass, interfaceClass);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ void testURLParamMap() {
Assertions.assertFalse(urlParam1.getParameters().containsKey("aaa"));
Assertions.assertFalse(urlParam1.getParameters().containsKey("version"));
Assertions.assertFalse(urlParam1.getParameters().containsKey(new Object()));
Assertions.assertEquals(new HashMap<>(urlParam1.getParameters()).toString(), urlParam1.getParameters().toString());

URLParam urlParam2 = URLParam.parse("aaa=aaa&version=1.0");
URLParam.URLParamMap urlParam2Map = (URLParam.URLParamMap) urlParam2.getParameters();
Expand Down Expand Up @@ -284,6 +285,10 @@ void testURLParamMap() {

set.add(urlParam4.getParameters());
Assertions.assertEquals(2,set.size());

URLParam urlParam5 = URLParam.parse("version=1.0");
Assertions.assertEquals(new HashMap<>(urlParam5.getParameters()).toString(), urlParam5.getParameters().toString());

}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,45 @@

package com.alibaba.dubbo.rpc.cluster.loadbalance;

import com.alibaba.dubbo.common.Constants;
import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.rpc.Invocation;
import com.alibaba.dubbo.rpc.Invoker;
import com.alibaba.dubbo.rpc.cluster.LoadBalance;

import java.util.List;

@Deprecated
public abstract class AbstractLoadBalance extends org.apache.dubbo.rpc.cluster.loadbalance.AbstractLoadBalance {
public abstract class AbstractLoadBalance implements LoadBalance {

@Override
public <T> Invoker<T> select(List<Invoker<T>> invokers, URL url, Invocation invocation) {
if (invokers == null || invokers.size() == 0)
return null;
if (invokers.size() == 1)
return invokers.get(0);
return doSelect(invokers, url, invocation);
}

protected abstract <T> Invoker<T> doSelect(List<Invoker<T>> invokers, URL url, Invocation invocation);

protected int getWeight(Invoker<?> invoker, Invocation invocation) {
int weight = invoker.getUrl().getMethodParameter(invocation.getMethodName(), Constants.WEIGHT_KEY, Constants.DEFAULT_WEIGHT);
if (weight > 0) {
long timestamp = invoker.getUrl().getParameter(Constants.TIMESTAMP_KEY, 0L);
if (timestamp > 0L) {
int uptime = (int) (System.currentTimeMillis() - timestamp);
int warmup = invoker.getUrl().getParameter(Constants.WARMUP_KEY, Constants.DEFAULT_WARMUP);
if (uptime > 0 && uptime < warmup) {
weight = calculateWarmupWeight(uptime, warmup, weight);
}
}
}
return weight;
}

static int calculateWarmupWeight(int uptime, int warmup, int weight) {
int ww = (int) ( (float) uptime / ( (float) warmup / (float) weight ) );
return ww < 1 ? 1 : (ww > weight ? weight : ww);
}
}
2 changes: 1 addition & 1 deletion dubbo-config/dubbo-config-spring/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<description>The spring config module of dubbo project</description>
<properties>
<skip_maven_deploy>false</skip_maven_deploy>
<spring-boot.version>2.7.11</spring-boot.version>
<spring-boot.version>2.7.12</spring-boot.version>
<!-- Uncomment spring_version property to check Spring 4.x compatibility -->
<!-- <spring_version>4.3.30.RELEASE</spring_version> -->
</properties>
Expand Down
2 changes: 1 addition & 1 deletion dubbo-demo/dubbo-demo-annotation/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

<properties>
<skip_maven_deploy>true</skip_maven_deploy>
<spring-boot-maven-plugin.version>2.7.11</spring-boot-maven-plugin.version>
<spring-boot-maven-plugin.version>2.7.12</spring-boot-maven-plugin.version>
</properties>

<modules>
Expand Down
2 changes: 1 addition & 1 deletion dubbo-demo/dubbo-demo-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

<properties>
<skip_maven_deploy>true</skip_maven_deploy>
<spring-boot-maven-plugin.version>2.7.11</spring-boot-maven-plugin.version>
<spring-boot-maven-plugin.version>2.7.12</spring-boot-maven-plugin.version>
</properties>

<artifactId>dubbo-demo-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<slf4j-log4j12.version>1.7.33</slf4j-log4j12.version>
<spring-boot.version>2.7.11</spring-boot.version>
<spring-boot.version>2.7.12</spring-boot.version>
<skip_maven_deploy>true</skip_maven_deploy>
</properties>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<slf4j-log4j12.version>1.7.33</slf4j-log4j12.version>
<spring-boot.version>2.7.11</spring-boot.version>
<spring-boot.version>2.7.12</spring-boot.version>
<skip_maven_deploy>true</skip_maven_deploy>
</properties>

Expand Down
4 changes: 2 additions & 2 deletions dubbo-demo/dubbo-demo-spring-boot/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<skip_maven_deploy>true</skip_maven_deploy>
<spring-boot.version>2.7.11</spring-boot.version>
<spring-boot-maven-plugin.version>2.7.11</spring-boot-maven-plugin.version>
<spring-boot.version>2.7.12</spring-boot.version>
<spring-boot-maven-plugin.version>2.7.12</spring-boot-maven-plugin.version>
<micrometer-core.version>1.11.0</micrometer-core.version>
</properties>
<dependencyManagement>
Expand Down
2 changes: 1 addition & 1 deletion dubbo-demo/dubbo-demo-xml/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

<properties>
<skip_maven_deploy>true</skip_maven_deploy>
<spring-boot-maven-plugin.version>2.7.11</spring-boot-maven-plugin.version>
<spring-boot-maven-plugin.version>2.7.12</spring-boot-maven-plugin.version>
</properties>

<modules>
Expand Down
10 changes: 5 additions & 5 deletions dubbo-dependencies-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
<httpclient_version>4.5.14</httpclient_version>
<httpcore_version>4.4.16</httpcore_version>
<fastjson_version>1.2.83</fastjson_version>
<fastjson2_version>2.0.31</fastjson2_version>
<fastjson2_version>2.0.32</fastjson2_version>
<zookeeper_version>3.4.14</zookeeper_version>
<curator_version>4.3.0</curator_version>
<curator_test_version>2.12.0</curator_test_version>
Expand All @@ -114,7 +114,7 @@
<cxf_version>3.5.5</cxf_version>
<thrift_version>0.18.1</thrift_version>
<hessian_version>4.0.66</hessian_version>
<protobuf-java_version>3.23.0</protobuf-java_version>
<protobuf-java_version>3.23.1</protobuf-java_version>
<javax_annotation-api_version>1.3.2</javax_annotation-api_version>
<servlet_version>3.1.0</servlet_version>
<jetty_version>9.4.51.v20230217</jetty_version>
Expand All @@ -124,7 +124,7 @@
<hibernate_validator_new_version>7.0.5.Final</hibernate_validator_new_version>
<jel_version>3.0.1-b12</jel_version>
<jcache_version>1.1.1</jcache_version>
<kryo_version>4.0.2</kryo_version>
<kryo_version>4.0.3</kryo_version>
<kryo_serializers_version>0.45</kryo_serializers_version>
<fst_version>2.57</fst_version>
<avro_version>1.11.1</avro_version>
Expand Down Expand Up @@ -177,14 +177,14 @@
<test_container_version>1.18.1</test_container_version>
<etcd_launcher_version>0.7.5</etcd_launcher_version>
<hessian_lite_version>3.2.13</hessian_lite_version>
<swagger_version>1.6.10</swagger_version>
<swagger_version>1.6.11</swagger_version>

<snappy_java_version>1.1.9.1</snappy_java_version>
<bouncycastle-bcprov_version>1.70</bouncycastle-bcprov_version>
<metrics_version>2.0.6</metrics_version>
<sofa_registry_version>5.4.3</sofa_registry_version>
<gson_version>2.10.1</gson_version>
<jackson_version>2.15.0</jackson_version>
<jackson_version>2.15.1</jackson_version>
<jsonrpc_version>1.6</jsonrpc_version>
<mortbay_jetty_version>6.1.26</mortbay_jetty_version>
<portlet_version>2.0</portlet_version>
Expand Down
Loading

0 comments on commit 43e9722

Please sign in to comment.