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