📄 checkprocess.java.svn-base
字号:
package collector.checkts;import java.util.*;import java.io.*;import collector.common.*;import collector.iiop.*;import pbs.sessionbean.ejb.*;import pbs.service.dao.*;import pbs.service.vo.*;import pbs.service.function.*;import pbs.service.struct.*;public class CheckProcess extends Thread{ Runtime rt = null; String pingOnStr = null; DownTs m_DownTs = null; String logname = "terminal_server_ping"; public CheckProcess() { rt = Runtime.getRuntime(); } private void initProcess(){ pingOnStr = CheckDefine.PING_ON_STR; if (pingOnStr == null || pingOnStr.length()<=0 ) { pingOnStr = "bytes=32"; } CFunction.getProperties(); this.m_DownTs = new DownTs(); } public static void sleep(int count) { try{ Thread.sleep(100*count); } catch(InterruptedException ie) { System.out.println("sleep in CheckProcess #1"); } } public void run(){ Object[] termServerArray = null; int count_of_ts = -1; terminal_server m_ts = null; int OnOff; commonFunc cfunc = new commonFunc(); pbs.service.util.Calendar cal = null; sample_event m_sample_event = null; ArrayList m_list = new ArrayList(); int ret = -1; int MAX_COUNTER = 240; int m_counter = 0 ; ArrayList m_tslist = null; Object[] tsArray = null; while(true){ initProcess(); System.out.println("down terminal_server"); if (this.m_DownTs.initHashTs()<= 0) { System.out.println("下装terminal_server表出错,2分钟后重新下装"); sleep(1200); continue; } if(CheckDefine.m_HashTs == null || CheckDefine.m_HashTs.size()<=0){ System.out.println("CheckDefine.m_HashTs不合法,2分钟后重新下载"); sleep(1200); continue; } if (this.m_DownTs.initHashProtocol()<= 0) { System.out.println("下装Protocol表出错,2分钟后重新下装"); sleep(1200); continue; } if (this.m_DownTs.initHashSampleEventType()<= 0) { System.out.println("下装SampleEventType表出错,2分钟后重新下装"); sleep(1200); continue; } termServerArray = CheckDefine.m_HashTs.values().toArray(); count_of_ts = termServerArray.length; m_sample_event = null; System.out.println("程序将检查所有"+count_of_ts+"台终端服务器的状态,Time:"+this.StringTimeSecond()); CFunction.writeLog("CheckTs","Time:" + this.StringTimeSecond()+" will check "+count_of_ts+" terminal_servers",null); CheckDefine.SampleEventCol = Collections.synchronizedCollection(new ArrayList()); CheckDefine.flagCol = Collections.synchronizedCollection(new ArrayList()); int subTsCount; int k; k = count_of_ts/10; if(count_of_ts%10 == 0) subTsCount = count_of_ts/10; else{ if(count_of_ts>=(k+1)*9 ) subTsCount = count_of_ts/10+1; else subTsCount = count_of_ts/10; } for(int i=0; i<10; i++){ m_tslist = new ArrayList(); if(i<9){ for(int j=0; j<subTsCount; j++){ m_tslist.add(termServerArray[subTsCount*i+j]); } } else{ int leftcount = count_of_ts-subTsCount*9; for(int j=0; j<leftcount; j++){ m_tslist.add(termServerArray[subTsCount*i+j]); } } System.out.println("i = "+i+" m_tslist.size = "+m_tslist.size()); tsArray = m_tslist.toArray(); subCheckProcess m_process = new subCheckProcess(tsArray); m_process.start(); } tsArray = null; m_tslist = null; while(true){ if(CheckDefine.flagCol.size() == 10) break; else{ System.out.println("CheckDefine.flagCol.size() = "+CheckDefine.flagCol.size()); this.sleep(50); } } m_list = new ArrayList(CheckDefine.SampleEventCol); if (m_list!=null){ if(m_list.size()>0){ System.out.println("准备发送状态数据,个数:"+m_list.size()); ret = this.sendEventList(m_list); } else{ System.out.println("m_list.size()<=0"); } } else{ System.out.println("m_list == null"); } pbs.service.util.Calendar cal2 = pbs.service.util.Calendar.getInstance(); System.out.println("一次检查完成,Time:" + this.StringTimeSecond() +" 终端服务器个数:"+count_of_ts); if(ret > 0){ System.out.println("入库成功,10分钟后进行下一轮检查"); CFunction.writeLog("CheckTs","Time:" + this.StringTimeSecond()+","+"checked "+count_of_ts+" terminal servers,sent into database Successfully",null); CFunction.writeLog("CheckTs"," ",null); } else{ System.out.println("入库失败,10分钟后进行下一轮检查"); CFunction.writeLog("CheckTs","Time:" + this.StringTimeSecond()+","+"checked "+count_of_ts+" terminal servers,sent into database Unsuccessfully",null); CFunction.writeLog("CheckTs"," ",null); } m_list = null; termServerArray = null; sleep(6000);//sleep10分钟 } } private int sendEventList(ArrayList m_list){ try{ IIopEvent m_iiopevent = null; m_iiopevent = this.m_DownTs.m_iiopswitch.getIIopEvent(); if (m_iiopevent == null) { System.out.println("sendEventList In CheckProcess Error #1"); return -1; } m_iiopevent.connect(); int ret = m_iiopevent.setDebugNo(CollectorDefine.SEND_EVENT_DEBUG); if (ret > 0) { ret = m_iiopevent.processEvent(m_list); System.out.println("发送终端服务器状态成功,个数:" + m_list.size()); } m_iiopevent.close(); return 1; } catch (Exception exception) { System.out.println("sendEventList In CheckProcess Error #2 " +exception.getMessage()); return -1; } } public static void main(String[] args){ System.out.println(CheckProcess.StringTimeSecond()); } public static String StringTimeSecond(long timelong) {//毫秒 Date dd = new Date(timelong); int year = dd.getYear() +1900; int cur_year = new Date(System.currentTimeMillis()).getYear()+1900; if(year<=cur_year-50 || year>cur_year+50){ return "no define"; } String yearString = (new Integer(year)).toString(); int mm = dd.getMonth(); String month = null; if ( (mm + 1) < 10) { month = "0" + (new Integer(mm + 1)).toString(); } else { month = (new Integer(mm + 1)).toString(); } String day = (new Integer(dd.getDate())).toString(); if (dd.getDate() < 10) { day = "0" + day; } String hour = (new Integer(dd.getHours())).toString(); if (dd.getHours() < 10) { hour = "0" + hour; } String min = (new Integer(dd.getMinutes())).toString(); if (dd.getMinutes() < 10) { min = "0" + min; } String second = (new Integer(dd.getSeconds())).toString(); if(dd.getSeconds() < 10){ second = "0"+second; } String date = year + "/" + month + "/" + day + " " + hour + ":" + min + ":" + second; return date; } public static String StringTimeSecond() { Date dd = new Date(System.currentTimeMillis()); int year = dd.getYear() +1900; int cur_year = new Date(System.currentTimeMillis()).getYear()+1900; if(year<=cur_year-50 || year>cur_year+50){ return "no define"; } String yearString = (new Integer(year)).toString(); int mm = dd.getMonth(); String month = null; if ( (mm + 1) < 10) { month = "0" + (new Integer(mm + 1)).toString(); } else { month = (new Integer(mm + 1)).toString(); } String day = (new Integer(dd.getDate())).toString(); if (dd.getDate() < 10) { day = "0" + day; } String hour = (new Integer(dd.getHours())).toString(); if (dd.getHours() < 10) { hour = "0" + hour; } String min = (new Integer(dd.getMinutes())).toString(); if (dd.getMinutes() < 10) { min = "0" + min; } String second = (new Integer(dd.getSeconds())).toString(); if(dd.getSeconds() < 10){ second = "0"+second; } String date = year + "/" + month + "/" + day + " " + hour + ":" + min + ":" + second; return date; } public static void WriteToFile(String filename,String m_String){ String pathname = "d:\\pbs_ts\\log\\"+ filename+".txt"; File m_exfile = new File(pathname); try { if (!m_exfile.exists()) { m_exfile.createNewFile(); } FileWriter fw = new FileWriter(m_exfile, true); PrintWriter pw = new PrintWriter(fw); pw.println(m_String); fw.close(); pw.close(); } catch (Exception exception) { exception.printStackTrace(); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -