liurunyu
2023-11-29 f2df44d7b3865cafe86baa48e19d1df0c0723702
pipIrr-mwTest-client阶段提交
3 文件已重命名
10个文件已修改
16个文件已删除
4个文件已添加
1566 ■■■■ 已修改文件
pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/AdapterImp_TcpClUnit.java 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/Server.java 28 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/ServerProperties.java 8 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/httpCl/HttpClUnit.java 112 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/httpCl/HttpClUnitAdapter.java 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/httpCl/HttpClUnitConfigVo.java 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/httpCl/HttpPost.java 11 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/httpCl/MyThreadJob.java 76 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/httpCl/RtuData4HAC_NBhV2_5.java 46 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/httpCl/RtuData4MeterV1_0.java 165 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/httpCl/TestBase64.java 23 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/httpCl/UpDataPayloadVo.java 16 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/httpCl/UpDataVo.java 174 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/rmiClient/Code.java 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/rmiClient/ResConfigVo.java 42 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/rmiClient/RmiClUnit.java 33 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/rmiClient/RmiResponseVo.java 12 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpClient/LocalCodecFactory.java 8 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpClient/LocalDecoder.java 31 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpClient/LocalEncoder.java 22 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpClient/MyThreadJob.java 130 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpClient/TcpClUnit.java 55 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpClient/TcpClUnitConfigVo.java 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpClient/TcpConnect.java 18 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpClient/TcpHandler.java 77 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpConnect/LocalDecoder.java 91 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpConnect/LocalEncoder.java 51 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpConnect/MinaConnectPool.java 107 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpConnect/MinaHandler.java 94 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/resources/Config.xml 8 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/resources/application.yml 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/resources/log4j2.xml 39 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/resources/log4j2.yml 64 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/AdapterImp_TcpClUnit.java
pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/Server.java
@@ -68,20 +68,40 @@
            //支持模块: springHibernate和 线程池
            SupportUnitConfigVo supVo = new SupportUnitConfigVo() ;
            //短工作时长线程池,线程负责用时较短的工作任务
            supVo.short_maxThread = conf.getSetAttrPlusInt(doc, "config.support", "short_maxThread", null, 1, 1000, null) ;//池中最大线程数为所有CPU核数+1
            supVo.short_minThread = conf.getSetAttrPlusInt(doc, "config.support", "short_minThread", null, 1, 5, null) ;//池中最小线程数
            supVo.short_maxThread = conf.getSetAttrPlusInt(doc, "config.support", "short_maxThread", null, -1, 1000, null) ;//池中最大线程数为所有CPU核数+1
            if(supVo.short_maxThread < 0){
                supVo.short_maxThread = -1 ;
            }
            supVo.short_minThread = conf.getSetAttrPlusInt(doc, "config.support", "short_minThread", null, -1, 100, null) ;//池中最小线程数
            if(supVo.short_minThread < 0){
                supVo.short_minThread = -1 ;
            }
            supVo.short_freeTimeout = conf.getSetAttrPlusInt(doc, "config.support", "short_freeTimeout", null, 1, 90, null) * 1000 ;//线程数空闲时长,若池中线程数量大于minThread,且有的线程空闲时长超过freeTimeout,则清除该线程,为了不清除,把minThread与maxThread设置相等
            supVo.short_busyTimeout = conf.getSetAttrPlusInt(doc, "config.support", "short_busyTimeout", null, 1, 10, null) * 1000 ;//线程不间断工作时长(单位为秒)超时限,认为线程已经了崩溃,将强制清除,短工作时长设置为5秒
            if(supVo.short_maxThread == 0 || supVo.short_minThread == 0){
                supVo.enableShortThreadPool = false ;
            }else{
                supVo.enableShortThreadPool = true ;
            }
            //长工作时长线程池,线程负责用时较长的工作任务
            supVo.long_maxThread = conf.getSetAttrInt(doc, "config.support", "long_maxThread", null, -1, 1000, null)  ;//池中最大线程数,若为-1,不受限制
            if(supVo.long_maxThread < 0){
                supVo.long_maxThread = -1 ;
            }
            supVo.long_minThread = conf.getSetAttrPlusInt(doc, "config.support", "long_minThread", null, 0, 5, null) ;//池中最小线程数
            supVo.long_minThread = conf.getSetAttrPlusInt(doc, "config.support", "long_minThread", null, -1, 100, null) ;//池中最小线程数
            if(supVo.long_minThread < 0){
                supVo.long_minThread = -1 ;
            }
            supVo.long_freeTimeout = conf.getSetAttrPlusInt(doc, "config.support", "long_freeTimeout", null, 1, 90, null) * 1000 ;//线程数空闲时长,若池中线程数量大于minThread,且有的线程空闲时长超过freeTimeout,则清除该线程
            supVo.long_busyTimeout = conf.getSetAttrInt(doc, "config.support", "long_busyTimeout", null, -1, 10, null) ;//线程不间断工作时长(单位为秒)超时限,若为-1,不受限制
            if(supVo.long_busyTimeout < 0){
                supVo.long_busyTimeout = -1 ;
            }
            if(supVo.long_maxThread == 0 || supVo.long_minThread == 0){
                supVo.enableLongThreadPool = false ;
            }else{
                supVo.enableLongThreadPool = true ;
            }
            supVo.showStartInfo = showStartInfo ;
