⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 subcheckprocess.java.svn-base

📁 通讯采集软件
💻 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.*;//import pbs.application.iiop.pub.*;public class subCheckProcess extends Thread {    private Object[] termServerArray = null;    Runtime rt = null;    String pingOnStr = null;    byte[] byteArray = null;    InputStream in = null;    String pingStr = null;    String command = null;    int count_of_ts;    terminal_server m_ts = null;    BufferedInputStream buffer_in = null;    public subCheckProcess(Object[] tsArray) {        termServerArray = tsArray;        rt = Runtime.getRuntime();    }    public void run(){        pingOnStr = CheckDefine.PING_ON_STR;        count_of_ts = termServerArray.length;        m_ts = null;        int OnOff;        sample_event m_sample_event = null;        ArrayList m_list = new ArrayList();        for(int i=0; i<count_of_ts; i++){            m_ts = (terminal_server)(termServerArray[i]);            if(m_ts == null){                System.out.println("下装完的参数中有为null的terminal_server");                continue;            }            else{                OnOff = testTsAlive(m_ts);                String fileoutString = "terminal_server ip = "+m_ts.getTsIp()+" "+this.StringTimeSecond()+"  ";                if (OnOff < 0) {                    fileoutString += "Error in subCheckProcess-----testTsAlive()";                    CFunction.writeLog("CheckTs",fileoutString,null);                    continue;                }                else{                    if(OnOff == Constant.COMPUTER_EVENT_TYPE_START){                        fileoutString += "CONNECT";                        //CFunction.writeLog("CheckTs",fileoutString,null);                        System.out.println("i = "+i+", "+"终端服务器 ip = "+m_ts.getTsIp()+" 状态:"+CollectorDefine.TS_ON);                        m_ts.setStatus(Constant.STATUS_NORMAL);                        CheckDefine.m_HashTs.put(new Long(m_ts.getTsId()),m_ts);                        m_sample_event =                        CFunction.assSysEvent(Constant.EVENT_POS_COMPUTER,                        CollectorDefine.TS_ON,                        System.currentTimeMillis()/1000,                        System.currentTimeMillis()/1000,                        m_ts.getTsName()+"恢复",                        -1,                        m_ts.getFacId(),                        -1,                        m_ts.getTsId(),                        -1,                        1);//服务端需要判断,和以前状态比较                    }                    else if(OnOff == Constant.COMPUTER_EVENT_TYPE_STOP){                        fileoutString += "DIS_CONNECT";                        long status = m_ts.getStatus();                        String m_String = "";                        if(status == Constant.STATUS_FAULT)                            m_String = "Constant.STATUS_FAULT";                        if(status == Constant.STATUS_STOP)                            m_String = "Constant.STATUS_STOP";                        if(status == Constant.STATUS_NORMAL)                            m_String = "Constant.STATUS_NORMAL";                        fileoutString += "  "+"Before Status: "+ m_String;                        //CFunction.writeLog("CheckTs",fileoutString ,null);                        System.out.println("i = "+i+", "+"终端服务器 ip = "+m_ts.getTsIp()+" 状态:"+CollectorDefine.TS_OFF);                        if (status == Constant.STATUS_FAULT || status == Constant.STATUS_STOP) {                        }                        else {                            m_ts.setStatus(Constant.STATUS_FAULT);                            CheckDefine.m_HashTs.put(new Long(m_ts.getTsId()),m_ts);                            m_sample_event =                            CFunction.assSysEvent(Constant.EVENT_POS_COMPUTER,                            CollectorDefine.TS_OFF,                            System.currentTimeMillis()/1000,                            System.currentTimeMillis()/1000,                            m_ts.getTsName()+"故障",                            -1,                            m_ts.getFacId(),                            -1,                            m_ts.getTsId(),                            -1,                            1);//服务端需要判断,和以前状态比较                        }                    }                    if (m_sample_event!= null) {                        m_list.add(m_sample_event);                    }                    else{                        System.out.println("m_sample_event == null");                    }                }            }            this.sleep(1);        }        CheckDefine.flagCol.add(new Object());        if(m_list.size()>0)            CheckDefine.SampleEventCol.addAll(m_list);        m_list = null;        m_sample_event = null;        termServerArray = null;        pingOnStr = null;        rt = null;    }    private int testTsAlive(terminal_server ts) {        byteArray = new byte[500];        command = "ping" + " " + ts.getTsIp();        in = null;        try{            in = (rt.exec(command)).getInputStream();            sleep(100);            in.read(byteArray);            pingStr = new String(byteArray,"gbk");        }        catch(Exception ex) {            System.out.println("Error in testTsAlive in subCheckProcess #1");            ex.printStackTrace();            if(in != null){                try{                    in.close();                }                catch(Exception e){                    if(e instanceof IOException){                        System.out.println("Caught IOException while closing the InputStream in #1");                        e.printStackTrace();                    }                }            }            in = null;            return -1;        }        try{            if (pingStr.indexOf(pingOnStr) != -1) {                if(in != null){                    try{                        in.close();                    }                    catch(Exception e){                        if(e instanceof IOException){                            System.out.println("Caught IOException while closing the InputStream in #2");                            e.printStackTrace();                        }                    }                }                in = null;                return Constant.COMPUTER_EVENT_TYPE_START;            }            else {                if(in != null){                    try{                        in.close();                    }                    catch(Exception e){                        if(e instanceof IOException){                            System.out.println("Caught IOException while closing the InputStream in #3");                            e.printStackTrace();                        }                    }                }                in = null;                return Constant.COMPUTER_EVENT_TYPE_STOP;            }        }        catch(Exception ioe) {            System.out.println("Error in testTsAlive in subCheckProcess #2");            ioe.printStackTrace();            if(in != null){                try{                    in.close();                }                catch(Exception e){                    if(e instanceof IOException){                        System.out.println("Caught IOException while closing the InputStream in #4");                        e.printStackTrace();                    }                }            }            in = null;            return -1;        }    }    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 sleep(int count) {        try{            Thread.sleep(100*count);        }        catch(InterruptedException ie) {            System.out.println("sleep in CheckProcess #1");        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -