package com.dy.aceMw.server.tasks;
|
|
import com.dy.aceMw.server.busi.AboutRtuNode;
|
import com.dy.aceMw.server.busi.TcpUpDataCache;
|
import com.dy.common.mw.core.CoreTask;
|
import com.dy.common.queue.Node;
|
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.Logger;
|
|
/**
|
* 对RTU上行数据进行业务处理
|
*/
|
public class BusiConstantTask extends CoreTask {
|
private static final Logger log = LogManager.getLogger(BusiConstantTask.class.getName());
|
|
/**
|
* 在单线程环境中运行
|
*/
|
@Override
|
public Integer excute() {
|
try{
|
return dealRtuUpdata() ;
|
}catch(Exception e){
|
log.error(e);
|
}
|
return null ;
|
}
|
|
/**
|
* 处理上行数据
|
*/
|
public Integer dealRtuUpdata() {
|
Node first = TcpUpDataCache.getFirstQueueNode() ;
|
if(first != null){
|
Integer count = TcpUpDataCache.size() ;
|
Node last = TcpUpDataCache.getLastQueueNode() ;
|
this.doDealRtuUpdata(first, last);
|
return count ;
|
}
|
return null ;
|
}
|
|
/**
|
* 处理缓存的上行数据节点
|
* @param first 第一个节点
|
* @param last 最后一个节点
|
*/
|
private void doDealRtuUpdata(Node first, Node last){
|
if(last != null){
|
//在dealNode方法中,可能要把last从队列中移除,这时last.pre为空,所以提前把last.pre取出来
|
Node pre = last.pre ;
|
dealNode(last) ;
|
if(first != null && first != last){
|
doDealRtuUpdata(first, pre) ;
|
}else if(first != null && first == last){
|
//停止
|
}else if(first == null){
|
//这种情况不会存在
|
doDealRtuUpdata(null, pre) ;
|
}
|
}
|
}
|
|
/**
|
* 处理一个节点
|
* @param node 节点
|
*/
|
private void dealNode(Node node){
|
AboutRtuNode obj = (AboutRtuNode)node.obj ;
|
obj.dealSelf() ;
|
TcpUpDataCache.removeNode(node);
|
}
|
|
}
|