@@ -113,8 +133,6 @@
            // Tcp Client 模块
            TcpClUnitConfigVo tcpClVo = new TcpClUnitConfigVo();
            tcpClVo.enable = conf.getSetAttrBoolean(doc, "config.tcpCl", "enable", null, null) ;
            tcpClVo.heartbeatTimes = conf.getSetAttrPlusInt(doc, "config.tcpCl", "heartbeatTimes", null, 1, 10, null) ;//连续配置次数心跳后发送一次数据
            tcpClVo.sendInterval = conf.getSetAttrPlusInt(doc, "config.tcpCl", "sendInterval", null, 1, 60, null) ;//发送心跳或数据的时间间隔
            if(tcpClVo.enable){
                AdapterImp_TcpClUnit httpClAdap = new AdapterImp_TcpClUnit();
                httpClAdap.setConfig(tcpClVo);
pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/ServerProperties.java
@@ -7,9 +7,13 @@
    //RTU截止地址
    public static Long rtuAddrEnd = 0L ;
    //服务端IP
    public static String serverIp = "" ;
    public static String tcpServerIp = "" ;
    //服务端上下文
    public static Integer serverPort = 0 ;
    public static Integer tcpServerPort = 0 ;
    //发送数据数据间隔
    public static Integer sendInterval = 0 ;//秒
    //每一轮次发送数据,其中包括心跳数据的次数
    public static Integer heartbeatTimes = 3 ;
    //发送数据次数
    public static Integer sendTimes = 0 ;
    
pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/httpCl/HttpClUnit.java
File was deleted
pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/httpCl/HttpClUnitAdapter.java
File was deleted
pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/httpCl/HttpClUnitConfigVo.java
File was deleted
pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/httpCl/HttpPost.java
File was deleted
pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/httpCl/MyThreadJob.java
File was deleted
pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/httpCl/RtuData4HAC_NBhV2_5.java
File was deleted
pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/httpCl/RtuData4MeterV1_0.java
File was deleted
pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/httpCl/TestBase64.java
File was deleted
pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/httpCl/UpDataPayloadVo.java
File was deleted
pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/httpCl/UpDataVo.java
File was deleted
pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/rmiClient/Code.java
@@ -9,7 +9,9 @@
    public static String cd3 = "003" ;//请求开始工作
    
    public static String cd4 = "004" ;//向服务端上报信息
    public static String cd5 = "005" ;//向服务端上报  数据上报工作已经完成
    public static String cd5 = "005" ;//向服务端上报  完成任务的数量
    public static String cd6 = "006" ;//向服务端上报  全部任务完成
}
pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/rmiClient/ResConfigVo.java
@@ -8,12 +8,16 @@
    //模拟客户的IMEI号截止号
    public Long rtuAddrEnd = 0L ;
    //服务端IP
    public String serverIp = "" ;
    public String tcpServerIp = "" ;
    //服务端上下文
    public Integer serverPort = 0 ;
    public Integer tcpServerPort = 0 ;
    //发送数据间隔
    public Integer sendInterval = 2 ;//秒
    //每一轮次发送数据,其中包括心跳发送次数
    public Integer heartbeatTimes = 3 ;
    //发送数据次数
    public Integer sendTimes = 0 ;
    /**
     * 对象转成json
     * @return 对象json
@@ -58,20 +62,36 @@
        this.rtuAddrEnd = rtuAddrEnd;
    }
    public String getServerIp() {
        return serverIp;
    public String getTcpServerIp() {
        return tcpServerIp;
    }
    public void setServerIp(String serverIp) {
        this.serverIp = serverIp;
    public void setTcpServerIp(String tcpServerIp) {
        this.tcpServerIp = tcpServerIp;
    }
    public Integer getServerPort() {
        return serverPort;
    public Integer getTcpServerPort() {
        return tcpServerPort;
    }
    public void setServerPort(Integer serverPort) {
        this.serverPort = serverPort;
    public void setTcpServerPort(Integer tcpServerPort) {
        this.tcpServerPort = tcpServerPort;
    }
    public Integer getSendInterval() {
        return sendInterval;
    }
    public void setSendInterval(Integer sendInterval) {
        this.sendInterval = sendInterval;
    }
    public Integer getHeartbeatTimes() {
        return heartbeatTimes;
    }
    public void setHeartbeatTimes(Integer heartbeatTimes) {
        this.heartbeatTimes = heartbeatTimes;
    }
    public Integer getSendTimes() {
pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/rmiClient/RmiClUnit.java
@@ -94,13 +94,30 @@
    }
    
    //把数据上报完成情况  上报给mwTestServer
    public void reportHadReportOver(Long seconds){
    public void reportHadReportOver(Integer count){
        try {
            Thread.sleep(100L);
            RmiRequestVo rqVo = new RmiRequestVo() ;
            rqVo.id = id ;
            rqVo.token = token ;
            rqVo.code = Code.cd5 ;
            rqVo.count = count ;
            String json = rqVo.toJson() ;
            frmWork.syncRequest(json) ;
        } catch (Exception e) {
            log.error("把数据上报完成情况  上报给mwTestServer失败" + e.getMessage());
        }
    }
    //把数据上报完成情况  上报给mwTestServer
    public void allOver(Long seconds){
        try {
            Thread.sleep(100L);
            RmiRequestVo rqVo = new RmiRequestVo() ;
            rqVo.id = id ;
            rqVo.token = token ;
            rqVo.code = Code.cd6 ;
            rqVo.over = true ;
            rqVo.seconds = seconds ;
            String json = rqVo.toJson() ;
@@ -178,15 +195,19 @@
                                if(rVo != null){
                                    ServerProperties.rtuAddrStart = rVo.rtuAddrStart;
                                    ServerProperties.rtuAddrEnd = rVo.rtuAddrEnd;
                                    ServerProperties.serverIp = rVo.serverIp;
                                    ServerProperties.serverPort = rVo.serverPort;
                                    ServerProperties.tcpServerIp = rVo.tcpServerIp;
                                    ServerProperties.tcpServerPort = rVo.tcpServerPort;
                                    ServerProperties.sendInterval = rVo.sendInterval ;
                                    ServerProperties.heartbeatTimes = rVo.heartbeatTimes ;
                                    ServerProperties.sendTimes = rVo.sendTimes ;
                                    log.info("得到配置成功");
                                    log.info("    开始RtuAddr=" + ServerProperties.rtuAddrStart);
                                    log.info("    截止RtuAddr=" + ServerProperties.rtuAddrEnd);
                                    log.info("    mwAccept服务IP=" + ServerProperties.serverIp);
                                    log.info("    mwAccept服务端口=" + ServerProperties.serverPort);
                                    log.info("    每imei上报数据次数=" + ServerProperties.sendTimes);
                                    log.info("    mwAccept服务IP=" + ServerProperties.tcpServerIp);
                                    log.info("    mwAccept服务端口=" + ServerProperties.tcpServerPort);
                                    log.info("    发送数据间隔=" + ServerProperties.sendTimes);
                                    log.info("    每轮次发送心跳次数=" + ServerProperties.heartbeatTimes);
                                    log.info("    每RTU上报数据轮次=" + ServerProperties.sendTimes);
                                    break ;
                                }else{
                                    log.error("rmi得到配置失败:json转ResConfigVo为null");
pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/rmiClient/RmiResponseVo.java
@@ -1,6 +1,7 @@
package com.dy.testClient.rmiClient;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
public class RmiResponseVo {
@@ -9,7 +10,7 @@
    public String errorInfo ;
    
    public String code ;
    public Object obj ;
    
    /**
@@ -33,11 +34,10 @@
     */
    public static RmiResponseVo jsonToObject(String json, Class<?> clazz)throws Exception{
        try{
            return JSON.parseObject(json, RmiResponseVo.class) ;
            //JSONDeserializer<RmiResponseVo> jsonD = new JSONDeserializer<RmiResponseVo>() ;
            //jsonD.use("obj", clazz) ;
            //RmiResponseVo resp = jsonD.deserialize(json, RmiResponseVo.class) ;
            //return resp ;
            JSONObject jsonObject = JSON.parseObject(json);
            RmiResponseVo vo = jsonObject.to(RmiResponseVo.class) ;
            vo.obj = jsonObject.getObject("obj", clazz);
            return vo ;
        }catch(Exception e){
            throw new Exception(e.getMessage() , e ) ;
        }
pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpClient/LocalCodecFactory.java
File was renamed from pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpConnect/LocalCodecFactory.java
@@ -1,9 +1,9 @@
package com.dy.testClient.tcpConnect;
package com.dy.testClient.tcpClient;
import org.apache.mina.filter.codec.ProtocolCodecFactory;
import org.apache.mina.filter.codec.ProtocolEncoder;
import org.apache.mina.filter.codec.ProtocolDecoder;
import org.apache.mina.core.session.IoSession;
import org.apache.mina.filter.codec.ProtocolCodecFactory;
import org.apache.mina.filter.codec.ProtocolDecoder;
import org.apache.mina.filter.codec.ProtocolEncoder;
public class LocalCodecFactory implements ProtocolCodecFactory {
    private ProtocolEncoder encoder;
pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpClient/LocalDecoder.java
New file
@@ -0,0 +1,31 @@
package com.dy.testClient.tcpClient;
import org.apache.mina.core.buffer.IoBuffer;
import org.apache.mina.core.session.IoSession;
import org.apache.mina.filter.codec.CumulativeProtocolDecoder;
import org.apache.mina.filter.codec.ProtocolDecoderOutput;
import java.io.IOException;
public class LocalDecoder extends CumulativeProtocolDecoder {
    private static final String DECODER_STATE_KEY = LocalDecoder.class.getName() + ".STATE";
    public static final int MAX_SIZE = 2147483647 ;
    /**
     * 对网络传输来的数据进行解码
     */
    protected boolean doDecode(IoSession session, IoBuffer in, ProtocolDecoderOutput out) throws IOException, Exception{
        int remain = in.remaining() ;
        if(remain > 0){
            byte[] preByte = new byte[remain];
            in.get(preByte) ;
            in.position(0) ;
        }
        return true;
    }
}
pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpClient/LocalEncoder.java
New file
@@ -0,0 +1,22 @@
package com.dy.testClient.tcpClient;
import org.apache.mina.core.buffer.IoBuffer;
import org.apache.mina.core.session.IoSession;
import org.apache.mina.filter.codec.ProtocolEncoderAdapter;
import org.apache.mina.filter.codec.ProtocolEncoderOutput;
import java.io.IOException;
public class LocalEncoder extends ProtocolEncoderAdapter {
    /**
     * 对数据进行编码,以备网络传输
     */
    public void encode(IoSession session, Object message, ProtocolEncoderOutput out) throws IOException, Exception{
        byte[] data = (byte[])message;
        //log.info("下行数据:" + ByteUtil.bytes2Hex(data, true));
        out.write(IoBuffer.allocate((data==null?0:data.length), false).put(data).flip());
    }
}
pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpClient/MyThreadJob.java
@@ -1,46 +1,126 @@
package com.dy.testClient.tcpClient;
import com.dy.common.mw.protocol.p206V1_0_0.CommonV1_0_1;
import com.dy.common.mw.protocol.p206V1_0_0.ProtocolConstantV206V1_0_0;
import com.dy.common.mw.protocol.p206V1_0_0.parse.global.GlCreate;
import com.dy.common.threadPool.ThreadPool;
import com.dy.testClient.httpCl.*;
import java.util.Base64;
import com.dy.common.util.ByteUtil;
import com.dy.testClient.ServerProperties;
import org.apache.mina.core.future.CloseFuture;
import org.apache.mina.core.session.IoSession;
public class MyThreadJob  implements ThreadPool.Job {
    public String rtuAddr;
    public String serverIp;
    public Integer serverPort;
    public IoSession session ;
    public static final int connectTimeout = 3000 ;
    public int sendTimes = 0 ;//发送数据次数
    public int heartbeatTimes = 0 ;//上报心跳次数
    public boolean isOver = false ;
    public MyThreadJob(){
    }
    public MyThreadJob(String rtuAddr){
    public MyThreadJob(String rtuAddr, String serverIp, Integer serverPort){
        this.rtuAddr = rtuAddr ;
        this.serverIp = serverIp ;
        this.serverPort = serverPort ;
    }
    @Override
    public void execute() throws Exception {
        testP206V1_0_0() ;
    }
    private void testP206V1_0_0(){
        try{
            RtuData4MeterV1_0 rd = new RtuData4MeterV1_0() ;
            byte[] bs = rd.create(rtuAddr) ;
            bs = Base64.getEncoder().encode(bs) ;
            UpDataPayloadVo payloadVo = new UpDataPayloadVo() ;
            payloadVo.APPdata = new String(bs, "UTF-8") ;
            UpDataVo vo = new UpDataVo(rtuAddr, "8086" + rtuAddr) ;
            vo.payload = payloadVo ;
            String json = vo.toJson() ;
            byte[] bytes = json.getBytes() ;
            HttpPost.post(bytes);
        }catch(Exception e){
            e.printStackTrace();
        }finally{
            HttpClUnit.clientOver() ;
        if(session == null){
            IoSession se = new TcpConnect().createSession(this.rtuAddr, this, this.serverIp, this.serverPort, connectTimeout, new TcpHandler()) ;
            if(se != null){
                this.session = se ;
            }
        }else{
            if(sendTimes <= ServerProperties.sendTimes){
                sendDataOfP206V1_0_0() ;
            }else{
                this.jobOver() ;
            }
        }
    }
    private void sendDataOfP206V1_0_0(){
        try{
            if(heartbeatTimes >= ServerProperties.heartbeatTimes){
                heartbeatTimes = 0 ;
                this.sendReportData() ;
                sendTimes++ ;
            }else{
                this.sendHeartbeat() ;
                heartbeatTimes++ ;
            }
        }catch(Exception e){
            e.printStackTrace();
        }
    }
    private void sendHeartbeat(){
        try{
            byte[] bs = this.createHeartbeat() ;
            this.session.write(bs) ;
        }catch (Exception e){
            e.printStackTrace();
        }
    }
    private void sendReportData(){
        TcpClUnit.clientSendData();
    }
    private void jobOver(){
        CloseFuture closeFuture = session.closeOnFlush() ;
        this.isOver = true ;
        TcpClUnit.clientOver() ;
    }
    /**
     * 构造下行数据
     * @return 字节数组
     * @throws Exception 异常
     */
    public byte[] createHeartbeat( ) throws Exception {
        CommonV1_0_1 commonV1_0_1 = new CommonV1_0_1() ;
        byte[] bytes ;
        byte[] bsHead = new byte[ProtocolConstantV206V1_0_0.lenHead2Code] ;
        byte index = 0 ;
        bsHead[index] = ProtocolConstantV206V1_0_0.P_Head_Byte ;
        index++ ;
        bsHead[index] = 0 ;//帧长度
        index++ ;
        bsHead[index] = ProtocolConstantV206V1_0_0.P_Head_Byte ;
        index++ ;
        bsHead[index] = commonV1_0_1.createCtrl((byte)0) ;
        index++ ;
        GlCreate.createRtuAddr(this.rtuAddr, bsHead, index);
        index += 5 ;
        ByteUtil.hex2Bytes("02", bsHead, index) ;
        byte[] bs = new byte[1] ;
        bs[0] = (byte)0xF2 ;//数据域: 1 个字节,F0 登录, F1 退出登录,F2 在线保持。
        bytes = ByteUtil.bytesMerge(bsHead, bs) ;
        GlCreate.createLen(bytes);//长度放字节数组中
        bytes = GlCreate.createCrcTail(bytes) ;//CRC和尾叠加字节数组中
        return bytes ;
    }
    @Override
    public void destroy() {
pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpClient/TcpClUnit.java
@@ -10,6 +10,10 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
public class TcpClUnit  implements UnitInterface {
    private static final Logger log = LogManager.getLogger(TcpClUnit.class) ;
@@ -20,8 +24,10 @@
    public static TcpClUnitConfigVo confVo ;
    private static ThreadPool.Pool pool ;
    private static Map<String, MyThreadJob> jobMap = new HashMap<>() ;
    private static Integer totalRunedClientCount = 0;
    private static Integer totalSendDataCount = 0;
    private static Integer totalOverClientCount = 0;
    private static Long startTime = 0L ;
@@ -69,12 +75,13 @@
                            startTime = System.currentTimeMillis() ;
                            for(Long addr = ServerProperties.rtuAddrStart; addr <= ServerProperties.rtuAddrEnd; addr++){
                                totalRunedClientCount++ ;
                                startClient(addr) ;
                                createImitate(addr) ;
                            }
                            startJob() ;
                            while(true){
                                if(totalOverClientCount.longValue() >= totalRunedClientCount.longValue()){
                                    Long seconds = (System.currentTimeMillis() - startTime)/1000 ;
                                    RmiClUnit.getInstance().reportHadReportOver(seconds) ;
                                    RmiClUnit.getInstance().allOver(seconds) ;
                                    System.out.println("共用时" + seconds + "秒");
                                    break ;
                                }else{
@@ -91,20 +98,48 @@
        }).start();
    }
    private void startClient(Long rtuAddr){
        try {
            pool.putJob(new MyThreadJob("" + rtuAddr));
        } catch (Exception e) {
            log.error("TcpClUnit.startClient() ", e);
        }
    /**
     * 创建RTU模拟MyThreadJob
     * @param rtuAddr rtu地址
     */
    private void createImitate(Long rtuAddr){
        jobMap.put("" + rtuAddr, new MyThreadJob("" + rtuAddr, ServerProperties.tcpServerIp, ServerProperties.tcpServerPort)) ;
    }
    private void startJob(){
        new Thread(new Runnable(){
            @Override
            public void run() {
                try {
                    Thread.sleep(1000L);
                    while(true){
                        Collection<MyThreadJob> collection = jobMap.values() ;
                        for(MyThreadJob job : collection){
                            pool.putJob(job);
                        }
                        Thread.sleep(ServerProperties.sendInterval * 1000);
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }).start();
    }
    public static synchronized void clientSendData(){
        totalSendDataCount++;
        if(totalSendDataCount % 100 == 0){
            RmiClUnit.getInstance().reportHadReportCount(totalSendDataCount);
            System.out.println("已经发送" + totalSendDataCount + "条数据");
        }
    }
    public static synchronized void clientOver(){
        totalOverClientCount++;
        if(totalOverClientCount % 100 == 0){
            RmiClUnit.getInstance().reportHadReportCount(totalOverClientCount);
            System.out.println("已经发送" + totalOverClientCount + "条数据");
            RmiClUnit.getInstance().reportHadReportOver(totalOverClientCount);
            System.out.println("已有" + totalOverClientCount + "完成了任务");
        }
    }
}
pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpClient/TcpClUnitConfigVo.java
@@ -2,6 +2,4 @@
public class TcpClUnitConfigVo {
    public boolean enable ;
    public int heartbeatTimes ;
    public int sendInterval ;
}
pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpClient/TcpConnect.java
File was renamed from pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpConnect/MinaConnect.java
@@ -1,38 +1,44 @@
package com.dy.testClient.tcpConnect;
package com.dy.testClient.tcpClient;
import org.apache.mina.core.future.ConnectFuture;
import org.apache.mina.core.session.IoSession;
import org.apache.mina.filter.codec.ProtocolCodecFilter;
import org.apache.mina.transport.socket.SocketConnector;
import org.apache.mina.transport.socket.nio.NioSocketConnector;
import java.net.InetSocketAddress;
public class MinaConnect {
public class TcpConnect {
    public static final String rtuAddrKey = "rtuAddr" ;
    public static final String threadJobKey = "threadJob" ;
    /**
     * 判断会话是否有效
     * @param se 网络会话
     * @return 是否连接
     */
    protected boolean isConnected(IoSession se) {
    public boolean isConnected(IoSession se) {
        return (se != null && se.isConnected());
    }
    /**
     * 创建新会话
     * @param rtuAddr rtu地址
     * @param job rtu工作类
     * @param host 服务器URI
     * @param port 服务器端口
     * @return 网络会话
     */
    protected IoSession createSession(String host , int port , int connectTimeout , MinaHandler handler) throws Exception{
    public IoSession createSession(String rtuAddr, MyThreadJob job, String host , int port , int connectTimeout , TcpHandler handler) throws Exception{
        SocketConnector connector = new NioSocketConnector();
        connector.getFilterChain().addLast("codec", new ProtocolCodecFilter(new LocalCodecFactory()));
        connector.setHandler(handler);
        ConnectFuture connectFuture = connector.connect(new InetSocketAddress(host, port));
        connectFuture.awaitUninterruptibly(connectTimeout);
        IoSession se = connectFuture.getSession();
        se.setAttribute(rtuAddrKey, rtuAddr) ;
        se.setAttribute(threadJobKey, job) ;
        return se ;
    }
@@ -42,7 +48,7 @@
     * @param se
     * @param connectTimeout
     */
    protected void disconnect(IoSession se , int connectTimeout) {
    public void disconnect(IoSession se , int connectTimeout) {
        if (se != null) {
            try{
                se.closeNow().awaitUninterruptibly(connectTimeout);
pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpClient/TcpHandler.java
New file
@@ -0,0 +1,77 @@
package com.dy.testClient.tcpClient;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.mina.core.service.IoHandlerAdapter;
import org.apache.mina.core.session.IdleStatus;
import org.apache.mina.core.session.IoSession;
import org.apache.mina.filter.FilterEvent;
public class TcpHandler  extends IoHandlerAdapter {
    private static Logger log = LogManager.getLogger(TcpHandler.class.getName()) ;
    /**
     * {@inheritDoc}
     */
    @Override
    public void sessionCreated(IoSession session) throws Exception {
    }
    /**
     * {@inheritDoc}
     */
    @Override
    public void sessionOpened(IoSession session) throws Exception {
    }
    /**
     * {@inheritDoc}
     */
    @Override
    public void sessionClosed(IoSession session) throws Exception {
    }
    /**
     * {@inheritDoc}
     */
    @Override
    public void sessionIdle(IoSession session, IdleStatus status) throws Exception {
    }
    /**
     * {@inheritDoc}
     */
    @Override
    public void exceptionCaught(IoSession session, Throwable cause) throws Exception {
    }
    /**
     * {@inheritDoc}
     */
    @Override
    public void messageReceived(IoSession session, Object message) throws Exception {
    }
    /**
     * {@inheritDoc}
     */
    @Override
    public void messageSent(IoSession session, Object message) throws Exception {
    }
    /**
     * {@inheritDoc}
     */
    @Override
    public void inputClosed(IoSession session) throws Exception {
        session.closeNow();
    }
    /**
     * {@inheritDoc}
     */
    @Override
    public void event(IoSession session, FilterEvent event) throws Exception {
    }
}
pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpConnect/LocalDecoder.java
File was deleted
pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpConnect/LocalEncoder.java
File was deleted
pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpConnect/MinaConnectPool.java
File was deleted
pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpConnect/MinaHandler.java
File was deleted
pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/resources/Config.xml
@@ -32,17 +32,13 @@
     -->
    <rmiCl
        rmiSvUrl="127.0.0.1"
        rmiSvContext="mwTestServer"
        rmiSvPort="9898"
        rmiSvContext="mwTestSv"
        rmiSvPort="12345"
    />
    <!--
    enable:是否启动
    heartbeatTimes:连续配置次数心跳后发送一次数据
    sendInterval:发送心跳或数据的时间间隔
     -->
    <tcpCl
        enable="true"
        heartbeatTimes="3"
        sendInterval="3"
    />
</config>        
pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/resources/application.yml
File was deleted
pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/resources/log4j2.xml
New file
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="OFF">
  <Appenders>
    <Console name="Console" target="SYSTEM_OUT">
      <PatternLayout charset="GBK" pattern="%d %-5p [%t] (%F:%L) - %m%n%throwable"/>
    </Console>
    <!--
        fileName="${sys:user.home}/logs/aepTest.log" filePattern="${sys:user.home}/logs/aepTest-%d{yyyy-MM}-%i.log.gz"
        fileName="/logs/testJgroups.log" filePattern="/logs/testJgroups-%d{yyyyMMdd}-%i.log.gz"
        fileName="logs/testJgroups.log" filePattern="logs/testJgroups-%d{yyyyMMdd}-%i.log.gz"
        sys:user.home当前用户在操作系统中的文档目录
        /logs/testJgroups.log当前软件所在硬盘根目录
        logs/testJgroups.log当前软件所在目录
     -->
    <RollingFile name="File" fileName="logs/mwTestCl.log" filePattern="logs/aepTest-%d{yyyyMMdd}-%i.log">
      <PatternLayout charset="UTF-8" pattern="%d %-5p [%t] (%class.%method:%L) - %m%n%throwable"/>
      <Policies>
        <TimeBasedTriggeringPolicy interval="7" />
        <SizeBasedTriggeringPolicy size="10MB"/>
      </Policies>
      <DefaultRolloverStrategy max="50" />
    </RollingFile>
  </Appenders>
  <Loggers>
      <!--
      <Logger name="com.zhzc.jgTest" level="debug">
      <AppenderRef ref="Console"/>
    </Logger>
      <Logger name="org.jgroups" level="info">
      <AppenderRef ref="File"/>
    </Logger>
      -->
    <!-- Root与各个Logger同时起作用 -->
    <Root level="info">
      <AppenderRef ref="Console"/>
      <AppenderRef ref="File"/>
    </Root>
  </Loggers>
</Configuration>
pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/resources/log4j2.yml
File was deleted