com.unboundid.ldap.sdk.unboundidds.monitors.ExtendedOperationResultCodeInfo Maven / Gradle / Ivy
                 Go to download
                
        
                    Show more of this group  Show more artifacts with this name
Show all versions of unboundid-ldapsdk-commercial-edition Show documentation
                Show all versions of unboundid-ldapsdk-commercial-edition Show documentation
      The UnboundID LDAP SDK for Java is a fast, comprehensive, and easy-to-use
      Java API for communicating with LDAP directory servers and performing
      related tasks like reading and writing LDIF, encoding and decoding data
      using base64 and ASN.1 BER, and performing secure communication.  This
      package contains the Commercial Edition of the LDAP SDK, which includes
      all of the general-purpose functionality contained in the Standard
      Edition, plus additional functionality specific to UnboundID server
      products.
    
                
            /*
 * Copyright 2014-2016 UnboundID Corp.
 * All Rights Reserved.
 */
/*
 * Copyright (C) 2015-2016 UnboundID Corp.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License (GPLv2 only)
 * or the terms of the GNU Lesser General Public License (LGPLv2.1 only)
 * as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, see .
 */
package com.unboundid.ldap.sdk.unboundidds.monitors;
import java.io.Serializable;
import java.util.Collections;
import java.util.Map;
import java.util.TreeMap;
import com.unboundid.ldap.sdk.Attribute;
import com.unboundid.ldap.sdk.Entry;
import com.unboundid.ldap.sdk.OperationType;
import com.unboundid.util.Debug;
import com.unboundid.util.NotMutable;
import com.unboundid.util.StaticUtils;
import com.unboundid.util.ThreadSafety;
import com.unboundid.util.ThreadSafetyLevel;
/**
 * 
 *   NOTE:  This class is part of the Commercial Edition of the UnboundID
 *   LDAP SDK for Java.  It is not available for use in applications that
 *   include only the Standard Edition of the LDAP SDK, and is not supported for
 *   use in conjunction with non-UnboundID products.
 * 
 * This class provides a data structure that provides information about the
 * result codes associated with various types of extended operations.
 */
