[fix] some statement can be simplified (#10525)
This commit is contained in:
parent
a159af592e
commit
e5b1caf583
|
|
@ -43,8 +43,9 @@ public class RandomLoadBalance extends AbstractLoadBalance {
|
|||
|
||||
/**
|
||||
* Select one invoker between a list using a random criteria
|
||||
* @param invokers List of possible invokers
|
||||
* @param url URL
|
||||
*
|
||||
* @param invokers List of possible invokers
|
||||
* @param url URL
|
||||
* @param invocation Invocation
|
||||
* @param <T>
|
||||
* @return The selected invoker
|
||||
|
|
@ -54,7 +55,7 @@ public class RandomLoadBalance extends AbstractLoadBalance {
|
|||
// Number of invokers
|
||||
int length = invokers.size();
|
||||
|
||||
if (!needWeightLoadBalance(invokers,invocation)){
|
||||
if (!needWeightLoadBalance(invokers, invocation)) {
|
||||
return invokers.get(ThreadLocalRandom.current().nextInt(length));
|
||||
}
|
||||
|
||||
|
|
@ -89,8 +90,7 @@ public class RandomLoadBalance extends AbstractLoadBalance {
|
|||
}
|
||||
|
||||
private <T> boolean needWeightLoadBalance(List<Invoker<T>> invokers, Invocation invocation) {
|
||||
|
||||
Invoker invoker = invokers.get(0);
|
||||
Invoker<T> invoker = invokers.get(0);
|
||||
URL invokerUrl = invoker.getUrl();
|
||||
if (invoker instanceof ClusterInvoker) {
|
||||
invokerUrl = ((ClusterInvoker<?>) invoker).getRegistryUrl();
|
||||
|
|
@ -99,22 +99,15 @@ public class RandomLoadBalance extends AbstractLoadBalance {
|
|||
// Multiple registry scenario, load balance among multiple registries.
|
||||
if (REGISTRY_SERVICE_REFERENCE_PATH.equals(invokerUrl.getServiceInterface())) {
|
||||
String weight = invokerUrl.getParameter(WEIGHT_KEY);
|
||||
if (StringUtils.isNotEmpty(weight)) {
|
||||
return true;
|
||||
}
|
||||
return StringUtils.isNotEmpty(weight);
|
||||
} else {
|
||||
String weight = invokerUrl.getMethodParameter(invocation.getMethodName(), WEIGHT_KEY);
|
||||
if (StringUtils.isNotEmpty(weight)) {
|
||||
return true;
|
||||
}else {
|
||||
} else {
|
||||
String timeStamp = invoker.getUrl().getParameter(TIMESTAMP_KEY);
|
||||
if (StringUtils.isNotEmpty(timeStamp)) {
|
||||
return true;
|
||||
}
|
||||
return StringUtils.isNotEmpty(timeStamp);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue