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

📄 checkprocess.java.svn-base

📁 通讯采集软件
💻 SVN-BASE
字号:
package collector.checkts;

//import pbs.service.dao.*;
//import pbs.service.dao.*;
import java.io.*;
import java.util.*;

import collector.common.*;
import collector.iiop.*;
import pbs.service.function.*;

//import pbs.application.iiop.pub.*;

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();
    this.initProcess();
  }

  private void initProcess() {
    pingOnStr = CheckDefine.PING_ON_STR;
    if (pingOnStr == null || pingOnStr.length() <= 0) {
      pingOnStr = "bytes=32";
    }
    collector.common.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() {
    int count_of_ts = -1;
    pbs.service.vo.terminal_server m_ts = null;
    int OnOff;
    pbs.service.function.commonFunc cfunc = new commonFunc();
    pbs.service.util.Calendar cal = null;
    int ret = -1;
    int MAX_COUNTER = 240;
    int m_counter = 0;
    m_DownTs.intIIop();
    while (true) {
      String appendString = "free: " +
          new Long(Runtime.getRuntime().freeMemory()).toString()
          + "  total: " + new Long(Runtime.getRuntime().totalMemory()).toString()
          + "  max: " + new Long(Runtime.getRuntime().maxMemory()).toString();
      collector.common.CFunction.writeLog("CheckTs",
                                          "start of a loop  " + appendString, null);
      System.out.println("down terminal_server");
      if (this.m_DownTs.initHashTs() <= 0) {
        System.out.println("下装terminal_server表出错,2分钟后重新建立iiop链接,重新下装");
        sleep(1200);
        m_DownTs.intIIop();
        continue;
      }
      if (CheckDefine.m_HashTs == null || CheckDefine.m_HashTs.size() <= 0) {
        System.out.println("CheckDefine.m_HashTs不合法,2分钟后重新建立iiop链接,重新下装");
        sleep(1200);
        m_DownTs.intIIop();
        continue;
      }

      if (this.m_DownTs.initHashProtocol() <= 0) {
        System.out.println("下装Protocol表出错,2分钟后重新建立iiop链接,重新下装");
        sleep(1200);
        m_DownTs.intIIop();
        continue;
      }
      if (this.m_DownTs.initHashSampleEventType() <= 0) {
        System.out.println("下装Protocol表出错,2分钟后重新建立iiop链接,重新下装");
        sleep(1200);
        m_DownTs.intIIop();
        continue;
      }

      appendString = "free: " +
          new Long(Runtime.getRuntime().freeMemory()).toString()
          + "  total: " + new Long(Runtime.getRuntime().totalMemory()).toString()
          + "  max: " + new Long(Runtime.getRuntime().maxMemory()).toString();
      //collector.common.CFunction.writeLog("CheckTs","Time:" + this.StringTimeSecond() + " mid of a loop  "+appendString, null);
      collector.common.CFunction.writeLog("CheckTs",
                                          "mid of a loop  " + appendString, null);

      Object[] termServerArray = CheckDefine.m_HashTs.values().toArray();
      count_of_ts = termServerArray.length;
      System.out.println("程序将检查所有" + count_of_ts + "台终端服务器的状态,Time:" +
                         this.StringTimeSecond());
      //collector.common.CFunction.writeLog("CheckTs","Time:" + this.StringTimeSecond() + " will check " +count_of_ts + " terminal_servers", null);
      collector.common.CFunction.writeLog("CheckTs",
                                          "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++) {
        ArrayList 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());
        Object[] 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);
        }
      }
      ArrayList 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分钟后进行下一轮检查");
        //collector.common.CFunction.writeLog("CheckTs","Time:" + this.StringTimeSecond() + "," + "checked " +count_of_ts +" terminal servers,sent into database Successfully", null);
        collector.common.CFunction.writeLog("CheckTs",
            "checked " + count_of_ts + " terminal servers,sent into database Successfully", null);
      }
      else {
        System.out.println("入库失败,10分钟后进行下一轮检查");
        collector.common.CFunction.writeLog("CheckTs",
                                            "Time:" + this.StringTimeSecond() +
                                            "," + "checked " +
            " terminal servers,sent into database Unsuccessfully", null);
        collector.common.CFunction.writeLog("CheckTs",
            "checked " + " terminal servers,sent into database Unsuccessfully", null);
      }
      m_list = null;
      termServerArray = null;

      appendString = "free: " +
          new Long(Runtime.getRuntime().freeMemory()).toString()
          + "  total: " + new Long(Runtime.getRuntime().totalMemory()).toString()
          + "  max: " + new Long(Runtime.getRuntime().maxMemory()).toString();
      //collector.common.CFunction.writeLog("CheckTs","Time:" + this.StringTimeSecond() + " end of a loop  "+appendString, null);
      collector.common.CFunction.writeLog("CheckTs",
                                          "end of a loop  " + appendString, null);
      collector.common.CFunction.writeLog("CheckTs", "   ", 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 + -