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