001/*
002 * Copyright 2008-2024 Ping Identity Corporation
003 * All Rights Reserved.
004 */
005/*
006 * Copyright 2008-2024 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) 2008-2024 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 state
058 * of the traditional work queue.  For all practical purposes, the traditional
059 * work queue has been replaced by the UnboundID Work Queue, which is the
060 * default work queue implementation (which exposes its own monitor information
061 * that can be accessed using the {@link UnboundIDWorkQueueMonitorEntry}).
062 * <BR>
063 * <BLOCKQUOTE>
064 *   <B>NOTE:</B>  This class, and other classes within the
065 *   {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only
066 *   supported for use against Ping Identity, UnboundID, and
067 *   Nokia/Alcatel-Lucent 8661 server products.  These classes provide support
068 *   for proprietary functionality or for external specifications that are not
069 *   considered stable or mature enough to be guaranteed to work in an
070 *   interoperable way with other types of LDAP servers.
071 * </BLOCKQUOTE>
072 * <BR>
073 * In the event that the traditional work queue is configured for use instead of
074 * the UnboundID work queue, then this monitor entry may be used to access the
075 * information that it provides, which may include:
076 * <UL>
077 *   <LI>The total number of requests submitted to the work queue.</LI>
078 *   <LI>The number of requests that were rejected because the work queue was
079 *       already at its maximum capacity.</LI>
080 *   <LI>The number of operations currently held in the work queue waiting to be
081 *       picked for processing by a worker thread.</LI>
082 *   <LI>The average number of operations held in the work queue since startup
083 *       as observed from periodic polling.</LI>
084 *   <LI>The maximum number of operations held in the work queue at any time
085 *       since startup as observed from periodic polling.</LI>
086 * </UL>
087 * The server should present at most one traditional work queue monitor entry.
088 * It can be retrieved using the
089 * {@link MonitorManager#getTraditionalWorkQueueMonitorEntry} method.  This
090 * entry provides specific methods for accessing information about the state of
091 * the work queue (e.g., the
092 * {@link TraditionalWorkQueueMonitorEntry#getCurrentBacklog} method may be used
093 * to retrieve the number of operations currently held in the work queue).
094 * Alternately, this information may be accessed using the generic API.  See the
095 * {@link MonitorManager} class documentation for an example that demonstrates
096 * the use of the generic API for accessing monitor data.
097 */
098@NotMutable()
099@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
100public final class TraditionalWorkQueueMonitorEntry
101       extends MonitorEntry
102{
103  /**
104   * The structural object class used in LDAP statistics monitor entries.
105   */
106  @NotNull static final String TRADITIONAL_WORK_QUEUE_MONITOR_OC =
107       "ds-traditional-work-queue-monitor-entry";
108
109
110
111  /**
112   * The name of the attribute that contains the average observed work queue
113   * request backlog.
114   */
115  @NotNull private static final String ATTR_AVERAGE_BACKLOG =
116       "averageRequestBacklog";
117
118
119
120  /**
121   * The name of the attribute that contains the current work queue request
122   * backlog.
123   */
124  @NotNull private static final String ATTR_CURRENT_BACKLOG =
125       "currentRequestBacklog";
126
127
128
129  /**
130   * The name of the attribute that contains the maximum observed work queue
131   * request backlog.
132   */
133  @NotNull private static final String ATTR_MAX_BACKLOG = "maxRequestBacklog";
134
135
136
137  /**
138   * The name of the attribute that contains the total number of requests that
139   * have been rejected because the work queue was full.
140   */
141  @NotNull private static final String ATTR_REQUESTS_REJECTED =
142       "requestsRejectedDueToQueueFull";
143
144
145
146  /**
147   * The name of the attribute that contains the total number of requests
148   * submitted.
149   */
150  @NotNull private static final String ATTR_REQUESTS_SUBMITTED =
151       "requestsSubmitted";
152
153
154
155  /**
156   * The serial version UID for this serializable class.
157   */
158  private static final long serialVersionUID = 5254676890679281070L;
159
160
161
162  // The average work queue backlog.
163  @Nullable private final Long averageBacklog;
164
165  // The current work queue backlog.
166  @Nullable private final Long currentBacklog;
167
168  // The maximum work queue backlog.
169  @Nullable private final Long maxBacklog;
170
171  // The total number of requests rejected due to a full work queue.
172  @Nullable private final Long requestsRejected;
173
174  // The total number of requests submitted.
175  @Nullable private final Long requestsSubmitted;
176
177
178
179  /**
180   * Creates a new traditional work queue monitor entry from the provided entry.
181   *
182   * @param  entry  The entry to be parsed as a traditional work queue monitor
183   *                entry.  It must not be {@code null}.
184   */
185  public TraditionalWorkQueueMonitorEntry(@NotNull final Entry entry)
186  {
187    super(entry);
188
189    averageBacklog    = getLong(ATTR_AVERAGE_BACKLOG);
190    currentBacklog    = getLong(ATTR_CURRENT_BACKLOG);
191    maxBacklog        = getLong(ATTR_MAX_BACKLOG);
192    requestsRejected  = getLong(ATTR_REQUESTS_REJECTED);
193    requestsSubmitted = getLong(ATTR_REQUESTS_SUBMITTED);
194  }
195
196
197
198  /**
199   * Retrieves the average number of operations observed in the work queue.
200   *
201   * @return  The average number of operations observed in the work queue, or
202   *          {@code null} if that information was not included in the monitor
203   *          entry.
204   */
205  @Nullable()
206  public Long getAverageBacklog()
207  {
208    return averageBacklog;
209  }
210
211
212
213  /**
214   * Retrieves the number of operations that are currently in the work queue
215   * waiting to be processed.
216   *
217   * @return  The number of operations that are currently in the work queue
218   *          waiting to be processed, or {@code null} if that information was
219   *          not included in the monitor entry.
220   */
221  @Nullable()
222  public Long getCurrentBacklog()
223  {
224    return currentBacklog;
225  }
226
227
228
229  /**
230   * Retrieves the maximum number of operations observed in the work queue at
231   * any given time.
232   *
233   * @return  The total number of operations observed in the work queue at any
234   *          given time, or {@code null} if that information was not included
235   *          in the monitor entry.
236   */
237  @Nullable()
238  public Long getMaxBacklog()
239  {
240    return maxBacklog;
241  }
242
243
244
245  /**
246   * Retrieves the total number of operation requests that were rejected because
247   * the work queue was at its maximum capacity.
248   *
249   * @return  The total number of operation requests rejected because the work
250   *          queue was at its maximum capacity, or {@code null} if that
251   *          information was not included in the monitor entry.
252   */
253  @Nullable()
254  public Long getRequestsRejectedDueToQueueFull()
255  {
256    return requestsRejected;
257  }
258
259
260
261  /**
262   * Retrieves the total number of operation requests submitted to the work
263   * queue.
264   *
265   * @return  The total number of operation requests submitted to the work
266   *          queue, or {@code null} if that information was not included in the
267   *          monitor entry.
268   */
269  @Nullable()
270  public Long getRequestsSubmitted()
271  {
272    return requestsSubmitted;
273  }
274
275
276
277  /**
278   * {@inheritDoc}
279   */
280  @Override()
281  @NotNull()
282  public String getMonitorDisplayName()
283  {
284    return INFO_TRADITIONAL_WORK_QUEUE_MONITOR_DISPNAME.get();
285  }
286
287
288
289  /**
290   * {@inheritDoc}
291   */
292  @Override()
293  @NotNull()
294  public String getMonitorDescription()
295  {
296    return INFO_TRADITIONAL_WORK_QUEUE_MONITOR_DESC.get();
297  }
298
299
300
301  /**
302   * {@inheritDoc}
303   */
304  @Override()
305  @NotNull()
306  public Map<String,MonitorAttribute> getMonitorAttributes()
307  {
308    final LinkedHashMap<String,MonitorAttribute> attrs =
309         new LinkedHashMap<>(StaticUtils.computeMapCapacity(10));
310
311    if (requestsSubmitted != null)
312    {
313      addMonitorAttribute(attrs,
314           ATTR_REQUESTS_SUBMITTED,
315           INFO_TRADITIONAL_WORK_QUEUE_DISPNAME_REQUESTS_SUBMITTED.get(),
316           INFO_TRADITIONAL_WORK_QUEUE_DESC_REQUESTS_SUBMITTED.get(),
317           requestsSubmitted);
318    }
319
320    if (requestsRejected != null)
321    {
322      addMonitorAttribute(attrs,
323           ATTR_REQUESTS_REJECTED,
324           INFO_TRADITIONAL_WORK_QUEUE_DISPNAME_REQUESTS_REJECTED.get(),
325           INFO_TRADITIONAL_WORK_QUEUE_DESC_REQUESTS_REJECTED.get(),
326           requestsRejected);
327    }
328
329    if (currentBacklog != null)
330    {
331      addMonitorAttribute(attrs,
332           ATTR_CURRENT_BACKLOG,
333           INFO_TRADITIONAL_WORK_QUEUE_DISPNAME_CURRENT_BACKLOG.get(),
334           INFO_TRADITIONAL_WORK_QUEUE_DESC_CURRENT_BACKLOG.get(),
335           currentBacklog);
336    }
337
338    if (averageBacklog != null)
339    {
340      addMonitorAttribute(attrs,
341           ATTR_AVERAGE_BACKLOG,
342           INFO_TRADITIONAL_WORK_QUEUE_DISPNAME_AVERAGE_BACKLOG.get(),
343           INFO_TRADITIONAL_WORK_QUEUE_DESC_AVERAGE_BACKLOG.get(),
344           averageBacklog);
345    }
346
347    if (maxBacklog != null)
348    {
349      addMonitorAttribute(attrs,
350           ATTR_MAX_BACKLOG,
351           INFO_TRADITIONAL_WORK_QUEUE_DISPNAME_MAX_BACKLOG.get(),
352           INFO_TRADITIONAL_WORK_QUEUE_DESC_MAX_BACKLOG.get(),
353           maxBacklog);
354    }
355
356    return Collections.unmodifiableMap(attrs);
357  }
358}