/**
   * バッファの内容をjvnログファイル、通知として送信する。
   *
   * @param builder バッファ内容。
   * @param jvnFileName jvnファイル名。
   * @param jvnFileFullPath jvnファイルのフルパス。
   * @param callback Callbackオブジェクト。
   * @param telegramId 電文 ID
   * @param config 設定。
   * @param itemName アイテム名。
   */
  static void flushBuffer(
      StringBuilder builder,
      String jvnFileName,
      String jvnFileFullPath,
      JavelinLogCallback callback,
      JavelinConfig config,
      long telegramId,
      String itemName) {

    try {
      String content = builder.toString();
      if (config.isLogJvnFile()) {
        if (jvnFileFullPath != null) {
          writeToFile(jvnFileFullPath, content);
        }
      }

      if (jvnFileName != null && callback != null) {
        callback.execute(jvnFileName, content, telegramId, itemName);
      }
    } catch (Exception ex) {
      SystemLogger.getInstance().warn(ex);
    }

    if (builder.length() > 0) {
      builder.delete(0, builder.length());
    }
  }
  /** 接続スレッドを開始します。 */
  public void connect() {
    String host = config__.getConnectHost();

    CommunicatorSetting setting = new CommunicatorSetting();
    setting.port = config__.getConnectPort();
    setting.sslEnable = config__.isSslEnable();
    setting.keyStore = config__.getSslKeystore();
    setting.keyStorePass = config__.getSslKeystorePass();
    setting.trustStore = config__.getSslTruststore();
    setting.trustStorePass = config__.getSslTruststorePass();

    this.init(host, setting);

    ConnectNotifyData connectNotify = new ConnectNotifyData();
    connectNotify.setKind(ConnectNotifyData.KIND_JAVELIN);
    connectNotify.setAgentName(config__.getAgentName());

    super.connect(connectNotify);
  }
Exemple #3
0
  /**
   * 利用するメソッド、MXBeanの初期化を行います。
   *
   * @param config Javelinの設定
   */
  public static void init(JavelinConfig config) {
    try {
      // OracleASを利用した場合、Thead#getThreadID()からスレッドIDを取得すると、
      // 常に固定値が出力されるので、Threadクラスのフィールドから取得する。
      // また、IBMのVMを利用した利用した場合には、"tid"というフィールドがないため、"uniqueId"を利用する。
      try {
        tidField__ = Thread.class.getDeclaredField("tid");
      } catch (SecurityException se) {
        SystemLogger.getInstance().debug(se);
      } catch (NoSuchFieldException nsfe) {
        tidField__ = Thread.class.getDeclaredField("uniqueId");
      }
      try {
        getLockedSynchronizersMethod__ =
            ThreadInfo.class.getDeclaredMethod("getLockedSynchronizers");
        getLockInfoMethod__ = ThreadInfo.class.getDeclaredMethod("getLockInfo");
        getLockedMonitorsMethod__ = ThreadInfo.class.getDeclaredMethod("getLockedMonitors");
        try {
          Class<?> monitorInfoClass = Class.forName("java.lang.management.MonitorInfo");
          getLockedStackDepthMethod__ = monitorInfoClass.getDeclaredMethod("getLockedStackDepth");
        } catch (ClassNotFoundException cne) {
          SystemLogger.getInstance().debug(cne);
        }
      } catch (SecurityException se) {
        SystemLogger.getInstance().debug(se);
      } catch (NoSuchMethodException nme) {
        SystemLogger.getInstance().debug(nme);
      }

      if (tidField__ != null) {
        tidField__.setAccessible(true);
      }

      if (config.isThreadContentionMonitor()
          && threadMBean__.isThreadContentionMonitoringSupported()) {
        threadMBean__.setThreadContentionMonitoringEnabled(true);
      }
      if (threadMBean__.isThreadCpuTimeSupported()) {
        threadMBean__.setThreadCpuTimeEnabled(true);
      }
    } catch (Exception ex) {
      SystemLogger.getInstance().warn(ex);
    }
  }
  /**
   * Javelinログとして、ファイルに出力する。 javelin.download.maxを超える場合には、分割して送信する。
   *
   * @param jvnLogBuilder ライター
   * @param tree {@link CallTree}オブジェクト
   * @param node ノード。
   * @param endNode ログに出力する CallTree の最後のノード(このノードまで出力される)
   * @param callback JavelinCallback。
   * @param jvnFileFullPath jvnファイルのフルパス。
   * @param jvnFileName jvnファイル名。
   * @param telegramId 電文 ID。
   * @param itemName アイテム名。
   * @return 引き続きノードを出力する場合は <code>true</code> 、ノード出力を終了する場合は <code>false</code>
   */
  public static boolean generateJavelinFileImpl(
      final StringBuilder jvnLogBuilder,
      final CallTree tree,
      final CallTreeNode node,
      final CallTreeNode endNode,
      JavelinLogCallback callback,
      String jvnFileName,
      String jvnFileFullPath,
      final long telegramId,
      final String itemName) {
    JavelinConfig config = new JavelinConfig();
    if (jvnLogBuilder.length() > config.getJvnDownloadMax()) {
      flushBuffer(
          jvnLogBuilder, jvnFileName, jvnFileFullPath, callback, config, telegramId, itemName);
    }

    if (node == null) {
      StackTraceElement[] stacktraces = ThreadUtil.getCurrentStackTrace();
      String stackTraceStr = "(JavelinFileGenerator#generateJavelinFileImpl) node is NULL.\n";
      stackTraceStr += ThreadUtil.getStackTrace(stacktraces, stacktraces.length);
      SystemLogger.getInstance().warn(stackTraceStr);
      return true;
    }

    // ファイルに1メッセージを書き込む。
    if (node.getInvocation() != null) {
      String jvnCallMessage = createLogMessage(tree, node);
      if (jvnCallMessage != null) {
        jvnLogBuilder.append(jvnCallMessage);
      }
    }

    List<CallTreeNode> children = node.getChildren();
    boolean continuePrint = true;
    for (int index = 0; index < children.size(); index++) {
      CallTreeNode child = children.get(index);
      continuePrint =
          generateJavelinFileImpl(
              jvnLogBuilder,
              tree,
              child,
              endNode,
              callback,
              jvnFileName,
              jvnFileFullPath,
              telegramId,
              itemName);
      if (continuePrint == false || child == endNode) {
        continuePrint = false;
        break;
      }
    }

    // Throwログを書き込む。
    if (node.getThrowable() != null) {
      writeThrowLog(jvnLogBuilder, tree, node);
    }

    // Eventログを書き込む。
    CommonEvent[] eventList = node.getEventList();
    if (eventList != null) {
      for (CommonEvent event : eventList) {
        writeEventLog(jvnLogBuilder, tree, node, event);
      }
    }

    String jvnReturnMessage = "";
    if (node.getEndTime() >= 0) {
      if (node.isFieldAccess()) {
        jvnReturnMessage =
            JavelinLogMaker.createJavelinLog(ID_FIELD_WRITE, node.getEndTime(), tree, node);
      } else {
        jvnReturnMessage =
            JavelinLogMaker.createJavelinLog(ID_RETURN, node.getEndTime(), tree, node);
      }
    }

    // ファイルに1メッセージを書き込む。
    if (jvnReturnMessage != null) {
      jvnLogBuilder.append(jvnReturnMessage);
    }

    return continuePrint;
  }
 private JavelinConnectThread() {
   super("JavelinConnectThread", false, false);
   this.isJavelin_ = true;
   StatsJavelinRecorder.addListener(this);
   this.registerTelegramListeners(config__.getTelegramListeners().split(","));
 }