zhubaomin
2025-03-25 427d87e5572d72d0e3aaa4364e4f53569222e321
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
54
55
56
57
58
59
60
61
62
63
package com.dy.rtuMw3rd.http4Xjnk;
 
import com.dy.common.mw.UnitAdapterInterface;
import com.dy.common.mw.UnitCallbackInterface;
import com.dy.common.mw.UnitInterface;
import com.dy.common.springUtil.SpringContextUtil;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
 
/**
 * @Author: liurunyu
 * @Date: 2025/3/19 15:14
 * @Description
 */
public class HttpUnit implements UnitInterface {
 
    private static final Logger log = LogManager.getLogger(HttpUnit.class) ;
 
    private static HttpUnit instance = new HttpUnit() ;
 
    public static HttpUnitAdapter adapter ;
    public static HttpUnitConfigVo confVo ;
 
    private HttpUnit(){} ;
 
    public static HttpUnit getInstance(){
        return instance ;
    }
 
    @Override
    public void setAdapter(UnitAdapterInterface adapter) throws Exception {
        if(adapter == null){
            throw new Exception("Http模块适配器对象不能为空!") ;
        }
        HttpUnit.adapter = (HttpUnitAdapter)adapter ;
        HttpUnit.confVo = HttpUnit.adapter.getConfig() ;
        if(HttpUnit.confVo == null){
            throw new Exception("Http模块配置对象不能为空!") ;
        }
    }
 
    @Override
    public void start(UnitCallbackInterface callback) throws Exception {
        System.out.println("Http模块成功启动");
        this.doStart();
        callback.call(null) ;
    }
 
 
    @Override
    public void stop(UnitCallbackInterface callback) throws Exception {
        callback.call(null);
    }
 
    private void doStart(){
        Worker w = SpringContextUtil.getBean(Worker.class) ;
        w.setHttpsBaseUr(confVo.httpsBaseUr);
        w.setAppid(confVo.appid);
        w.setSecret(confVo.secret );
        w.setWorkInterval(confVo.flushDataFromSvInterval + 0L);
        w.start();
    }
}