All Downloads are FREE. Search and download functionalities are using the official Maven repository.

top.yqingyu.trans$client.api.ConnectionConfig Maven / Gradle / Ivy

package top.yqingyu.trans$client.api;


import top.yqingyu.common.qydata.DataMap;
import top.yqingyu.common.qymsg.*;
import top.yqingyu.common.utils.UUIDUtil;
import top.yqingyu.common.utils.YamlUtil;

import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.atomic.AtomicBoolean;

public class ConnectionConfig {
    public final String CLIENT_USER_ID = UUIDUtil.randomUUID().toString2();
    public final AtomicBoolean RUNNING = new AtomicBoolean(true);
    public volatile String AC_STR = "okkkko";
    public String HEART_BEAT = "HEART_BEAT";
    public String HOST = "127.0.0.1";
    public int PORT = 4729;
    public int PORT2 = 4730;
    public int PORT3 = 4731;
    public DataMap loginData = new DataMap();

    public volatile int BODY_LENGTH_MAX = 65536 * 100;
    //以下时间为毫秒
    public volatile int PARTITION_CLEAN_TIME = 30 * 60 * 1000;
    public volatile int HEADER_BODY_INTERVAL = 50;

    public volatile int LOGIN_TIMEOUT = 9000;   //登陆超时时间
    public volatile int MSG_TIMEOUT = 5000;   //消息超时时间
    public volatile int HEART_BEAT_TIME = 15000;   //心跳时间
    public volatile int MSG_DEAL_TIME = 10;   //消息接收发送线程时间间隔
    public Type type = Type.INSTANCE;

    public enum Type {
        FILE, //配置文件读取。
        INSTANCE //创建固定实例。
    }

    public boolean pooling = false;

    public short pool_max = 10;
    public short pool_min = 2;
    public long keep_live_time = 3600 * 24;

    public final LinkedBlockingQueue Main_PartitionMsgQueue = new LinkedBlockingQueue<>();
    public final LinkedBlockingQueue REQ_MSG_QUEUE = new LinkedBlockingQueue<>();
    public final LinkedBlockingQueue RSP_MSG_QUEUE = new LinkedBlockingQueue<>();

    public QyMsg AC_MSG = new QyMsg(MsgType.AC, DataType.JSON);
    public QyMsg NORMAL_MSG = new QyMsg(MsgType.NORM_MSG, DataType.JSON);
    public QyMsg HEART_BEAT_MSG = new QyMsg(MsgType.HEART_BEAT, DataType.JSON);

    public volatile String DEFAULT_DOWNLOAD_PATH = System.getProperty("user.dir");

    private ConnectionConfig() {
    }

    public static ConnectionConfig build(Type type) {
        return build(type, new DataMap());
    }

    public static ConnectionConfig build(Type type, DataMap loginData) {

        ConnectionConfig cfg = new ConnectionConfig();
        if (Type.FILE.equals(type)) {
            YamlUtil client_yml = YamlUtil.loadYaml("client", YamlUtil.LoadType.BOTH);
            DataMap client = client_yml.getDataMap("trans_client.yml").getData("client");

            cfg.AC_STR = client.getString("ac_str");
            cfg.HEART_BEAT = client.getString("heart_beat");

            cfg.HOST = client.getString("host");
            cfg.PORT = client.getData("main").getIntValue("port");
            cfg.PORT2 = client.getData("sc").getIntValue("port");
            cfg.PORT3 = client.getData("cs").getIntValue("port");

            cfg.BODY_LENGTH_MAX = client.getData("main").getIntValue("body-length-max");
            cfg.PARTITION_CLEAN_TIME = client.getData("cs").getDataMap("msg").getIntValue("partition-clean-time");
            cfg.HEADER_BODY_INTERVAL = client.getData("cs").getDataMap("msg").getIntValue("header-body-interval");


            DataMap time_set = client.getData("main").getData("time_set");
            cfg.LOGIN_TIMEOUT = time_set.getIntValue("login_timeout");
            cfg.MSG_TIMEOUT = time_set.getIntValue("msg_timeout");
            cfg.HEART_BEAT_TIME = time_set.getIntValue("heart_beat_time");
            cfg.MSG_DEAL_TIME = time_set.getIntValue("msg_deal_time");
            cfg.DEFAULT_DOWNLOAD_PATH = client.getString("def-download-path",System.getProperty("user.dir"));
        }

        MsgTransfer.init(32, cfg.BODY_LENGTH_MAX);
        cfg.loginData = loginData;
        cfg.HEART_BEAT_MSG.setFrom(cfg.CLIENT_USER_ID);
        cfg.HEART_BEAT_MSG.putMsg(cfg.HEART_BEAT);
        cfg.AC_MSG.setFrom(cfg.CLIENT_USER_ID);
        cfg.AC_MSG.putMsg(cfg.AC_STR);
        cfg.NORMAL_MSG.setFrom(cfg.CLIENT_USER_ID);
        MsgHelper.init(cfg.Main_PartitionMsgQueue, cfg.RSP_MSG_QUEUE, "MainPartitionAssB", cfg.RUNNING, cfg.PARTITION_CLEAN_TIME);
        return cfg;
    }

