001/*
002 * Copyright 2011-2022 Ping Identity Corporation
003 * All Rights Reserved.
004 */
005/*
006 * Copyright 2011-2022 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) 2011-2022 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.NotNull;
047import com.unboundid.util.Nullable;
048import com.unboundid.util.StaticUtils;
049import com.unboundid.util.ThreadSafety;
050import com.unboundid.util.ThreadSafetyLevel;
051
052import static com.unboundid.ldap.sdk.unboundidds.monitors.MonitorMessages.*;
053
054
055
056/**
057 * This class defines a monitor entry that provides information about the
058 * processing times of operations that are performed in the server in the
059 * context of a single application.  It derives most of its functionality
060 * from its parent class, {@link ProcessingTimeHistogramMonitorEntry}.  The
061 * only additional information that is provided is the name of the application
062 * to which the monitor entry applies.
063 * <BR>
064 * <BLOCKQUOTE>
065 *   <B>NOTE:</B>  This class, and other classes within the
066 *   {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only
067 *   supported for use against Ping Identity, UnboundID, and
068 *   Nokia/Alcatel-Lucent 8661 server products.  These classes provide support
069 *   for proprietary functionality or for external specifications that are not
070 *   considered stable or mature enough to be guaranteed to work in an
071 *   interoperable way with other types of LDAP servers.
072 * </BLOCKQUOTE>
073 * <BR>
074 * The server can present zero or more per application processing time
075 * histogram monitor entries.  They can be retrieved using the
076 * {@link MonitorManager#getPerApplicationProcessingTimeHistogramMonitorEntries}
077 * method.  This entry provides specific methods for accessing information about
078 * processing times per bucket (e.g., the
079 * Alternately, this information may be accessed using the generic
080 * API.  See the {@link MonitorManager} class documentation for an example that
081 * demonstrates the use of the generic API for accessing monitor data.
082 */
083@NotMutable()
084@ThreadSafety(level= ThreadSafetyLevel.COMPLETELY_THREADSAFE)
085public final class PerApplicationProcessingTimeHistogramMonitorEntry
086       extends ProcessingTimeHistogramMonitorEntry
087{
088  /**
089   * The serial version UID for this serializable class.
090   */
091  private static final long serialVersionUID = 1467986373260986009L;
092
093
094
095  /**
096   * The structural object class used in processing time histogram monitor
097   * entries.
098   */
099  @NotNull static final String
100       PER_APPLICATION_PROCESSING_TIME_HISTOGRAM_MONITOR_OC =
101            "ds-per-application-processing-time-histogram-monitor-entry";
102
103
104
105  /**
106   * The name of the attribute that contains the name of the application to
107   * which this monitor entry applies.
108   */
109  @NotNull private static final String ATTR_APPLICATION_NAME =
110       "applicationName";
111
112
113
114  // The name of the application to which this monitor entry applies.
115  @Nullable private final String applicationName;
116
117
118  /**
119   * Creates a new processing time histogram monitor entry from the provided
120   * entry.
121   *
122   * @param  entry  The entry to be parsed as a processing time histogram
123   *                monitor entry.  It must not be {@code null}.
124   */
125  public PerApplicationProcessingTimeHistogramMonitorEntry(
126              @NotNull final Entry entry)
127  {
128    super(entry);
129
130    applicationName = entry.getAttributeValue(ATTR_APPLICATION_NAME);
131  }
132
133
134
135  /**
136   * Returns the name of the application to which this monitor entry applies.
137   *
138   * @return  The name of the application to which this monitor entry applies,
139   *          or {@code null} if it was not included in the monitor entry.
140   */
141  @Nullable()
142  public String getApplicationName()
143  {
144    return applicationName;
145  }
146
147
148
149  /**
150   * {@inheritDoc}
151   */
152  @Override()
153  @NotNull()
154  public String getMonitorDisplayName()
155  {
156    return INFO_PER_APP_PROCESSING_TIME_MONITOR_DISPNAME.get();
157  }
158
159
160
161  /**
162   * {@inheritDoc}
163   */
164  @Override()
165  @NotNull()
166  public String getMonitorDescription()
167  {
168    return INFO_PER_APP_PROCESSING_TIME_MONITOR_DESC.get();
169  }
170
171
172
173  /**
174   * {@inheritDoc}
175   */
176  @Override()
177  @NotNull()
178  public Map<String,MonitorAttribute> getMonitorAttributes()
179  {
180    final Map<String,MonitorAttribute> superAttrs =
181         super.getMonitorAttributes();
182
183    final LinkedHashMap<String,MonitorAttribute> attrs = new LinkedHashMap<>(
184         StaticUtils.computeMapCapacity(superAttrs.size()+1));
185    attrs.putAll(superAttrs);
186
187    if (applicationName != null)
188    {
189      addMonitorAttribute(attrs,
190           ATTR_APPLICATION_NAME,
191           INFO_PER_APP_PROCESSING_TIME_DISPNAME_APP_NAME.get(),
192           INFO_PER_APP_PROCESSING_TIME_DESC_APP_NAME.get(),
193           applicationName);
194    }
195
196    return Collections.unmodifiableMap(attrs);
197  }
198}