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