资源网络节点是针对拥有资源拥有者,资源拥有者将自己id、port、连接情况和资源列表信息提供给注册中心。注册中心以便选取最佳的接收端。
一、资源网络节点基本信息
package man.kuke.registry;
/**
* @author: kuke
* @date: 2020/12/5 - 19:06
* @description:
*/
public interface INodeAddress {
INodeAddress setIp(String ip);
INodeAddress setPort(int port);
String getIp();
int getPort();
}
二、资源节点健康值
用于描述接收端负载连接情况,接收端可向资源资源注册中心汇报;注册中心根据其选择连接较少的接收端。其目的:为了实现接收端负载平衡。
package man.kuke.registry;
/**
* @author: kuke
* @date: 2020/12/5 - 19:08
* @description:
*/
public interface IResourceNodeAddress extends INodeAddress {
int SERVER = 1;
int NORMAL = 2;
int MIN_HEALTH = 10;
int MAX_HEALTH = 1;
IResourceNodeAddress setType(int type);
int getType();
IResourceNodeAddress setHealth(int health);
int getHealth();
}
三、资源节点
package man.kuke.registry;
/**
* @author: kuke
* @date: 2020/12/5 - 19:09
* @description:
*/
public class Node implements IResourceNodeAddress {
private String ip;
private int port;
private int type;
private int health;
@Override
public IResourceNodeAddress setType(int type) {
this.type = type;
return this;
}
@Override
public int getType() {
return this.type;
}
@Override
public IResourceNodeAddress setHealth(int health) {
this.health =health;
return this;
}
@Override
public int getHealth() {
return this.health;
}
@Override
public INodeAddress setIp(String ip) {
this.ip = ip;
return this;
}
@Override
public INodeAddress setPort(int port) {
this.ip = ip;
return this;
}
@Override
public String getIp() {
return this.ip;
}
@Override
public int getPort() {
return port;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((ip == null) ? 0 : ip.hashCode());
result = prime * result + port;
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Node other = (Node) obj;
if (ip == null) {
if (other.ip != null)
return false;
} else if (!ip.equals(other.ip))
return false;
return port == other.port;
}
@Override
public String toString() {
return "Node{" +
"ip='" + ip + '\'' +
", port=" + port +
", type=" + type +
", health=" + health +
'}';
}
}