#
luxiaotao1123
2024-10-30 2fa6b113248685c6569194e31aa10031d5c114c0
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
package com.zy.acs.manager.core.listen;
 
import com.zy.acs.common.constant.RedisConstant;
import com.zy.acs.common.domain.AgvProtocol;
import com.zy.acs.common.utils.RedisSupport;
import com.zy.acs.manager.core.service.AgvDataService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
 
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
 
/**
 * Created by vincent on 2023/6/16
 */
@Slf4j
@Component
public class AgvDataSubscriber {
 
    private Thread thread;
    private final RedisSupport redis = RedisSupport.defaultRedisSupport;
 
    @Autowired
    private AgvDataService agvDataService;
 
    @PostConstruct
    private void start(){
//        redis.deleteList(RedisConstant.AGV_DATA_FLAG);
        thread = new Thread(() -> {
            while (!Thread.currentThread().isInterrupted()) {
                try {
                    // 间隔
                    Thread.sleep(10);
 
                    AgvProtocol protocol = redis.pop(RedisConstant.AGV_DATA_FLAG);
                    if (null != protocol){
 
                        agvDataService.dataProcess(protocol);
                    }
 
                } catch (Exception ignore) {}
            }
        });
        thread.start();
    }
 
    @PreDestroy
    public void shutDown(){
        if (thread != null) thread.interrupt();
    }
 
 
}