package com.dy.rtuMw.server.rtuData; 
 | 
  
 | 
import com.dy.rtuMw.server.ServerProperties; 
 | 
import com.dy.common.queue.Node; 
 | 
import com.dy.common.queue.Queue; 
 | 
  
 | 
public class RtuDataCache { 
 | 
  
 | 
    //TCP下行命令缓存队列 
 | 
    private static Queue cacheQueue = new Queue("tcpUpDataQueue") ; 
 | 
  
 | 
    private static RtuDataCache instance = new RtuDataCache() ; 
 | 
  
 | 
    private RtuDataCache(){ 
 | 
        cacheQueue.setLimit(ServerProperties.cacheUpDownDataWarnCount, ServerProperties.cacheUpDownDataMaxCount); 
 | 
    } 
 | 
  
 | 
    public static RtuDataCache getInstance(){ 
 | 
        return instance ; 
 | 
    } 
 | 
  
 | 
    /** 
 | 
     * 缓存节点 
 | 
     * @param reportOrResponse_trueOrFalse reportOrResponse_trueOrFalse 
 | 
     * @param node node 
 | 
     * @throws Exception 异常 
 | 
     */ 
 | 
    public static void cacheRtuUpData(boolean reportOrResponse_trueOrFalse, RtuDataNode node) throws Exception{ 
 | 
        if(node != null && node.obj != null){ 
 | 
            if(reportOrResponse_trueOrFalse){ 
 | 
                cacheQueue.pushHead(node); 
 | 
            }else{ 
 | 
                cacheQueue.pushTail(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() ; 
 | 
    } 
 | 
  
 | 
} 
 |