【Java项目】多文件传输:资源注册中心@资源网络节点

资源网络节点是针对拥有资源拥有者,资源拥有者将自己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 +
                '}';
    }
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值