📄 subcheckprocess.java.svn-base
字号:
package collector.checkts;
//import pbs.service.dao.*;
//import pbs.service.dao.*;
import java.io.*;
import java.util.*;
import collector.common.*;
//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;
pbs.service.vo.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;
pbs.service.vo.sample_event m_sample_event = null;
ArrayList m_list = new ArrayList();
for (int i = 0; i < count_of_ts; i++) {
m_ts = (pbs.service.vo.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()";
collector.common.CFunction.writeLog("CheckTs", fileoutString, null);
continue;
}
else {
if (OnOff == pbs.service.function.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(pbs.service.function.Constant.STATUS_NORMAL);
CheckDefine.m_HashTs.put(new Long(m_ts.getTsId()), m_ts);
m_sample_event =
collector.common.CFunction.assSysEvent(pbs.service.function.
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 ==
pbs.service.function.Constant.COMPUTER_EVENT_TYPE_STOP) {
fileoutString += "DIS_CONNECT";
long status = m_ts.getStatus();
String m_String = "";
if (status == pbs.service.function.Constant.STATUS_FAULT) {
m_String = "Constant.STATUS_FAULT";
}
if (status == pbs.service.function.Constant.STATUS_STOP) {
m_String = "Constant.STATUS_STOP";
}
if (status == pbs.service.function.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 == pbs.service.function.Constant.STATUS_FAULT ||
status == pbs.service.function.Constant.STATUS_STOP) {
}
else {
m_ts.setStatus(pbs.service.function.Constant.STATUS_FAULT);
CheckDefine.m_HashTs.put(new Long(m_ts.getTsId()), m_ts);
m_sample_event =
collector.common.CFunction.assSysEvent(pbs.service.function.
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");
}
}
}
//pzy modi 20060804
this.sleep(50);
//pzy modi 20060804
}
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(pbs.service.vo.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 pbs.service.function.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 pbs.service.function.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 + -