修复负载均衡器的问题
This commit is contained in:
parent
87fc0e66b5
commit
d50e0cb44c
@ -15,15 +15,15 @@ public class ConsistencyHashBalance implements LoadBalance {
|
||||
private static final int VIRTUAL_NUM = 5;
|
||||
|
||||
// 虚拟节点分配,key是hash值,value是虚拟节点服务器名称
|
||||
private static SortedMap<Integer, String> shards = new TreeMap<Integer, String>();
|
||||
private SortedMap<Integer, String> shards = new TreeMap<Integer, String>();
|
||||
|
||||
// 真实节点列表
|
||||
private static List<String> realNodes = new LinkedList<String>();
|
||||
private List<String> realNodes = new LinkedList<String>();
|
||||
|
||||
//模拟初始服务器
|
||||
private static String[] servers =null;
|
||||
private String[] servers =null;
|
||||
|
||||
private static void init(List<String> serviceList) {
|
||||
private void init(List<String> serviceList) {
|
||||
for (String server :serviceList) {
|
||||
realNodes.add(server);
|
||||
System.out.println("真实节点[" + server + "] 被添加");
|
||||
@ -41,7 +41,7 @@ public class ConsistencyHashBalance implements LoadBalance {
|
||||
* @param node
|
||||
* @return
|
||||
*/
|
||||
public static String getServer(String node,List<String> serviceList) {
|
||||
public String getServer(String node,List<String> serviceList) {
|
||||
init(serviceList);
|
||||
int hash = getHash(node);
|
||||
Integer key = null;
|
||||
|
||||
@ -15,15 +15,15 @@ public class ConsistencyHashBalance implements LoadBalance {
|
||||
private static final int VIRTUAL_NUM = 5;
|
||||
|
||||
// 虚拟节点分配,key是hash值,value是虚拟节点服务器名称
|
||||
private static SortedMap<Integer, String> shards = new TreeMap<Integer, String>();
|
||||
private SortedMap<Integer, String> shards = new TreeMap<Integer, String>();
|
||||
|
||||
// 真实节点列表
|
||||
private static List<String> realNodes = new LinkedList<String>();
|
||||
private List<String> realNodes = new LinkedList<String>();
|
||||
|
||||
//模拟初始服务器
|
||||
private static String[] servers =null;
|
||||
private String[] servers =null;
|
||||
|
||||
private static void init(List<String> serviceList) {
|
||||
private void init(List<String> serviceList) {
|
||||
for (String server :serviceList) {
|
||||
realNodes.add(server);
|
||||
System.out.println("真实节点[" + server + "] 被添加");
|
||||
@ -41,7 +41,7 @@ public class ConsistencyHashBalance implements LoadBalance {
|
||||
* @param node
|
||||
* @return
|
||||
*/
|
||||
public static String getServer(String node,List<String> serviceList) {
|
||||
public String getServer(String node,List<String> serviceList) {
|
||||
init(serviceList);
|
||||
int hash = getHash(node);
|
||||
Integer key = null;
|
||||
|
||||
@ -15,15 +15,15 @@ public class ConsistencyHashBalance implements LoadBalance {
|
||||
private static final int VIRTUAL_NUM = 5;
|
||||
|
||||
// 虚拟节点分配,key是hash值,value是虚拟节点服务器名称
|
||||
private static SortedMap<Integer, String> shards = new TreeMap<Integer, String>();
|
||||
private SortedMap<Integer, String> shards = new TreeMap<Integer, String>();
|
||||
|
||||
// 真实节点列表
|
||||
private static List<String> realNodes = new LinkedList<String>();
|
||||
private List<String> realNodes = new LinkedList<String>();
|
||||
|
||||
//模拟初始服务器
|
||||
private static String[] servers =null;
|
||||
private String[] servers =null;
|
||||
|
||||
private static void init(List<String> serviceList) {
|
||||
private void init(List<String> serviceList) {
|
||||
for (String server :serviceList) {
|
||||
realNodes.add(server);
|
||||
System.out.println("真实节点[" + server + "] 被添加");
|
||||
@ -41,7 +41,7 @@ public class ConsistencyHashBalance implements LoadBalance {
|
||||
* @param node
|
||||
* @return
|
||||
*/
|
||||
public static String getServer(String node,List<String> serviceList) {
|
||||
public String getServer(String node,List<String> serviceList) {
|
||||
init(serviceList);
|
||||
int hash = getHash(node);
|
||||
Integer key = null;
|
||||
@ -60,7 +60,7 @@ public class ConsistencyHashBalance implements LoadBalance {
|
||||
*
|
||||
* @param node
|
||||
*/
|
||||
public void addNode(String node) {
|
||||
public void addNode(String node) {
|
||||
if (!realNodes.contains(node)) {
|
||||
realNodes.add(node);
|
||||
System.out.println("真实节点[" + node + "] 上线添加");
|
||||
|
||||
Loading…
Reference in New Issue
Block a user