zhubaomin
2 天以前 080c76ddb23b9f199ed2f59f3871b0058347d43e
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
64
65
66
67
68
69
package com.dy.rtuMw.server.mqtt;
 
import com.dy.common.queue.Node;
import com.dy.common.queue.Queue;
import com.dy.rtuMw.server.ServerProperties;
 
/**
 * @Author: liurunyu
 * @Date: 2025/6/5 15:05
 * @Description
 */
public class MqttComResultCache {
 
    //TCP下行命令缓存队列
    private static Queue cacheQueue = new Queue("MqttComResultCache") ;
 
    private static MqttComResultCache instance = new MqttComResultCache() ;
 
    private MqttComResultCache(){
        cacheQueue.setLimit(ServerProperties.cacheUpDownDataWarnCount, ServerProperties.cacheUpDownDataMaxCount);
    }
 
    public static MqttComResultCache getInstance(){
        return instance ;
    }
 
    /**
     * 缓存节点
     * @param node node
     * @throws Exception 异常
     */
    public static void cacheMqttComResult(MqttComResultNode node) throws Exception{
        if(node != null && node.obj != null){
            cacheQueue.pushHead(node);
        }
    }
 
    /**
     * 得到第一个节点
     * @return Node
     */
    public static Node getFirstQueueNode(){
        return cacheQueue.getFirstNode() ;
    }
 
    /**
     * 得到最后一个节点
     * @return Node
     */
    public static Node getLastQueueNode(){
        return cacheQueue.getLastNode() ;
    }
 
    /**
     * 移除节点
     * @param node
     */
    public static void removeNode(Node node){
        cacheQueue.remove(node);
    }
 
    /**
     * 缓存的节点数
     * @Return 缓存节点数
     */
    public static Integer size(){
        return cacheQueue.size() ;
    }
}