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