Skip to content

Commit

Permalink
[fix] some statement can be simplified (#10525)
Browse files Browse the repository at this point in the history
  • Loading branch information
llnancy committed Sep 2, 2022
1 parent a159af5 commit e5b1caf
Showing 1 changed file with 8 additions and 15 deletions.
Expand Up @@ -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
Expand All @@ -54,7 +55,7 @@ protected <T> Invoker<T> doSelect(List<Invoker<T>> invokers, URL url, Invocation
// Number of invokers
int length = invokers.size();

if (!needWeightLoadBalance(invokers,invocation)){
if (!needWeightLoadBalance(invokers, invocation)) {
return invokers.get(ThreadLocalRandom.current().nextInt(length));
}

Expand Down Expand Up @@ -89,8 +90,7 @@ protected <T> Invoker<T> doSelect(List<Invoker<T>> invokers, URL url, Invocation
}

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();
Expand All @@ -99,22 +99,15 @@ private <T> boolean needWeightLoadBalance(List<Invoker<T>> invokers, Invocation
// 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;
}


}

0 comments on commit e5b1caf

Please sign in to comment.