@NotMutable()
@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
public final class ExtendedOperationResultCodeInfo
       implements Serializable
{
  /**
   * The serial version UID for this serializable class.
   */
  private static final long serialVersionUID = 2412562905271298484L;
  // The percentage of all extended operations that failed.
  private final Double failedPercent;
  // The total number of operations of the associated type that failed.
  private final Long failedCount;
  // The total number of operations of the associated type.
  private final Long totalCount;
  // The percentage of extended operations that failed, indexed by OID.
  private final Map failedPercentsByOID;
  // The number of extended operations that failed, indexed by OID.
  private final Map failedCountsByOID;
  // The number of extended operations processed, indexed by OID.
  private final Map totalCountsByOID;
  // Information about each result code returned for each type of extended
  // operation, indexed first by extended request OID, then by the result code's
  // integer value.
  private final Map> resultCodeInfoMap;
  // The names of the types of extended operations processed, indexed by OID.
  private final Map requestNamesByOID;
  /**
   * Creates a new extended operation result code information object from the
   * provided information.
   *
   * @param  entry  The monitor entry to use to obtain the result code
   *                information.
   */
  ExtendedOperationResultCodeInfo(final MonitorEntry entry)
  {
    totalCount = entry.getLong("extended-op-total-count");
    failedCount = entry.getLong("extended-op-failed-count");
    failedPercent = entry.getDouble("extended-op-failed-percent");
    final TreeMap names = new TreeMap();
    final TreeMap totalCounts = new TreeMap();
    final TreeMap failedCounts = new TreeMap();
    final TreeMap failedPercents = new TreeMap();
    final TreeMap> rcMaps =
         new TreeMap>();
    final Entry e = entry.getEntry();
    for (final Attribute a : e.getAttributes())
    {
      try
      {
        final String lowerName = StaticUtils.toLowerCase(a.getName());
        if (lowerName.startsWith("extended-op-") &&
            lowerName.endsWith("-total-count"))
        {
          final String dashedOID =
               lowerName.substring(12, (lowerName.length() - 12));
          final String dottedOID = dashedOID.replace('-', '.');
          final String name = entry.getString(
               "extended-op-" + dashedOID + "-name");
          final long total = a.getValueAsLong();
          final long failed = entry.getLong(
               "extended-op-" + dashedOID + "-failed-count");
          final double failedPct = entry.getDouble(
               "extended-op-" + dashedOID + "-failed-percent");
          names.put(dottedOID, name);
          totalCounts.put(dottedOID, total);
          failedCounts.put(dottedOID, failed);
          failedPercents.put(dottedOID, failedPct);
          rcMaps.put(dottedOID,
               getRCMap(e, "extended-op-" + dashedOID + "-result-"));
        }
      }
      catch (final Exception ex)
      {
        Debug.debugException(ex);
      }
    }
    requestNamesByOID = Collections.unmodifiableMap(names);
    totalCountsByOID = Collections.unmodifiableMap(totalCounts);
    failedCountsByOID = Collections.unmodifiableMap(failedCounts);
    failedPercentsByOID = Collections.unmodifiableMap(failedPercents);
    resultCodeInfoMap = Collections.unmodifiableMap(rcMaps);
  }
  /**
   * Retrieves a map with result code information for a particular type of
   * extended operation.
   *
   * @param  entry   The entry to be examined.
   * @param  prefix  The prefix that will be used for all attributes of
   *                 interest.
   *
   * @return  A map with result code information for a particular type of
   *          extended operation.
   */
  private static Map getRCMap(final Entry entry,
                                                      final String prefix)
  {
    final TreeMap m =
         new TreeMap();
    for (final Attribute a : entry.getAttributes())
    {
      try
      {
        final String lowerName = StaticUtils.toLowerCase(a.getName());
        if (lowerName.startsWith(prefix) && lowerName.endsWith("-name"))
        {
          final int intValue = Integer.parseInt(lowerName.substring(
               prefix.length(), (lowerName.length() - 5)));
          final String name = a.getValue();
          final long count = entry.getAttributeValueAsLong(
               prefix + intValue + "-count");
          final double percent = Double.parseDouble(
               entry.getAttributeValue(prefix + intValue + "-percent"));
          final double totalResponseTimeMillis = Double.parseDouble(
               entry.getAttributeValue(prefix + intValue +
                    "-total-response-time-millis"));
          final double averageResponseTimeMillis = Double.parseDouble(
               entry.getAttributeValue(prefix + intValue +
                    "-average-response-time-millis"));
          m.put(intValue, new ResultCodeInfo(intValue, name,
               OperationType.EXTENDED, count, percent, totalResponseTimeMillis,
               averageResponseTimeMillis));
        }
      }
      catch (final Exception ex)
      {
        Debug.debugException(ex);
      }
    }
    return Collections.unmodifiableMap(m);
  }
  /**
   * Retrieves the total number of extended operations of all types that have
   * been processed, if available.
   *
   * @return  The total number of extended operations of all types that have
   *          been processed, or {@code null} if this information was not in the
   *          monitor entry.
   */
  public Long getTotalCount()
  {
    return totalCount;
  }
  /**
   * Retrieves the number of extended operations of each type that have been
   * processed, indexed by extended request OID, if available.
   *
   * @return  The number of extended operations of each type that have been
   *          processed, or an empty map if this information was not in the
   *          monitor entry.
   */
  public Map getTotalCountsByOID()
  {
    return totalCountsByOID;
  }
  /**
   * Retrieves the number of extended operations of all types that resulted in
   * failure, if available.
   *
   * @return  The number of extended operations of all types that resulted in
   *          failure, or {@code null} if this information was not in the
   *          monitor entry.
   */
  public Long getFailedCount()
  {
    return failedCount;
  }
  /**
   * Retrieves the number of extended operations of each type that resulted in
   * failure, indexed by extended request OID, if available.
   *
   * @return  The number of extended operations of each type that resulted in
   *          failure, or an empty map if this information was not in the
   *          monitor entry.
   */
  public Map getFailedCountsByOID()
  {
    return failedCountsByOID;
  }
  /**
   * Retrieves the percent of extended operations of all types that resulted in
   * failure, if available.
   *
   * @return  The percent of extended operations of all types that resulted in
   *          failure, or {@code null} if this information was not in the
   *          monitor entry.
   */
  public Double getFailedPercent()
  {
    return failedPercent;
  }
  /**
   * Retrieves the percent of extended operations of each type that resulted in
   * failure, indexed by extended request OID, if available.
   *
   * @return  The percent of extended operations of each type that resulted in
   *          failure, or an empty map if this information was not in the
   *          monitor entry.
   */
  public Map getFailedPercentsByOID()
  {
    return failedPercentsByOID;
  }
  /**
   * Retrieves a map with information about the result codes that have been
   * returned for extended operations of each type, indexed first by extended
   * request OID, and then by the result code's integer value.
   *
   * @return  A map with information about the result codes that have been
   *          returned for extended operations of each type, or an empty map if
   *          this information was not in the monitor entry.
   */
  public Map> getResultCodeInfoMap()
  {
    return resultCodeInfoMap;
  }
  /**
   * Retrieves a map with the human-readable names for each type of extended
   * request, indexed by request OID, if available.
   *
   * @return  A map with the human-readable names for each type of extended
   *          request, or an empty map if this information was not in the
   *          monitor entry.
   */
  public Map getExtendedRequestNamesByOID()
  {
    return requestNamesByOID;
  }
}
                            © 2015 - 2025 Weber Informatics LLC | Privacy Policy