1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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);
    }
 
 
}