001/*
002 * Copyright 2011-2020 Ping Identity Corporation
003 * All Rights Reserved.
004 */
005/*
006 * Copyright 2011-2020 Ping Identity Corporation
007 *
008 * Licensed under the Apache License, Version 2.0 (the "License");
009 * you may not use this file except in compliance with the License.
010 * You may obtain a copy of the License at
011 *
012 *    http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing, software
015 * distributed under the License is distributed on an "AS IS" BASIS,
016 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017 * See the License for the specific language governing permissions and
018 * limitations under the License.
019 */
020/*
021 * Copyright (C) 2015-2020 Ping Identity Corporation
022 *
023 * This program is free software; you can redistribute it and/or modify
024 * it under the terms of the GNU General Public License (GPLv2 only)
025 * or the terms of the GNU Lesser General Public License (LGPLv2.1 only)
026 * as published by the Free Software Foundation.
027 *
028 * This program is distributed in the hope that it will be useful,
029 * but WITHOUT ANY WARRANTY; without even the implied warranty of
030 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
031 * GNU General Public License for more details.
032 *
033 * You should have received a copy of the GNU General Public License
034 * along with this program; if not, see <http://www.gnu.org/licenses>.
035 */
036package com.unboundid.ldap.sdk.unboundidds.monitors;
037
038
039
040import java.util.Collections;
041import java.util.LinkedHashMap;
042import java.util.Map;
043
044import com.unboundid.ldap.sdk.Entry;
045import com.unboundid.util.NotMutable;
046import com.unboundid.util.StaticUtils;
047import com.unboundid.util.ThreadSafety;
048import com.unboundid.util.ThreadSafetyLevel;
049
050import static com.unboundid.ldap.sdk.unboundidds.monitors.MonitorMessages.*;
051
052
053
054/**
055 * This class defines a monitor entry that provides information about the
056 * processing times of operations that are performed in the server in the
057 * context of a single application.  It derives most of its functionality
058 * from its parent class, {@link ProcessingTimeHistogramMonitorEntry}.  The
059 * only additional information that is provided is the name of the application
060 * to which the monitor entry applies.
061 * <BR>
062 * <BLOCKQUOTE>
063 *   <B>NOTE:</B>  This class, and other classes within the
064 *   {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only
065 *   supported for use against Ping Identity, UnboundID, and
066 *   Nokia/Alcatel-Lucent 8661 server products.  These classes provide support
067 *   for proprietary functionality or for external specifications that are not
068 *   considered stable or mature enough to be guaranteed to work in an
069 *   interoperable way with other types of LDAP servers.
070 * </BLOCKQUOTE>
071 * <BR>
072 * The server can present zero or more per application processing time
073 * histogram monitor entries.  They can be retrieved using the
074 * {@link MonitorManager#getPerApplicationProcessingTimeHistogramMonitorEntries}
075 * method.  This entry provides specific methods for accessing information about
076 * processing times per bucket (e.g., the
077 * Alternately, this information may be accessed using the generic
078 * API.  See the {@link MonitorManager} class documentation for an example that
079 * demonstrates the use of the generic API for accessing monitor data.
080 */
081@NotMutable()
082@ThreadSafety(level= ThreadSafetyLevel.COMPLETELY_THREADSAFE)
083public final class PerApplicationProcessingTimeHistogramMonitorEntry
084       extends ProcessingTimeHistogramMonitorEntry
085{
086  /**
087   * The serial version UID for this serializable class.
088   */
089  private static final long serialVersionUID = 1467986373260986009L;
090
091
092
093  /**
094   * The structural object class used in processing time histogram monitor
095   * entries.
096   */
097  static final String PER_APPLICATION_PROCESSING_TIME_HISTOGRAM_MONITOR_OC =
098       "ds-per-application-processing-time-histogram-monitor-entry";
099
100
101
102  /**
103   * The name of the attribute that contains the name of the application to
104   * which this monitor entry applies.
105   */
106  private static final String ATTR_APPLICATION_NAME = "applicationName";
107
108
109
110  // The name of the application to which this monitor entry applies.
111  private final String applicationName;
112
113
114  /**
115   * Creates a new processing time histogram monitor entry from the provided
116   * entry.
117   *
118   * @param  entry  The entry to be parsed as a processing time histogram
119   *                monitor entry.  It must not be {@code null}.
120   */
121  public PerApplicationProcessingTimeHistogramMonitorEntry(final Entry entry)
122  {
123    super(entry);
124
125    applicationName = entry.getAttributeValue(ATTR_APPLICATION_NAME);
126  }
127
128
129
130  /**
131   * Returns the name of the application to which this monitor entry applies.
132   *
133   * @return  The name of the application to which this monitor entry applies,
134   *          or {@code null} if it was not included in the monitor entry.
135   */
136  public String getApplicationName()
137  {
138    return applicationName;
139  }
140
141
142
143  /**
144   * {@inheritDoc}
145   */
146  @Override()
147  public String getMonitorDisplayName()
148  {
149    return INFO_PER_APP_PROCESSING_TIME_MONITOR_DISPNAME.get();
150  }
151
152
153
154  /**
155   * {@inheritDoc}
156   */
157  @Override()
158  public String getMonitorDescription()
159  {
160    return INFO_PER_APP_PROCESSING_TIME_MONITOR_DESC.get();
161  }
162
163
164
165  /**
166   * {@inheritDoc}
167   */
168  @Override()
169  public Map<String,MonitorAttribute> getMonitorAttributes()
170  {
171    final Map<String,MonitorAttribute> superAttrs =
172         super.getMonitorAttributes();
173
174    final LinkedHashMap<String,MonitorAttribute> attrs = new LinkedHashMap<>(
175         StaticUtils.computeMapCapacity(superAttrs.size()+1));
176    attrs.putAll(superAttrs);
177
178    if (applicationName != null)
179    {
180      addMonitorAttribute(attrs,
181           ATTR_APPLICATION_NAME,
182           INFO_PER_APP_PROCESSING_TIME_DISPNAME_APP_NAME.get(),
183           INFO_PER_APP_PROCESSING_TIME_DESC_APP_NAME.get(),
184           applicationName);
185    }
186
187    return Collections.unmodifiableMap(attrs);
188  }
189}