Example #1
0
  /** 对IP_Net_To_Media进行探测 */
  private void doIPNetProbe() {
    if (DiscoverEngine.getInstance().getStopStatus() == 1) return;
    List ipNetTable =
        SnmpUtil.getInstance().getIpNetToMediaTable(this.getIpAddress(), this.getCommunity());

    if (ipNetTable == null || ipNetTable.size() == 0) // important
    {
      setDiscovered(true);
      return;
    }
    ipTotal = ipNetTable.size();
    int threadTotal = 0; // 线程总数
    SysLogger.info("PER_THREAD_IP===" + PER_THREAD_IP);
    if (ipTotal % PER_THREAD_IP == 0) // 每个线程对N个ip进行探测
    threadTotal = ipTotal / PER_THREAD_IP;
    else threadTotal = ipTotal / PER_THREAD_IP + 1;

    IPNetProbeThread probeThread = null;
    for (int i = 0; i < threadTotal; i++) {
      if (i == threadTotal - 1)
        probeThread = new IPNetProbeThread(this, ipNetTable.subList(i * PER_THREAD_IP, ipTotal));
      else
        probeThread =
            new IPNetProbeThread(
                this, ipNetTable.subList(i * PER_THREAD_IP, (i + 1) * PER_THREAD_IP));
      DiscoverEngine.getInstance().addThread(probeThread);
    }
  }
  public void run() {
    if (DiscoverEngine.getInstance().getStopStatus() == 1) return;
    snmp = SnmpUtil.getInstance();
    SysLogger.info("开始分析设备" + node.getIpAddress() + "的地址转发表");
    Set shieldList = DiscoverResource.getInstance().getShieldSet();
    List netshieldList = DiscoverResource.getInstance().getNetshieldList();
    List netincludeList = DiscoverResource.getInstance().getNetincludeList();
    IfEntity ifEntity = null;
    IfEntity endifEntity = null;

    // 生成线程池
    ThreadPool threadPool = new ThreadPool(addressList.size());

    for (int i = 0; i < addressList.size(); i++) {
      // ###################################
      // 若不需要服务器,则不进行交换机的ARP表采集
      // if(1==1)continue;
      // ###################################
      try {
        // node.updateCount(2);
        IpAddress ipAddr = (IpAddress) addressList.get(i);
        threadPool.runTask(NetMediThread.createTask(ipAddr, node));
        // SysLogger.info("在"+node.getIpAddress()+"的地址转发表发现IP "+ipAddr.getIpAddress()+",开始分析");
      } catch (Exception ex) {
        ex.printStackTrace();
      }
    } // end_for
    // 关闭线程池并等待所有任务完成
    threadPool.join();
    threadPool.close();
    threadPool = null;

    DiscoverEngine.getInstance().addDiscoverdcount();
    snmp = null;
    setCompleted(true);
  } // end_run