zhubaomin
2025-04-07 1a2b07f01ba4616fd9e894dddf474b56d020158c
pipIrr-platform/pipIrr-mw/pipIrr-mw-simulate-rtu202404/src/main/java/com/dy/simRtu202404/tcpClient/TcpClUnit.java
New file
@@ -0,0 +1,53 @@
package com.dy.simRtu202404.tcpClient;
import com.dy.common.mw.UnitAdapterInterface;
import com.dy.common.mw.UnitCallbackInterface;
import com.dy.common.mw.UnitInterface;
/**
 * @Author: liurunyu
 * @Date: 2025/02/26 11:10
 * @Description
 */
public class TcpClUnit implements UnitInterface {
    private static TcpClUnit instance = new TcpClUnit() ;
    public static TcpClUnitAdapter adapter ;
    public static TcpClUnitConfigVo confVo ;
    private static Starter worker ;
    private TcpClUnit(){} ;
    public static TcpClUnit getInstance(){
        return instance ;
    }
    @Override
    public void setAdapter(UnitAdapterInterface adapter) throws Exception {
        if(adapter == null){
            throw new Exception("Tcp Client模块适配器对象不能为空!") ;
        }
        TcpClUnit.adapter = (TcpClUnitAdapter)adapter ;
        TcpClUnit.confVo = TcpClUnit.adapter.getConfig() ;
        if(TcpClUnit.confVo == null){
            throw new Exception("Tcp Client模块配置对象不能为空!") ;
        }
        TcpClUnit.worker = Starter.getInstance(TcpClUnit.confVo) ;
    }
    @Override
    public void start(UnitCallbackInterface callback) throws Exception {
        System.out.println("Tcp Client模块成功启动");
        TcpClUnit.worker.doStart();
        callback.call(null) ;
    }
    @Override
    public void stop(UnitCallbackInterface callback) throws Exception {
        callback.call(null);
    }
}