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