private int sweepClient() {
    int size;
    synchronized (this.clientList_) {
      for (int index = this.clientList_.size() - 1; index >= 0; index--) {
        JavelinClientThread client = this.clientList_.get(index);
        if (client.isClosed()) {
          this.clientList_.remove(index);
        }
      }
      size = this.clientList_.size();
    }

    return size;
  }
  /**
   * クライアントにTelegramを送信する。
   *
   * @param telegram 送信する電文。
   */
  public void sendTelegram(Telegram telegram) {

    if (telegram == null) {
      return;
    }

    boolean isSweep = false;

    List<byte[]> byteList = TelegramUtil.createTelegram(telegram);
    for (byte[] bytes : byteList) {
      List<JavelinClientThread> clientList = this.clientList_;
      int size = clientList.size();
      for (int index = size - 1; index >= 0; index--) {
        JavelinClientThread client = null;
        synchronized (clientList) {
          if (index < clientList.size()) {
            client = clientList.get(index);
          } else {
            continue;
          }
        }

        if (client.isClosed()) {
          isSweep = true;
          continue;
        }

        client.sendAlarm(bytes);
        if (LOGGER.isDebugEnabled()) {
          client.logTelegram(telegram, bytes);
        }
      }
    }

    if (isSweep == true) {
      sweepClient();
    }
  }
  /** 通信用スレッドを実行する。 */
  @SuppressWarnings("deprecation")
  public void run() {
    try {
      Thread.sleep(this.waitForThreadStart_);
    } catch (Exception ex) {
      // Do nothing.
    }

    ThreadGroup group = new ThreadGroup("JavelinThreadGroup");
    String key = "";
    String message = "";

    this.isRunning_ = true;

    while (this.isRunning_ == true && this.isListening_ == false) {
      try {
        this.objServerSocket_ = new ServerSocket(this.port_);

        key = "javelin.communicate.JavelinAcceptThread.start";
        message = CommunicatorMessages.getMessage(key, this.port_);
        LOGGER.info(message);
        this.isListening_ = true;
      } catch (IOException objIOException) {
        int interval = this.bindInterval_;
        key = "javelin.communicate.JavelinAcceptThread.restart";
        message = CommunicatorMessages.getMessage(key, this.port_, interval);
        LOGGER.warn(message);
        if (this.isRange_ == true) {
          // ポート番号を1増やして再接続を行う。
          // 接続範囲を超えた場合には、javelin.bind.intervalの間スリープした後、処理を再度実行する。
          this.port_++;
          if (this.port_ > this.rangeMax_) {
            key = "javelin.communicate.JavelinAcceptThread.overRange";
            message = CommunicatorMessages.getMessage(key, this.rangeMax_, this.startPort_);
            LOGGER.info(message);
            this.port_ = this.startPort_;
          }
        }
        sleep();
      }
    }

    while (this.isRunning_) {
      try {
        try {
          accept(group);
        } catch (RuntimeException re) {
          key = "javelin.communicate.snmp.TrapListener.SendingTelegramErrorMessage";
          message = CommunicatorMessages.getMessage(key);
          LOGGER.warn(message, re);
        }
      } catch (Throwable th) {
        LOGGER.warn(th);
      }
    }

    synchronized (this.clientList_) {
      for (int index = this.clientList_.size() - 1; index >= 0; index--) {
        JavelinClientThread client = this.clientList_.get(index);
        client.stop();
      }
    }

    try {
      if (this.objServerSocket_ != null && this.isConnected()) {
        this.objServerSocket_.close();
      }
    } catch (IOException ioe) {
      key = "javelin.communicate.commonMessage.serverSocketCloseError";
      message = CommunicatorMessages.getMessage(key);
      LOGGER.warn(message, ioe);
    }
  }