mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Valery Kharseko
11 hours ago 4c7057e45ba8a2f3bc1f0b02b3edf14886fd1956
opendj-server-legacy/src/snmp/src/org/opends/server/snmp/DsApplIfOpsEntryImpl.java
@@ -88,8 +88,14 @@
   */
  @Override
  public String getDsApplIfProtocol() {
      String portNumber = (String)this.monitor.getAttribute
              (this.connectionHandlerName, "ds-connectionhandler-listener");
      Object listener = this.monitor.getAttribute(
              this.connectionHandlerName, "ds-connectionhandler-listener");
      if (listener instanceof Object[]) {
          // A connection handler with several listen addresses reports them as an array.
          Object[] listeners = (Object[]) listener;
          listener = listeners.length > 0 ? listeners[0] : null;
      }
      String portNumber = listener != null ? String.valueOf(listener) : null;
      if (portNumber==null) {
          return this.DsApplIfProtocol;
      }
@@ -103,22 +109,38 @@
  }
  /**
   * Returns the value of the provided connection handler statistic as a
   * counter, or zero if the statistic is not available or does not hold a
   * number.
   *
   * @param statisticName the name of the connection handler statistic
   * @return the counter value of the statistic
   */
  private Long getCounter32Statistic(String statisticName) {
    if (stats == null) {
      stats = this.monitor.getConnectionHandlerStatistics(
              connectionHandlerName);
    }
    if (stats == null) {
      return 0L;
    }
    try {
      long value = Long.parseLong(
              String.valueOf(this.monitor.getAttribute(stats, statisticName)));
      return SNMPMonitor.counter32Value(value);
    } catch (NumberFormatException e) {
      // The statistic is not available or is not a number.
      return 0L;
    }
  }
  /**
   * {@inheritDoc}
   * @return DsApplIfSearchOps
   */
  @Override
  public Long getDsApplIfSearchOps() {
    if (stats == null) {
      stats = this.monitor.getConnectionHandlerStatistics(
              connectionHandlerName);
    }
    if (stats != null) {
      long value = Long.parseLong((String) this.monitor.getAttribute(stats,
              "searchRequests"));
      return SNMPMonitor.counter32Value(value);
    } else {
      return 0L;
    }
    return getCounter32Statistic("searchRequests");
  }
  /**
@@ -127,17 +149,7 @@
   */
  @Override
  public Long getDsApplIfOneLevelSearchOps() {
    if (stats == null) {
      stats = this.monitor.getConnectionHandlerStatistics(
              connectionHandlerName);
    }
    if (stats != null) {
      long value = Long.parseLong((String) this.monitor.getAttribute(stats,
              "searchOneRequests"));
      return SNMPMonitor.counter32Value(value);
    } else {
      return 0L;
    }
    return getCounter32Statistic("searchOneRequests");
  }
  /**
@@ -146,17 +158,7 @@
   */
  @Override
  public Long getDsApplIfWholeSubtreeSearchOps() {
    if (stats == null) {
      stats = this.monitor.getConnectionHandlerStatistics(
              connectionHandlerName);
    }
    if (stats != null) {
      long value = Long.parseLong((String) this.monitor.getAttribute(stats,
              "searchSubRequests"));
      return SNMPMonitor.counter32Value(value);
    } else {
      return 0L;
    }
    return getCounter32Statistic("searchSubRequests");
  }
  /**
@@ -165,17 +167,7 @@
   */
  @Override
  public Long getDsApplIfModifyRDNOps() {
    if (stats == null) {
      stats = this.monitor.getConnectionHandlerStatistics(
              connectionHandlerName);
    }
    if (stats != null) {
      long value = Long.parseLong((String) this.monitor.getAttribute(
              stats, "modifyDNRequests"));
      return SNMPMonitor.counter32Value(value);
    } else {
      return 0L;
    }
    return getCounter32Statistic("modifyDNRequests");
  }
  /**
@@ -184,17 +176,7 @@
   */
  @Override
  public Long getDsApplIfModifyEntryOps() {
    if (stats == null) {
      stats = this.monitor.getConnectionHandlerStatistics(
              connectionHandlerName);
    }
    if (stats != null) {
      long value = Long.parseLong((String) this.monitor.getAttribute(
              stats, "modifyRequests"));
      return SNMPMonitor.counter32Value(value);
    } else {
      return 0L;
    }
    return getCounter32Statistic("modifyRequests");
  }
  /**
@@ -203,17 +185,7 @@
   */
  @Override
  public Long getDsApplIfRemoveEntryOps() {
    if (stats == null) {
      stats = this.monitor.getConnectionHandlerStatistics(
              connectionHandlerName);
    }
    if (stats != null) {
      long value = Long.parseLong((String) this.monitor.getAttribute(
              stats, "deleteRequests"));
      return SNMPMonitor.counter32Value(value);
    } else {
      return 0L;
    }
    return getCounter32Statistic("deleteRequests");
  }
  /**
@@ -222,17 +194,7 @@
   */
  @Override
  public Long getDsApplIfAddEntryOps() {
    if (stats == null) {
      stats = this.monitor.getConnectionHandlerStatistics(
              connectionHandlerName);
    }
    if (stats != null) {
      long value = Long.parseLong((String) this.monitor.getAttribute(
              stats, "addRequests"));
      return SNMPMonitor.counter32Value(value);
    } else {
      return 0L;
    }
    return getCounter32Statistic("addRequests");
  }
  /**
@@ -241,17 +203,7 @@
   */
  @Override
  public Long getDsApplIfCompareOps() {
    if (stats == null) {
      stats = this.monitor.getConnectionHandlerStatistics(
              connectionHandlerName);
    }
    if (stats != null) {
      long value = Long.parseLong((String) this.monitor.getAttribute(
              stats, "compareRequests"));
      return SNMPMonitor.counter32Value(value);
    } else {
      return 0L;
    }
    return getCounter32Statistic("compareRequests");
  }
  /**
@@ -274,17 +226,7 @@
   */
  @Override
  public Long getDsApplIfOutBytes() {
    if (stats == null) {
      stats = this.monitor.getConnectionHandlerStatistics(
              connectionHandlerName);
    }
    if (stats != null) {
      long value = Long.parseLong((String) this.monitor.getAttribute(
              stats, "bytesWritten"));
      return SNMPMonitor.counter32Value(value);
    } else {
      return 0L;
    }
    return getCounter32Statistic("bytesWritten");
  }
  /**
@@ -293,17 +235,7 @@
   */
  @Override
  public Long getDsApplIfInBytes() {
    if (stats == null) {
      stats = this.monitor.getConnectionHandlerStatistics(
              connectionHandlerName);
    }
    if (stats != null) {
      long value = Long.parseLong((String) this.monitor.getAttribute(
              stats, "bytesRead"));
      return SNMPMonitor.counter32Value(value);
    } else {
      return 0L;
    }
    return getCounter32Statistic("bytesRead");
  }
  /**