    public String getCLIENT_USER_ID() {
        return CLIENT_USER_ID;
    }

    public AtomicBoolean getRUNNING() {
        return RUNNING;
    }

    public String getAC_STR() {
        return AC_STR;
    }

    public void setAC_STR(String AC_STR) {
        this.AC_STR = AC_STR;
    }

    public String getHEART_BEAT() {
        return HEART_BEAT;
    }

    public void setHEART_BEAT(String HEART_BEAT) {
        this.HEART_BEAT = HEART_BEAT;
    }

    public String getHOST() {
        return HOST;
    }

    public void setHOST(String HOST) {
        this.HOST = HOST;
    }

    public int getPORT() {
        return PORT;
    }

    public void setPORT(int PORT) {
        this.PORT = PORT;
    }

    public int getPORT2() {
        return PORT2;
    }

    public void setPORT2(int PORT2) {
        this.PORT2 = PORT2;
    }

    public int getPORT3() {
        return PORT3;
    }

    public void setPORT3(int PORT3) {
        this.PORT3 = PORT3;
    }

    public int getBODY_LENGTH_MAX() {
        return BODY_LENGTH_MAX;
    }

    public void setBODY_LENGTH_MAX(int BODY_LENGTH_MAX) {
        this.BODY_LENGTH_MAX = BODY_LENGTH_MAX;
    }

    public int getPARTITION_CLEAN_TIME() {
        return PARTITION_CLEAN_TIME;
    }

    public void setPARTITION_CLEAN_TIME(int PARTITION_CLEAN_TIME) {
        this.PARTITION_CLEAN_TIME = PARTITION_CLEAN_TIME;
    }

    public int getHEADER_BODY_INTERVAL() {
        return HEADER_BODY_INTERVAL;
    }

    public void setHEADER_BODY_INTERVAL(int HEADER_BODY_INTERVAL) {
        this.HEADER_BODY_INTERVAL = HEADER_BODY_INTERVAL;
    }

    public int getLOGIN_TIMEOUT() {
        return LOGIN_TIMEOUT;
    }

    public void setLOGIN_TIMEOUT(int LOGIN_TIMEOUT) {
        this.LOGIN_TIMEOUT = LOGIN_TIMEOUT;
    }

    public int getMSG_TIMEOUT() {
        return MSG_TIMEOUT;
    }

    public void setMSG_TIMEOUT(int MSG_TIMEOUT) {
        this.MSG_TIMEOUT = MSG_TIMEOUT;
    }

    public int getHEART_BEAT_TIME() {
        return HEART_BEAT_TIME;
    }

    public void setHEART_BEAT_TIME(int HEART_BEAT_TIME) {
        this.HEART_BEAT_TIME = HEART_BEAT_TIME;
    }

    public int getMSG_DEAL_TIME() {
        return MSG_DEAL_TIME;
    }

    public void setMSG_DEAL_TIME(int MSG_DEAL_TIME) {
        this.MSG_DEAL_TIME = MSG_DEAL_TIME;
    }

    public Type getCfgType() {
        return type;
    }

    public void setCfgType(Type type) {
        this.type = type;
    }

    public boolean isPooling() {
        return pooling;
    }

    public void setPooling(boolean pooling) {
        this.pooling = pooling;
    }

    public short getPool_max() {
        return pool_max;
    }

    public void setPool_max(byte pool_max) {
        this.pool_max = pool_max;
    }

    public short getPool_min() {
        return pool_min;
    }

    public void setPool_min(byte pool_min) {
        this.pool_min = pool_min;
    }

    public long getKeep_live_time() {
        return keep_live_time;
    }

    public void setKeep_live_time(long keep_live_time) {
        this.keep_live_time = keep_live_time;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy