Skip to content
Snippets Groups Projects
Commit ab6d7646 authored by Recolic Keghart's avatar Recolic Keghart
Browse files

init

parent 295f3718
No related branches found
No related tags found
No related merge requests found
Pipeline #743 failed with stages
in 3 minutes and 47 seconds
......@@ -6,6 +6,7 @@ import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.RpcException;
import org.apache.dubbo.rpc.cluster.LoadBalance;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ThreadLocalRandom;
......@@ -18,9 +19,11 @@ import java.util.concurrent.ThreadLocalRandom;
* 选手需要基于此类实现自己的负载均衡算法
*/
public class UserLoadBalance implements LoadBalance {
private int n = 0;
private int[] peers = {0,0,0,1,1,2};
@Override
public <T> Invoker<T> select(List<Invoker<T>> invokers, URL url, Invocation invocation) throws RpcException {
return invokers.get(ThreadLocalRandom.current().nextInt(invokers.size()));
++n;
return invokers.get(peers[n%6]);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment