001/* 002 * Copyright 2008-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.List; 028import java.util.Map; 029 030import com.unboundid.ldap.sdk.Entry; 031import com.unboundid.util.NotMutable; 032import com.unboundid.util.StaticUtils; 033import com.unboundid.util.ThreadSafety; 034import com.unboundid.util.ThreadSafetyLevel; 035 036import static com.unboundid.ldap.sdk.unboundidds.monitors.MonitorMessages.*; 037 038 039 040/** 041 * This class defines a monitor entry that provides information about the 042 * operations currently being processed by the Directory Server. 043 * <BR> 044 * <BLOCKQUOTE> 045 * <B>NOTE:</B> This class, and other classes within the 046 * {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only 047 * supported for use against Ping Identity, UnboundID, and 048 * Nokia/Alcatel-Lucent 8661 server products. These classes provide support 049 * for proprietary functionality or for external specifications that are not 050 * considered stable or mature enough to be guaranteed to work in an 051 * interoperable way with other types of LDAP servers. 052 * </BLOCKQUOTE> 053 * <BR> 054 * The server should present at most one active operations monitor entry. It 055 * can be retrieved using the 056 * {@link MonitorManager#getActiveOperationsMonitorEntry} method. The 057 * {@link ActiveOperationsMonitorEntry#getActiveOperations} method may be used 058 * to retrieve information for each operation in progress. Alternately, this 059 * information may be accessed using the generic API. See the 060 * {@link MonitorManager} class documentation for an example that demonstrates 061 * the use of the generic API for accessing monitor data. 062 */ 063@NotMutable() 064@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE) 065public final class ActiveOperationsMonitorEntry 066 extends MonitorEntry 067{ 068 /** 069 * The structural object class used in active operations monitor entries. 070 */ 071 static final String ACTIVE_OPERATIONS_MONITOR_OC = 072 "ds-active-operations-monitor-entry"; 073 074 075 076 /** 077 * The name of the attribute that contains information about the number of 078 * operations currently in progress. 079 */ 080 private static final String ATTR_NUM_OPS_IN_PROGRESS = 081 "num-operations-in-progress"; 082 083 084 085 /** 086 * The name of the attribute that contains information about the number of 087 * persistent searches currently in progress. 088 */ 089 private static final String ATTR_NUM_PSEARCHES_IN_PROGRESS = 090 "num-persistent-searches-in-progress"; 091 092 093 094 /** 095 * The name of the attribute that contains information about an operation in 096 * progress. 097 */ 098 private static final String ATTR_OP_IN_PROGRESS = "operation-in-progress"; 099 100 101 102 /** 103 * The name of the attribute that contains information about a persistent 104 * search in progress. 105 */ 106 private static final String ATTR_PSEARCH_IN_PROGRESS = 107 "persistent-search-in-progress"; 108 109 110 111 /** 112 * The serial version UID for this serializable class. 113 */ 114 private static final long serialVersionUID = -6583987693176406802L; 115 116 117 118 // The list of operations currently in progress. 119 private final List<String> activeOperations; 120 121 // The list of persistent searches currently in progress. 122 private final List<String> activePersistentSearches; 123 124 // The number of operations currently in progress. 125 private final Long numOpsInProgress; 126 127 // The number of persistent searches currently in progress. 128 private final Long numPsearchesInProgress; 129 130 131 132 /** 133 * Creates a new active operations monitor entry from the provided entry. 134 * 135 * @param entry The entry to be parsed as a active operations monitor entry. 136 * It must not be {@code null}. 137 */ 138 public ActiveOperationsMonitorEntry(final Entry entry) 139 { 140 super(entry); 141 142 activeOperations = getStrings(ATTR_OP_IN_PROGRESS); 143 activePersistentSearches = getStrings(ATTR_PSEARCH_IN_PROGRESS); 144 numOpsInProgress = getLong(ATTR_NUM_OPS_IN_PROGRESS); 145 numPsearchesInProgress = getLong(ATTR_NUM_PSEARCHES_IN_PROGRESS); 146 } 147 148 149 150 /** 151 * Retrieves the number of operations currently in progress in the Directory 152 * Server. 153 * 154 * @return The number of operations currently in progress in the Directory 155 * Server, or {@code null} if it was not included in the monitor 156 * entry. 157 */ 158 public Long getNumOperationsInProgress() 159 { 160 return numOpsInProgress; 161 } 162 163 164 165 /** 166 * Retrieves a list of the string representations of the operations in 167 * progress in the Directory Server. 168 * 169 * @return A list of the string representations of the operations in 170 * progress in the Directory Server, or an empty list if it was not 171 * included in the monitor entry. 172 */ 173 public List<String> getActiveOperations() 174 { 175 return activeOperations; 176 } 177 178 179 180 /** 181 * Retrieves the number of persistent searches currently in progress in the 182 * Directory Server. 183 * 184 * @return The number of persistent searches currently in progress in the 185 * Directory Server, or {@code null} if it was not included in the 186 * monitor entry. 187 */ 188 public Long getNumPersistentSearchesInProgress() 189 { 190 return numPsearchesInProgress; 191 } 192 193 194 195 /** 196 * Retrieves a list of the string representations of the persistent searches 197 * in progress in the Directory Server. 198 * 199 * @return A list of the string representations of the persistent searches in 200 * progress in the Directory Server, or an empty list if it was not 201 * included in the monitor entry. 202 */ 203 public List<String> getActivePersistentSearches() 204 { 205 return activePersistentSearches; 206 } 207 208 209 210 /** 211 * {@inheritDoc} 212 */ 213 @Override() 214 public String getMonitorDisplayName() 215 { 216 return INFO_ACTIVE_OPERATIONS_MONITOR_DISPNAME.get(); 217 } 218 219 220 221 /** 222 * {@inheritDoc} 223 */ 224 @Override() 225 public String getMonitorDescription() 226 { 227 return INFO_ACTIVE_OPERATIONS_MONITOR_DESC.get(); 228 } 229 230 231 232 /** 233 * {@inheritDoc} 234 */ 235 @Override() 236 public Map<String,MonitorAttribute> getMonitorAttributes() 237 { 238 final LinkedHashMap<String,MonitorAttribute> attrs = 239 new LinkedHashMap<>(StaticUtils.computeMapCapacity(4)); 240 241 if (numOpsInProgress != null) 242 { 243 addMonitorAttribute(attrs, 244 ATTR_NUM_OPS_IN_PROGRESS, 245 INFO_ACTIVE_OPERATIONS_DISPNAME_NUM_OPS_IN_PROGRESS.get(), 246 INFO_ACTIVE_OPERATIONS_DESC_NUM_OPS_IN_PROGRESS.get(), 247 numOpsInProgress); 248 } 249 250 if (! activeOperations.isEmpty()) 251 { 252 addMonitorAttribute(attrs, 253 ATTR_OP_IN_PROGRESS, 254 INFO_ACTIVE_OPERATIONS_DISPNAME_OPS_IN_PROGRESS.get(), 255 INFO_ACTIVE_OPERATIONS_DESC_OPS_IN_PROGRESS.get(), 256 activeOperations); 257 } 258 259 if (numPsearchesInProgress != null) 260 { 261 addMonitorAttribute(attrs, 262 ATTR_NUM_PSEARCHES_IN_PROGRESS, 263 INFO_ACTIVE_OPERATIONS_DISPNAME_NUM_PSEARCHES_IN_PROGRESS.get(), 264 INFO_ACTIVE_OPERATIONS_DESC_NUM_PSEARCHES_IN_PROGRESS.get(), 265 numPsearchesInProgress); 266 } 267 268 if (! activePersistentSearches.isEmpty()) 269 { 270 addMonitorAttribute(attrs, 271 ATTR_PSEARCH_IN_PROGRESS, 272 INFO_ACTIVE_OPERATIONS_DISPNAME_PSEARCHES_IN_PROGRESS.get(), 273 INFO_ACTIVE_OPERATIONS_DESC_PSEARCHES_IN_PROGRESS.get(), 274 activePersistentSearches); 275 } 276 277 return Collections.unmodifiableMap(attrs); 278 } 279}