This repository has been archived on 2025-09-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
nms-nmsserver/src/com/nms/server/thread/dataCollect/NonRltTaskResultCollectManagerThread.java
2018-09-27 16:17:06 +08:00

108 lines
4.1 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package com.nms.server.thread.dataCollect;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.Future;
import org.apache.log4j.Logger;
import com.nms.server.common.Common;
import com.nms.server.common.Constants;
import com.nms.server.dao.CommonDao;
import com.nms.server.service.CommonService;
import com.nms.server.util.ExceptionPrintUtils;
//主动收集任务(执行完成,但无结果的任务)结果管理线程
public class NonRltTaskResultCollectManagerThread implements Runnable{
private Logger logger = Logger.getLogger(NonRltTaskResultCollectManagerThread.class);
public void run() {
CommonDao dao = null;
try {
// Thread.currentThread().setName("数据(无结果任务的结果数据)收集管理线程");
Thread.currentThread().setName("Data (No result task result data) To Collect Management Thread");
dao = new CommonDao();
CommonService service = new CommonService(dao);
//- 非升级操作判断
if(Common.SERVER_UN_UPGRADE_FLAG){//---起什么作用?
/**
* 向表MISSION_STATE_TABLE中查询MISSION_TYPE任务类型1,4,6IS_LOOP是否为周期任务1是0不是
* 一个任务会有多个节点ip执行任务结果表中一个任务id会有多条seq_id不同什么时候任务结果表里会有对应任务id的结果信息所以从表MISSION_STATE_TABLE开始查
* 按任务类型来:
*/
//需要收集任务结果的列表ip<任务id,>
Map<String,Map<String,String[]>> ipTaskIdsMap = service.getNonRltIpTaskMap();
Iterator ite = ipTaskIdsMap.entrySet().iterator();
int j=0;
String key = "";
while(ite.hasNext()) {
Entry en = (Entry)ite.next();
String ip = en.getKey().toString();
if(ip!=null&&!"".equals(ip.trim())) {
//- 检查线程运行状态 运行中无操作
key = Constants.NONRLTTASK_RESULT_COLLECT+":"+ip;
Future<?> future = Common.getFutureMap().get(key);
if(future != null && !future.isCancelled() && !future.isDone()){ //运行中
logger.info(""+ip+"的任务结果(对于该有结果,而无结果的任务)收集执行线程 运行中 不再启动新收集线程");
continue;
}
Map<String,String[]> taskInfoMap = (Map<String,String[]>)en.getValue();//当前ip上执行成功的任务id
// future = Common.service.submit(new NonRltTaskResultCollectThread("任务结果(对于该有结果,而无结果的任务)收集执行线程",ip,Constants.SSL_CLIENT_PORT,taskInfoMap));
future = Common.service.submit(new NonRltTaskResultCollectThread("Task Result(For tasks that should have results,but not results) Collect Execution Thread",ip,Constants.SSL_CLIENT_PORT,taskInfoMap));
//注册
Common.getFutureMap().put(key, future);
j++;
}
}
logger.info("*******************************************共"+ipTaskIdsMap.size()+"个节点,任务结果(对于该有结果,而无结果的任务)收集执行线程启动个数:"+j);
}
} catch (Exception e) {
logger.error(ExceptionPrintUtils.printExceptionStack(e));
} finally{
if(dao!=null){
dao.close();
dao=null;
}
logger.debug("执行结束");
}
}
public static void main(String[] args) {
try
{
// new InitServerThread().initCommonInfo(new CommonDao());
// NonRltTaskResultCollectManagerThread runThread = new NonRltTaskResultCollectManagerThread();
// Thread thread = new Thread(runThread);
// thread.start();
//
// Thread.sleep(10000);
//
// MissionResultThread mrt = new MissionResultThread("rlt");
// mrt.run();
// Map<String,String> m = new HashMap<String,String>();
//// String key = "";
// for(int i=0;i<6;i++) {
// String key="i="+i;
// m.put(key, ":"+i);
// }
//
// Iterator i = m.keySet().iterator();
// while(i.hasNext()) {
// String e = (String)i.next();
// System.out.println("key="+e.toString()+",value="+m.get(e).toString());
// }
} catch (Exception e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}