File was renamed from pipIrr-platform/pipIrr-mw/pipIrr-mw-accept/src/main/java/com/dy/aceMw/server/forTcp/TcpDownCommandCach.java |
| | |
| | | /** |
| | | * 非线程安全的,只能在单线程中运行 |
| | | */ |
| | | public class TcpDownCommandCach { |
| | | public class TcpDownCommandCache { |
| | | |
| | | //TCP下行命令缓存队列 |
| | | private static Queue cachQueue = new Queue("tcpDownComandQueue") ; |
| | | private static Queue cacheQueue = new Queue("tcpDownCommandQueue") ; |
| | | |
| | | private static TcpDownCommandCach instance = new TcpDownCommandCach() ; |
| | | private static TcpDownCommandCache instance = new TcpDownCommandCache() ; |
| | | |
| | | private TcpDownCommandCach(){ |
| | | cachQueue.setLimit(990000, 1000000); |
| | | private TcpDownCommandCache(){ |
| | | cacheQueue.setLimit(ServerProperties.cacheUpDownDataWarnCount, ServerProperties.cacheUpDownDataMaxCount); |
| | | } |
| | | |
| | | public static TcpDownCommandCach getInstance(){ |
| | | public static TcpDownCommandCache getInstance(){ |
| | | return instance ; |
| | | } |
| | | |
| | |
| | | * @param result |
| | | * @throws Exception |
| | | */ |
| | | public static void cachCommand(MidResultToRtu result) throws Exception{ |
| | | public static void cacheCommand(MidResultToRtu result) throws Exception{ |
| | | if(result != null){ |
| | | if(result.maxSendTimes == null){ |
| | | //设置最大发送次数 |
| | | result.maxSendTimes = ServerProperties.downComandMaxResendTimes ; |
| | | } |
| | | if(result.isSendFirst){ |
| | | cachQueue.pushHead(new TcpDownCommandObj(result)); |
| | | cacheQueue.pushHead(new TcpDownCommandObj(result)); |
| | | }else{ |
| | | cachQueue.pushTail(new TcpDownCommandObj(result)); |
| | | cacheQueue.pushTail(new TcpDownCommandObj(result)); |
| | | } |
| | | } |
| | | } |
| | |
| | | public static MidResultToRtu matchFromHead(MidResultFromRtu rsFromRtu){ |
| | | MidResultToRtu res = null ; |
| | | TcpDownCommandObj obj = null ; |
| | | Node node = cachQueue.getFirstNode() ; |
| | | Node node = cacheQueue.getFirstNode() ; |
| | | while(node != null && node.obj != null){ |
| | | obj = (TcpDownCommandObj)node.obj; |
| | | res = obj.result ; |
| | |
| | | public static MidResultToRtu matchFromTail(MidResultFromRtu rsFromRtu){ |
| | | MidResultToRtu res = null ; |
| | | TcpDownCommandObj obj = null ; |
| | | Node node = cachQueue.getLastNode() ; |
| | | Node node = cacheQueue.getLastNode() ; |
| | | while(node != null && node.obj != null){ |
| | | obj = (TcpDownCommandObj)node.obj; |
| | | res = obj.result ; |
| | |
| | | * @return |
| | | */ |
| | | public static Node getFirstQueueNode(){ |
| | | return cachQueue.getFirstNode() ; |
| | | return cacheQueue.getFirstNode() ; |
| | | } |
| | | |
| | | /** |
| | |
| | | * @return |
| | | */ |
| | | public static Node getLastQueueNode(){ |
| | | return cachQueue.getLastNode() ; |
| | | return cacheQueue.getLastNode() ; |
| | | } |
| | | |
| | | /** |
| | |
| | | * @param node |
| | | */ |
| | | public static void removeNode(Node node){ |
| | | cachQueue.remove(node); |
| | | cacheQueue.remove(node); |
| | | } |
| | | |
| | | /** |
| | | * 缓存的节点数 |
| | | * @param node |
| | | * @Return 缓存节点数 |
| | | */ |
| | | public static Integer size(){ |
| | | return cachQueue.size() ; |
| | | return cacheQueue.size() ; |
| | | } |
| | | |
| | | } |