Skip to content

Commit

Permalink
Merge 085e6c2 into ce4fb5d
Browse files Browse the repository at this point in the history
  • Loading branch information
laijianbin committed Dec 12, 2017
2 parents ce4fb5d + 085e6c2 commit 2b6c106
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,17 +89,16 @@ public LoadbalanceHandler() {

@Override
public void handle(Invocation invocation, AsyncResponse asyncResp) throws Exception {
String p = Configuration.INSTANCE.getPolicy(invocation.getMicroserviceName());
String policy = Configuration.INSTANCE.getPolicy(invocation.getMicroserviceName());
String strategy = Configuration.INSTANCE.getRuleStrategyName(invocation.getMicroserviceName());

if (this.policy != null && !this.policy.equals(p)
|| (this.strategy != null && !this.strategy.equals(strategy))) {
if (!isNotChanged(policy,strategy)){
//配置变化,需要重新生成所有的lb实例
synchronized (lock) {
loadBalancerMap.clear();
}
}
this.policy = p;
this.policy = policy;
this.strategy = strategy;

LoadBalancer loadBalancer = getOrCreateLoadBalancer(invocation);
Expand Down Expand Up @@ -350,4 +349,15 @@ private void loadFilter(String filter, LoadBalancer lb) {
}
}
}
public boolean isNotChanged(String loadbalancePolicy, String loadbalanceStrategy) {
//不考虑policy和strategy混合使用的情况(policy和strategy都不为null)
if (loadbalancePolicy == null && loadbalanceStrategy == null) {
return this.policy == null && this.strategy == null;
}
if (loadbalancePolicy != null && loadbalanceStrategy == null) {
return loadbalancePolicy.equals(this.policy) && this.strategy == null;
}
return loadbalanceStrategy.equals(this.strategy) && this.policy == null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -436,4 +436,15 @@ public void sendWithRetry() {

// no exception
}
@Test
public void testIsNotChanged() {
boolean nullResult = handler.isNotChanged(null, null);
Assert.assertEquals(true, nullResult);

boolean strategyNullResult = handler.isNotChanged("com.netflix.loadbalancer.RandomRule", null);
Assert.assertEquals(false, strategyNullResult);

boolean policyNullResult = handler.isNotChanged(null, "Random");
Assert.assertEquals(false, policyNullResult);
}
}

0 comments on commit 2b6c106

Please sign in to comment.