108 lines
4.1 KiB
Java
108 lines
4.1 KiB
Java
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,6),IS_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();
|
||
}
|
||
}
|
||
}
|