001/*
002 * Copyright 2008-2020 Ping Identity Corporation
003 * All Rights Reserved.
004 */
005/*
006 * Copyright 2008-2020 Ping Identity Corporation
007 *
008 * Licensed under the Apache License, Version 2.0 (the "License");
009 * you may not use this file except in compliance with the License.
010 * You may obtain a copy of the License at
011 *
012 *    http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing, software
015 * distributed under the License is distributed on an "AS IS" BASIS,
016 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017 * See the License for the specific language governing permissions and
018 * limitations under the License.
019 */
020/*
021 * Copyright (C) 2015-2020 Ping Identity Corporation
022 *
023 * This program is free software; you can redistribute it and/or modify
024 * it under the terms of the GNU General Public License (GPLv2 only)
025 * or the terms of the GNU Lesser General Public License (LGPLv2.1 only)
026 * as published by the Free Software Foundation.
027 *
028 * This program is distributed in the hope that it will be useful,
029 * but WITHOUT ANY WARRANTY; without even the implied warranty of
030 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
031 * GNU General Public License for more details.
032 *
033 * You should have received a copy of the GNU General Public License
034 * along with this program; if not, see <http://www.gnu.org/licenses>.
035 */
036package com.unboundid.ldap.sdk.unboundidds.monitors;
037
038
039
040import java.util.Collections;
041import java.util.LinkedHashMap;
042import java.util.List;
043import java.util.Map;
044
045import com.unboundid.ldap.sdk.Entry;
046import com.unboundid.util.NotMutable;
047import com.unboundid.util.StaticUtils;
048import com.unboundid.util.ThreadSafety;
049import com.unboundid.util.ThreadSafetyLevel;
050
051import static com.unboundid.ldap.sdk.unboundidds.monitors.MonitorMessages.*;
052
053
054
055/**
056 * This class defines a monitor entry that provides information about the
057 * operations currently being processed by the Directory Server.
058 * <BR>
059 * <BLOCKQUOTE>
060 *   <B>NOTE:</B>  This class, and other classes within the
061 *   {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only
062 *   supported for use against Ping Identity, UnboundID, and
063 *   Nokia/Alcatel-Lucent 8661 server products.  These classes provide support
064 *   for proprietary functionality or for external specifications that are not
065 *   considered stable or mature enough to be guaranteed to work in an
066 *   interoperable way with other types of LDAP servers.
067 * </BLOCKQUOTE>
068 * <BR>
069 * The server should present at most one active operations monitor entry.  It
070 * can be retrieved using the
071 * {@link MonitorManager#getActiveOperationsMonitorEntry} method.  The
072 * {@link ActiveOperationsMonitorEntry#getActiveOperations} method may be used
073 * to retrieve information for each operation in progress.  Alternately, this
074 * information may be accessed using the generic API.  See the
075 * {@link MonitorManager} class documentation for an example that demonstrates
076 * the use of the generic API for accessing monitor data.
077 */
078@NotMutable()
079@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
080public final class ActiveOperationsMonitorEntry
081       extends MonitorEntry
082{
083  /**
084   * The structural object class used in active operations monitor entries.
085   */
086  static final String ACTIVE_OPERATIONS_MONITOR_OC =
087       "ds-active-operations-monitor-entry";
088
089
090
091  /**
092   * The name of the attribute that contains information about the number of
093   * operations currently in progress.
094   */
095  private static final String ATTR_NUM_OPS_IN_PROGRESS =
096       "num-operations-in-progress";
097
098
099
100  /**
101   * The name of the attribute that contains information about the number of
102   * persistent searches currently in progress.
103   */
104  private static final String ATTR_NUM_PSEARCHES_IN_PROGRESS =
105       "num-persistent-searches-in-progress";
106
107
108
109  /**
110   * The name of the attribute that contains information about an operation in
111   * progress.
112   */
113  private static final String ATTR_OP_IN_PROGRESS = "operation-in-progress";
114
115
116
117  /**
118   * The name of the attribute that contains information about a persistent
119   * search in progress.
120   */
121  private static final String ATTR_PSEARCH_IN_PROGRESS =
122       "persistent-search-in-progress";
123
124
125
126  /**
127   * The serial version UID for this serializable class.
128   */
129  private static final long serialVersionUID = -6583987693176406802L;
130
131
132
133  // The list of operations currently in progress.
134  private final List<String> activeOperations;
135
136  // The list of persistent searches currently in progress.
137  private final List<String> activePersistentSearches;
138
139  // The number of operations currently in progress.
140  private final Long numOpsInProgress;
141
142  // The number of persistent searches currently in progress.
143  private final Long numPsearchesInProgress;
144
145
146
147  /**
148   * Creates a new active operations monitor entry from the provided entry.
149   *
150   * @param  entry  The entry to be parsed as a active operations monitor entry.
151   *                It must not be {@code null}.
152   */
153  public ActiveOperationsMonitorEntry(final Entry entry)
154  {
155    super(entry);
156
157    activeOperations         = getStrings(ATTR_OP_IN_PROGRESS);
158    activePersistentSearches = getStrings(ATTR_PSEARCH_IN_PROGRESS);
159    numOpsInProgress         = getLong(ATTR_NUM_OPS_IN_PROGRESS);
160    numPsearchesInProgress   = getLong(ATTR_NUM_PSEARCHES_IN_PROGRESS);
161  }
162
163
164
165  /**
166   * Retrieves the number of operations currently in progress in the Directory
167   * Server.
168   *
169   * @return  The number of operations currently in progress in the Directory
170   *          Server, or {@code null} if it was not included in the monitor
171   *          entry.
172   */
173  public Long getNumOperationsInProgress()
174  {
175    return numOpsInProgress;
176  }
177
178
179
180  /**
181   * Retrieves a list of the string representations of the operations in
182   * progress in the Directory Server.
183   *
184   * @return  A list of the string representations of the operations in
185   *          progress in the Directory Server, or an empty list if it was not
186   *          included in the monitor entry.
187   */
188  public List<String> getActiveOperations()
189  {
190    return activeOperations;
191  }
192
193
194
195  /**
196   * Retrieves the number of persistent searches currently in progress in the
197   * Directory Server.
198   *
199   * @return  The number of persistent searches currently in progress in the
200   *          Directory Server, or {@code null} if it was not included in the
201   *          monitor entry.
202   */
203  public Long getNumPersistentSearchesInProgress()
204  {
205    return numPsearchesInProgress;
206  }
207
208
209
210  /**
211   * Retrieves a list of the string representations of the persistent searches
212   * in progress in the Directory Server.
213   *
214   * @return  A list of the string representations of the persistent searches in
215   *          progress in the Directory Server, or an empty list if it was not
216   *          included in the monitor entry.
217   */
218  public List<String> getActivePersistentSearches()
219  {
220    return activePersistentSearches;
221  }
222
223
224
225  /**
226   * {@inheritDoc}
227   */
228  @Override()
229  public String getMonitorDisplayName()
230  {
231    return INFO_ACTIVE_OPERATIONS_MONITOR_DISPNAME.get();
232  }
233
234
235
236  /**
237   * {@inheritDoc}
238   */
239  @Override()
240  public String getMonitorDescription()
241  {
242    return INFO_ACTIVE_OPERATIONS_MONITOR_DESC.get();
243  }
244
245
246
247  /**
248   * {@inheritDoc}
249   */
250  @Override()
251  public Map<String,MonitorAttribute> getMonitorAttributes()
252  {
253    final LinkedHashMap<String,MonitorAttribute> attrs =
254         new LinkedHashMap<>(StaticUtils.computeMapCapacity(4));
255
256    if (numOpsInProgress != null)
257    {
258      addMonitorAttribute(attrs,
259           ATTR_NUM_OPS_IN_PROGRESS,
260           INFO_ACTIVE_OPERATIONS_DISPNAME_NUM_OPS_IN_PROGRESS.get(),
261           INFO_ACTIVE_OPERATIONS_DESC_NUM_OPS_IN_PROGRESS.get(),
262           numOpsInProgress);
263    }
264
265    if (! activeOperations.isEmpty())
266    {
267      addMonitorAttribute(attrs,
268           ATTR_OP_IN_PROGRESS,
269           INFO_ACTIVE_OPERATIONS_DISPNAME_OPS_IN_PROGRESS.get(),
270           INFO_ACTIVE_OPERATIONS_DESC_OPS_IN_PROGRESS.get(),
271           activeOperations);
272    }
273
274    if (numPsearchesInProgress != null)
275    {
276      addMonitorAttribute(attrs,
277           ATTR_NUM_PSEARCHES_IN_PROGRESS,
278           INFO_ACTIVE_OPERATIONS_DISPNAME_NUM_PSEARCHES_IN_PROGRESS.get(),
279           INFO_ACTIVE_OPERATIONS_DESC_NUM_PSEARCHES_IN_PROGRESS.get(),
280           numPsearchesInProgress);
281    }
282
283    if (! activePersistentSearches.isEmpty())
284    {
285      addMonitorAttribute(attrs,
286           ATTR_PSEARCH_IN_PROGRESS,
287           INFO_ACTIVE_OPERATIONS_DISPNAME_PSEARCHES_IN_PROGRESS.get(),
288           INFO_ACTIVE_OPERATIONS_DESC_PSEARCHES_IN_PROGRESS.get(),
289           activePersistentSearches);
290    }
291
292    return Collections.unmodifiableMap(attrs);
293  }
294}