001/*
002 * Copyright 2014-2020 Ping Identity Corporation
003 * All Rights Reserved.
004 */
005/*
006 * Copyright 2014-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 group
056 * cache and the number and types of groups available in the server.
057 * <BR>
058 * <BLOCKQUOTE>
059 *   <B>NOTE:</B>  This class, and other classes within the
060 *   {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only
061 *   supported for use against Ping Identity, UnboundID, and
062 *   Nokia/Alcatel-Lucent 8661 server products.  These classes provide support
063 *   for proprietary functionality or for external specifications that are not
064 *   considered stable or mature enough to be guaranteed to work in an
065 *   interoperable way with other types of LDAP servers.
066 * </BLOCKQUOTE>
067 */
068@NotMutable()
069@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
070public final class GroupCacheMonitorEntry
071       extends MonitorEntry
072{
073  /**
074   * The structural object class used in group cache monitor entries.
075   */
076  static final String GROUP_CACHE_MONITOR_OC =
077       "ds-group-cache-monitor-entry";
078
079
080
081  /**
082   * The name of the attribute that contains information about the amount of
083   * memory required by the group cache, in bytes.
084   */
085  private static final String ATTR_CURRENT_CACHE_USED_BYTES =
086       "current-cache-used-bytes";
087
088
089
090  /**
091   * The name of the attribute that contains information about the amount of
092   * memory required by the group cache, as a percentage of the total JVM heap
093   * size.
094   */
095  private static final String ATTR_CURRENT_CACHE_USED_PERCENT =
096       "current-cache-used-as-percentage-of-max-heap";
097
098
099
100  /**
101   * The name of the attribute that contains information about the length of
102   * time required to determine group cache memory usage.
103   */
104  private static final String ATTR_CURRENT_CACHE_USED_UPDATE_MILLIS =
105       "current-cache-used-update-ms";
106
107
108
109  /**
110   * The name of the attribute that contains information about the number of
111   * dynamic group entries defined in the server.
112   */
113  private static final String ATTR_DYNAMIC_GROUP_ENTRIES =
114       "dynamic-group-entries";
115
116
117
118  /**
119   * The name of the attribute that contains information about the number of
120   * static group entries defined in the server.
121   */
122  private static final String ATTR_STATIC_GROUP_ENTRIES =
123       "static-group-entries";
124
125
126
127  /**
128   * The name of the attribute that contains information about the total number
129   * of static group members defined in the server.
130   */
131  private static final String ATTR_TOTAL_STATIC_GROUP_MEMBERS =
132       "static-group-members";
133
134
135
136  /**
137   * The name of the attribute that contains information about the number of
138   * unique static group members defined in the server.
139   */
140  private static final String ATTR_UNIQUE_STATIC_GROUP_MEMBERS =
141       "static-group-unique-members";
142
143
144
145  /**
146   * The name of the attribute that contains information about the number of
147   * virtual static group entries defined in the server.
148   */
149  private static final String ATTR_VIRTUAL_STATIC_GROUP_ENTRIES =
150       "virtual-static-group-entries";
151
152
153
154  /**
155   * The serial version UID for this serializable class.
156   */
157  private static final long serialVersionUID = -5665905374595185773L;
158
159
160
161  // The length of time in milliseconds required to determine the current cache
162  // usage.
163  private final Double currentCacheUsedUpdateMillis;
164
165  // The percentage of the JVM heap used by the group cache.
166  private final Integer currentCacheUsedPercent;
167
168  // The amount of memory (in bytes) currently in use by the group cache.
169  private final Long currentCacheUsedBytes;
170
171  // The number of dynamic group entries defined in the server.
172  private final Long dynamicGroupEntries;
173
174  // The number of static group entries defined in the server.
175  private final Long staticGroupEntries;
176
177  // The number of total static group members defined in the server.
178  private final Long staticGroupMembers;
179
180  // The number of unique static group members defined in the server.
181  private final Long staticGroupUniqueMembers;
182
183  // The number of virtual static group entries defined in the server.
184  private final Long virtualStaticGroupEntries;
185
186
187
188  /**
189   * Creates a new group cache monitor entry from the provided entry.
190   *
191   * @param  entry  The entry to be parsed as a group cache monitor entry.  It
192   *                must not be {@code null}.
193   */
194  public GroupCacheMonitorEntry(final Entry entry)
195  {
196    super(entry);
197
198    staticGroupEntries = getLong(ATTR_STATIC_GROUP_ENTRIES);
199    staticGroupMembers = getLong(ATTR_TOTAL_STATIC_GROUP_MEMBERS);
200    staticGroupUniqueMembers = getLong(ATTR_UNIQUE_STATIC_GROUP_MEMBERS);
201    dynamicGroupEntries = getLong(ATTR_DYNAMIC_GROUP_ENTRIES);
202    virtualStaticGroupEntries = getLong(ATTR_VIRTUAL_STATIC_GROUP_ENTRIES);
203    currentCacheUsedBytes = getLong(ATTR_CURRENT_CACHE_USED_BYTES);
204    currentCacheUsedPercent = getInteger(ATTR_CURRENT_CACHE_USED_PERCENT);
205    currentCacheUsedUpdateMillis =
206         getDouble(ATTR_CURRENT_CACHE_USED_UPDATE_MILLIS);
207  }
208
209
210
211  /**
212   * Retrieves the number of static group entries defined in the server, if
213   * available.
214   *
215   * @return  The number of static group entries defined in the server, or
216   *          {@code null} if it was not included in the monitor entry.
217   */
218  public Long getStaticGroupEntries()
219  {
220    return staticGroupEntries;
221  }
222
223
224
225  /**
226   * Retrieves the total number of static group members defined in the server,
227   * if available.  Users that are members of multiple static groups will be
228   * counted multiple times.
229   *
230   * @return  The total number of static group members defined in the server, or
231   *          {@code null} if it was not included in the monitor entry.
232   */
233  public Long getTotalStaticGroupMembers()
234  {
235    return staticGroupMembers;
236  }
237
238
239
240  /**
241   * Retrieves the number of unique static group members defined in the server,
242   * if available.  Users that are members of multiple static groups will only
243   * be counted once.
244   *
245   * @return  The number of unique static group members defined in the server,
246   *          or {@code null} if it was not included in the monitor entry.
247   */
248  public Long getUniqueStaticGroupMembers()
249  {
250    return staticGroupUniqueMembers;
251  }
252
253
254
255  /**
256   * Retrieves the number of dynamic group entries defined in the server, if
257   * available.
258   *
259   * @return  The number of dynamic group entries defined in the server, or
260   *          {@code null} if it was not included in the monitor entry.
261   */
262  public Long getDynamicGroupEntries()
263  {
264    return dynamicGroupEntries;
265  }
266
267
268
269  /**
270   * Retrieves the number of virtual static group entries defined in the server,
271   * if available.
272   *
273   * @return  The number of virtual static group entries defined in the server,
274   *          or {@code null} if it was not included in the monitor entry.
275   */
276  public Long getVirtualStaticGroupEntries()
277  {
278    return virtualStaticGroupEntries;
279  }
280
281
282
283  /**
284   * Retrieves the amount of memory in bytes used by the group cache, if
285   * available.
286   *
287   * @return  The amount of memory in bytes used by the group cache, or
288   *          {@code null} if it was not included in the monitor entry.
289   */
290  public Long getCurrentCacheUsedBytes()
291  {
292    return currentCacheUsedBytes;
293  }
294
295
296
297  /**
298   * Retrieves the amount of memory used by the group cache as a percentage of
299   * the maximum heap size, if available.
300   *
301   * @return  The amount of memory in bytes used by the group cache, or
302   *          {@code null} if it was not included in the monitor entry.
303   */
304  public Integer getCurrentCacheUsedAsPercentOfMaxHeap()
305  {
306    return currentCacheUsedPercent;
307  }
308
309
310
311  /**
312   * Retrieves the length of time in milliseconds required to compute the group
313   * cache size, if available.
314   *
315   * @return  The length of time in milliseconds required to compute the group
316   *          cache size, or {@code null} if it was not included in the monitor
317   *          entry.
318   */
319  public Double getCurrentCacheUsedUpdateDurationMillis()
320  {
321    return currentCacheUsedUpdateMillis;
322  }
323
324
325
326  /**
327   * {@inheritDoc}
328   */
329  @Override()
330  public String getMonitorDisplayName()
331  {
332    return INFO_GROUP_CACHE_MONITOR_DISPNAME.get();
333  }
334
335
336
337  /**
338   * {@inheritDoc}
339   */
340  @Override()
341  public String getMonitorDescription()
342  {
343    return INFO_GROUP_CACHE_MONITOR_DESC.get();
344  }
345
346
347
348  /**
349   * {@inheritDoc}
350   */
351  @Override()
352  public Map<String,MonitorAttribute> getMonitorAttributes()
353  {
354    final LinkedHashMap<String,MonitorAttribute> attrs =
355         new LinkedHashMap<>(StaticUtils.computeMapCapacity(8));
356
357    if (staticGroupEntries != null)
358    {
359      addMonitorAttribute(attrs,
360           ATTR_STATIC_GROUP_ENTRIES,
361           INFO_GROUP_CACHE_DISPNAME_STATIC_GROUP_ENTRIES.get(),
362           INFO_GROUP_CACHE_DESC_STATIC_GROUP_ENTRIES.get(),
363           staticGroupEntries);
364    }
365
366    if (staticGroupMembers != null)
367    {
368      addMonitorAttribute(attrs,
369           ATTR_TOTAL_STATIC_GROUP_MEMBERS,
370           INFO_GROUP_CACHE_DISPNAME_STATIC_GROUP_MEMBERS.get(),
371           INFO_GROUP_CACHE_DESC_STATIC_GROUP_MEMBERS.get(),
372           staticGroupMembers);
373    }
374
375    if (staticGroupUniqueMembers != null)
376    {
377      addMonitorAttribute(attrs,
378           ATTR_UNIQUE_STATIC_GROUP_MEMBERS,
379           INFO_GROUP_CACHE_DISPNAME_STATIC_GROUP_UNIQUE_MEMBERS.get(),
380           INFO_GROUP_CACHE_DESC_STATIC_GROUP_UNIQUE_MEMBERS.get(),
381           staticGroupUniqueMembers);
382    }
383
384    if (dynamicGroupEntries != null)
385    {
386      addMonitorAttribute(attrs,
387           ATTR_DYNAMIC_GROUP_ENTRIES,
388           INFO_GROUP_CACHE_DISPNAME_DYNAMIC_GROUP_ENTRIES.get(),
389           INFO_GROUP_CACHE_DESC_DYNAMIC_GROUP_ENTRIES.get(),
390           dynamicGroupEntries);
391    }
392
393    if (virtualStaticGroupEntries != null)
394    {
395      addMonitorAttribute(attrs,
396           ATTR_VIRTUAL_STATIC_GROUP_ENTRIES,
397           INFO_GROUP_CACHE_DISPNAME_VIRTUAL_STATIC_GROUP_ENTRIES.get(),
398           INFO_GROUP_CACHE_DESC_VIRTUAL_STATIC_GROUP_ENTRIES.get(),
399           virtualStaticGroupEntries);
400    }
401
402    if (currentCacheUsedBytes != null)
403    {
404      addMonitorAttribute(attrs,
405           ATTR_CURRENT_CACHE_USED_BYTES,
406           INFO_GROUP_CACHE_DISPNAME_CACHE_SIZE_BYTES.get(),
407           INFO_GROUP_CACHE_DESC_CACHE_SIZE_BYTES.get(),
408           currentCacheUsedBytes);
409    }
410
411    if (currentCacheUsedPercent != null)
412    {
413      addMonitorAttribute(attrs,
414           ATTR_CURRENT_CACHE_USED_PERCENT,
415           INFO_GROUP_CACHE_DISPNAME_CACHE_SIZE_PERCENT.get(),
416           INFO_GROUP_CACHE_DESC_CACHE_SIZE_PERCENT.get(),
417           currentCacheUsedPercent);
418    }
419
420    if (currentCacheUsedUpdateMillis != null)
421    {
422      addMonitorAttribute(attrs,
423           ATTR_CURRENT_CACHE_USED_UPDATE_MILLIS,
424           INFO_GROUP_CACHE_DISPNAME_CACHE_SIZE_UPDATE_MILLIS.get(),
425           INFO_GROUP_CACHE_DESC_CACHE_SIZE_UPDATE_MILLIS.get(),
426           currentCacheUsedUpdateMillis);
427    }
428
429    return Collections.unmodifiableMap(attrs);
430  }
431}