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