001/*
002 * Copyright 2008-2024 Ping Identity Corporation
003 * All Rights Reserved.
004 */
005/*
006 * Copyright 2008-2024 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) 2008-2024 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.io.Serializable;
041import java.util.Arrays;
042import java.util.Collections;
043import java.util.Date;
044import java.util.Iterator;
045import java.util.LinkedHashMap;
046import java.util.List;
047import java.util.Map;
048
049import com.unboundid.ldap.sdk.Attribute;
050import com.unboundid.ldap.sdk.Entry;
051import com.unboundid.ldap.sdk.ReadOnlyEntry;
052import com.unboundid.util.Debug;
053import com.unboundid.util.DebugType;
054import com.unboundid.util.NotExtensible;
055import com.unboundid.util.NotNull;
056import com.unboundid.util.Nullable;
057import com.unboundid.util.StaticUtils;
058import com.unboundid.util.ThreadSafety;
059import com.unboundid.util.ThreadSafetyLevel;
060import com.unboundid.util.Validator;
061
062import static com.unboundid.ldap.sdk.unboundidds.monitors.MonitorMessages.*;
063
064
065
066/**
067 * This class defines a generic monitor entry that provides access to monitor
068 * information provided by a Ping Identity, UnboundID, or Nokia/Alcatel-Lucent
069 * 8661 server instance.  Subclasses may provide specific methods for
070 * interpreting the information exposed by specific types of monitor entries.
071 * <BR>
072 * <BLOCKQUOTE>
073 *   <B>NOTE:</B>  This class, and other classes within the
074 *   {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only
075 *   supported for use against Ping Identity, UnboundID, and
076 *   Nokia/Alcatel-Lucent 8661 server products.  These classes provide support
077 *   for proprietary functionality or for external specifications that are not
078 *   considered stable or mature enough to be guaranteed to work in an
079 *   interoperable way with other types of LDAP servers.
080 * </BLOCKQUOTE>
081 * <BR>
082 * See the {@link MonitorManager} class for an example that demonstrates the
083 * process for retrieving all monitor entries available in the directory server
084 * and retrieving the information they provide using the generic API.
085 */
086@NotExtensible()
087@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
088public class MonitorEntry
089       implements Serializable
090{
091  /**
092   * The object class used for all monitor entries.  Specific monitor entries
093   * will have a subclass of this class.
094   */
095  @NotNull static final String GENERIC_MONITOR_OC = "ds-monitor-entry";
096
097
098
099  /**
100   * The base DN for all monitor entries.
101   */
102  @NotNull static final String MONITOR_BASE_DN = "cn=monitor";
103
104
105
106  /**
107   * The name of the attribute used to hold the name assigned to the monitor
108   * entry.
109   */
110  @NotNull private static final String ATTR_MONITOR_NAME = "cn";
111
112
113
114  /**
115   * The serial version UID for this serializable class.
116   */
117  private static final long serialVersionUID = -8889119758772055683L;
118
119
120
121  // The entry containing the information used by this monitor entry object.
122  @NotNull private final ReadOnlyEntry entry;
123
124  // The monitor object class for the associated monitor entry, if available.
125  @NotNull private final String monitorClass;
126
127  // The monitor name for this monitor entry.
128  @Nullable private final String monitorName;
129
130
131
132  /**
133   * Creates a new monitor entry from the information contained in the provided
134   * entry.
135   *
136   * @param  entry  The entry providing information to use for this monitor
137   *                entry.  It must not be {@code null}.
138   */
139  public MonitorEntry(@NotNull final Entry entry)
140  {
141    Validator.ensureNotNull(entry);
142
143    this.entry = new ReadOnlyEntry(entry);
144
145    monitorClass = getMonitorClass(entry);
146    monitorName  = getString(ATTR_MONITOR_NAME);
147  }
148
149
150
151  /**
152   * Retrieves the DN for this monitor entry.
153   *
154   * @return  The DN for this monitor entry.
155   */
156  @NotNull()
157  public final String getDN()
158  {
159    return entry.getDN();
160  }
161
162
163
164  /**
165   * Retrieves the {@code Entry} used to create this monitor entry.
166   *
167   * @return  The {@code Entry} used to create this monitor entry.
168   */
169  @NotNull()
170  public final ReadOnlyEntry getEntry()
171  {
172    return entry;
173  }
174
175
176
177  /**
178   * Retrieves the name of the structural object class for this monitor entry.
179   *
180   * @return  The name of the structural object class for this monitor entry, or
181   *          the generic monitor object class if no appropriate subclass could
182   *          be identified.
183   */
184  @NotNull()
185  public final String getMonitorClass()
186  {
187    return monitorClass;
188  }
189
190
191
192  /**
193   * Retrieves the monitor name for this monitor entry.
194   *
195   * @return  The monitor name for this monitor entry, or {@code null} if it was
196   *          not included in the monitor entry.
197   */
198  @Nullable()
199  public final String getMonitorName()
200  {
201    return monitorName;
202  }
203
204
205
206  /**
207   * Retrieves a human-readable display name for this monitor entry.
208   *
209   * @return  A human-readable display name for this monitor entry.
210   */
211  @NotNull()
212  public String getMonitorDisplayName()
213  {
214    return INFO_GENERIC_MONITOR_DISPNAME.get();
215  }
216
217
218
219  /**
220   * Retrieves a human-readable description name for this monitor entry.
221   *
222   * @return  A human-readable description name for this monitor entry.
223   */
224  @NotNull()
225  public String getMonitorDescription()
226  {
227    return INFO_GENERIC_MONITOR_DESC.get();
228  }
229
230
231
232  /**
233   * Retrieves the set of parsed monitor attributes for this monitor entry,
234   * mapped from a unique identifier (in all lowercase characters) to the
235   * corresponding monitor attribute.
236   *
237   * @return  The set of parsed monitor attributes for this monitor entry.
238   */
239  @NotNull()
240  public Map<String,MonitorAttribute> getMonitorAttributes()
241  {
242    // Retrieve a map of all attributes in the entry except cn and objectClass.
243    final LinkedHashMap<String,MonitorAttribute> attrs =
244         new LinkedHashMap<>(StaticUtils.computeMapCapacity(20));
245
246    for (final Attribute a : entry.getAttributes())
247    {
248      final String lowerName = StaticUtils.toLowerCase(a.getName());
249      if (lowerName.equals("cn") || lowerName.equals("objectclass"))
250      {
251        continue;
252      }
253
254      attrs.put(lowerName,
255           new MonitorAttribute(lowerName, a.getName(), "", a.getValues()));
256    }
257
258    return Collections.unmodifiableMap(attrs);
259  }
260
261
262
263  /**
264   * Creates a monitor entry object from the provided entry.  An attempt will be
265   * made to decode the entry as an instance of the most appropriate subclass,
266   * but if that is not possible then it will be parsed as a generic monitor
267   * entry.
268   *
269   * @param  entry  The entry to be decoded as a monitor entry.
270   *
271   * @return  The decoded monitor entry of the appropriate subtype, or a generic
272   *          monitor entry if no appropriate subclass could be identified.
273   */
274  @NotNull()
275  public static MonitorEntry decode(@NotNull final Entry entry)
276  {
277    final String monitorClass = getMonitorClass(entry);
278
279    if (monitorClass.equalsIgnoreCase(
280             ActiveOperationsMonitorEntry.ACTIVE_OPERATIONS_MONITOR_OC))
281    {
282      return new ActiveOperationsMonitorEntry(entry);
283    }
284    else if (monitorClass.equalsIgnoreCase(
285                  BackendMonitorEntry.BACKEND_MONITOR_OC))
286    {
287      return new BackendMonitorEntry(entry);
288    }
289    else if (monitorClass.equalsIgnoreCase(
290                  ClientConnectionMonitorEntry.CLIENT_CONNECTION_MONITOR_OC))
291    {
292      return new ClientConnectionMonitorEntry(entry);
293    }
294    else if (monitorClass.equalsIgnoreCase(
295                  ConnectionHandlerMonitorEntry.CONNECTION_HANDLER_MONITOR_OC))
296    {
297      return new ConnectionHandlerMonitorEntry(entry);
298    }
299    else if (monitorClass.equalsIgnoreCase(
300                  DiskSpaceUsageMonitorEntry.DISK_SPACE_USAGE_MONITOR_OC))
301    {
302      return new DiskSpaceUsageMonitorEntry(entry);
303    }
304    else if (monitorClass.equalsIgnoreCase(
305                  EntryCacheMonitorEntry.ENTRY_CACHE_MONITOR_OC))
306    {
307      return new EntryCacheMonitorEntry(entry);
308    }
309    else if (monitorClass.equalsIgnoreCase(
310                  FIFOEntryCacheMonitorEntry.FIFO_ENTRY_CACHE_MONITOR_OC))
311    {
312      return new FIFOEntryCacheMonitorEntry(entry);
313    }
314    else if (monitorClass.equalsIgnoreCase(
315                  GaugeMonitorEntry.GAUGE_MONITOR_OC))
316    {
317      return new GaugeMonitorEntry(entry);
318    }
319    else if (monitorClass.equalsIgnoreCase(
320                  GeneralMonitorEntry.GENERAL_MONITOR_OC))
321    {
322      return new GeneralMonitorEntry(entry);
323    }
324    else if (monitorClass.equalsIgnoreCase(
325                  GroupCacheMonitorEntry.GROUP_CACHE_MONITOR_OC))
326    {
327      return new GroupCacheMonitorEntry(entry);
328    }
329    else if (monitorClass.equalsIgnoreCase(
330         HostSystemRecentCPUAndMemoryMonitorEntry.
331              HOST_SYSTEM_RECENT_CPU_AND_MEMORY_MONITOR_OC))
332    {
333      return new HostSystemRecentCPUAndMemoryMonitorEntry(entry);
334    }
335    else if (monitorClass.equalsIgnoreCase(
336                  IndexMonitorEntry.INDEX_MONITOR_OC))
337    {
338      return new IndexMonitorEntry(entry);
339    }
340    else if (monitorClass.equalsIgnoreCase(
341                  IndicatorGaugeMonitorEntry.INDICATOR_GAUGE_MONITOR_OC))
342    {
343      return new IndicatorGaugeMonitorEntry(entry);
344    }
345    else if (monitorClass.equalsIgnoreCase(
346                  JEEnvironmentMonitorEntry.JE_ENVIRONMENT_MONITOR_OC))
347    {
348      return new JEEnvironmentMonitorEntry(entry);
349    }
350    else if (monitorClass.equalsIgnoreCase(
351         LDAPExternalServerMonitorEntry.LDAP_EXTERNAL_SERVER_MONITOR_OC))
352    {
353      return new LDAPExternalServerMonitorEntry(entry);
354    }
355    else if (monitorClass.equalsIgnoreCase(
356                  LDAPStatisticsMonitorEntry.LDAP_STATISTICS_MONITOR_OC))
357    {
358      return new LDAPStatisticsMonitorEntry(entry);
359    }
360    else if (monitorClass.equalsIgnoreCase(
361         LoadBalancingAlgorithmMonitorEntry.
362              LOAD_BALANCING_ALGORITHM_MONITOR_OC))
363    {
364      return new LoadBalancingAlgorithmMonitorEntry(entry);
365    }
366    else if (monitorClass.equalsIgnoreCase(
367                  MemoryUsageMonitorEntry.MEMORY_USAGE_MONITOR_OC))
368    {
369      return new MemoryUsageMonitorEntry(entry);
370    }
371    else if (monitorClass.equalsIgnoreCase(
372                  NumericGaugeMonitorEntry.NUMERIC_GAUGE_MONITOR_OC))
373    {
374      return new NumericGaugeMonitorEntry(entry);
375    }
376    else if (monitorClass.equalsIgnoreCase(
377                  PerApplicationProcessingTimeHistogramMonitorEntry.
378                       PER_APPLICATION_PROCESSING_TIME_HISTOGRAM_MONITOR_OC))
379    {
380      return new PerApplicationProcessingTimeHistogramMonitorEntry(entry);
381    }
382    else if (monitorClass.equalsIgnoreCase(
383                  ProcessingTimeHistogramMonitorEntry.
384                       PROCESSING_TIME_HISTOGRAM_MONITOR_OC))
385    {
386      return new ProcessingTimeHistogramMonitorEntry(entry);
387    }
388    else if (monitorClass.equalsIgnoreCase(
389                  ReplicaMonitorEntry.REPLICA_MONITOR_OC))
390    {
391      return new ReplicaMonitorEntry(entry);
392    }
393    else if (monitorClass.equalsIgnoreCase(
394                  ReplicationServerMonitorEntry.REPLICATION_SERVER_MONITOR_OC))
395    {
396      return new ReplicationServerMonitorEntry(entry);
397    }
398    else if (monitorClass.equalsIgnoreCase(
399                  ReplicationSummaryMonitorEntry.
400                       REPLICATION_SUMMARY_MONITOR_OC))
401    {
402      return new ReplicationSummaryMonitorEntry(entry);
403    }
404    else if (monitorClass.equalsIgnoreCase(
405                  ResultCodeMonitorEntry.RESULT_CODE_MONITOR_OC))
406    {
407      return new ResultCodeMonitorEntry(entry);
408    }
409    else if (monitorClass.equalsIgnoreCase(
410                  StackTraceMonitorEntry.STACK_TRACE_MONITOR_OC))
411    {
412      return new StackTraceMonitorEntry(entry);
413    }
414    else if (monitorClass.equalsIgnoreCase(
415                  SystemInfoMonitorEntry.SYSTEM_INFO_MONITOR_OC))
416    {
417      return new SystemInfoMonitorEntry(entry);
418    }
419    else if (monitorClass.equalsIgnoreCase(
420                  TraditionalWorkQueueMonitorEntry.
421                       TRADITIONAL_WORK_QUEUE_MONITOR_OC))
422    {
423      return new TraditionalWorkQueueMonitorEntry(entry);
424    }
425    else if (monitorClass.equalsIgnoreCase(
426                  UnboundIDWorkQueueMonitorEntry.
427                       UNBOUNDID_WORK_QUEUE_MONITOR_OC))
428    {
429      return new UnboundIDWorkQueueMonitorEntry(entry);
430    }
431    else if (monitorClass.equalsIgnoreCase(
432                  VersionMonitorEntry.VERSION_MONITOR_OC))
433    {
434      return new VersionMonitorEntry(entry);
435    }
436    else if (monitorClass.equalsIgnoreCase(
437                  X509CertificateMonitorEntry.X509_CERTIFICATE_MONITOR_OC))
438    {
439      return new X509CertificateMonitorEntry(entry);
440    }
441
442    return new MonitorEntry(entry);
443  }
444
445
446
447  /**
448   * Gets the most appropriate monitor class from the provided entry.
449   *
450   * @param  entry  The entry from which to extract the monitor class.
451   *
452   * @return  The most appropriate monitor class from the provided entry, or the
453   *          generic monitor object class if no appropriate subclass could be
454   *          identified.
455   */
456  @NotNull()
457  private static String getMonitorClass(@NotNull final Entry entry)
458  {
459    String monitorOC = null;
460    final String[] ocNames = entry.getObjectClassValues();
461    for (final String oc : ocNames)
462    {
463      if (oc.equalsIgnoreCase("top") ||
464          oc.equalsIgnoreCase("extensibleObject") ||
465          oc.equalsIgnoreCase(GENERIC_MONITOR_OC))
466      {
467        // This isn't the class we're looking for.
468        continue;
469      }
470      else if (oc.equalsIgnoreCase(
471                    NumericGaugeMonitorEntry.NUMERIC_GAUGE_MONITOR_OC) ||
472               oc.equalsIgnoreCase(
473                    IndicatorGaugeMonitorEntry.INDICATOR_GAUGE_MONITOR_OC))
474      {
475        // These classes are subclasses of the base gauge monitor class.
476        // We'll allow them even if the monitor class is already set.
477        monitorOC = oc;
478      }
479      else if (oc.equalsIgnoreCase(GaugeMonitorEntry.GAUGE_MONITOR_OC))
480      {
481        // This is a superclass for the numeric and indicator gauge classes.
482        // We'll use it only if the monitor class isn't set, but we won't
483        // complain if the monitor class is already set.
484        if (monitorOC == null)
485        {
486          monitorOC = oc;
487        }
488      }
489      else
490      {
491        if (monitorOC != null)
492        {
493          if (Debug.debugEnabled(DebugType.MONITOR))
494          {
495            Debug.debugMonitor(entry,
496                 "Multiple monitor subclasses detected:  " + monitorOC +
497                      " and " + oc);
498          }
499        }
500
501        monitorOC = oc;
502      }
503    }
504
505    if (monitorOC == null)
506    {
507      if (entry.hasObjectClass(GENERIC_MONITOR_OC))
508      {
509        Debug.debugMonitor(entry, "No appropriate monitor subclass");
510      }
511      else
512      {
513        Debug.debugMonitor(entry, "Missing the generic monitor class");
514      }
515
516      return GENERIC_MONITOR_OC;
517    }
518    else
519    {
520      return monitorOC;
521    }
522  }
523
524
525
526  /**
527   * Retrieves the value of the specified attribute as a {@code Boolean} object.
528   *
529   * @param  attributeName  The name of the target attribute.
530   *
531   * @return  The {@code Boolean} object parsed from the specified attribute, or
532   *          {@code null} if the attribute does not exist in the entry or it
533   *          cannot be parsed as a {@code Boolean} value.
534   */
535  @Nullable()
536  protected final Boolean getBoolean(@NotNull final String attributeName)
537  {
538    final String valueStr = entry.getAttributeValue(attributeName);
539    if (valueStr == null)
540    {
541      if (Debug.debugEnabled(DebugType.MONITOR))
542      {
543        Debug.debugMonitor(entry, "No value for Boolean attribute " +
544             attributeName);
545      }
546
547      return null;
548    }
549    else if (valueStr.equalsIgnoreCase("true"))
550    {
551      return Boolean.TRUE;
552    }
553    else if (valueStr.equalsIgnoreCase("false"))
554    {
555      return Boolean.FALSE;
556    }
557    else
558    {
559      if (Debug.debugEnabled(DebugType.MONITOR))
560      {
561        Debug.debugMonitor(entry,
562             "Invalid value '" + valueStr + "' for Boolean attribute " +
563                  attributeName);
564      }
565
566      return null;
567    }
568  }
569
570
571
572  /**
573   * Retrieves the value of the specified attribute as a {@code Date} object.
574   *
575   * @param  attributeName  The name of the target attribute.
576   *
577   * @return  The {@code Date} object parsed from the specified attribute, or
578   *          {@code null} if the attribute does not exist in the entry or it
579   *          cannot be parsed as a {@code Date} value.
580   */
581  @Nullable()
582  protected final Date getDate(@NotNull final String attributeName)
583  {
584    final String valueStr = entry.getAttributeValue(attributeName);
585    if (valueStr == null)
586    {
587      if (Debug.debugEnabled(DebugType.MONITOR))
588      {
589        Debug.debugMonitor(entry, "No value for Date attribute " +
590             attributeName);
591      }
592
593      return null;
594    }
595    else
596    {
597      try
598      {
599        return StaticUtils.decodeGeneralizedTime(valueStr);
600      }
601      catch (final Exception e)
602      {
603        Debug.debugException(e);
604
605        if (Debug.debugEnabled(DebugType.MONITOR))
606        {
607          Debug.debugMonitor(entry,
608               "Invalid value '" + valueStr + "' for Date attribute " +
609                    attributeName);
610        }
611
612        return null;
613      }
614    }
615  }
616
617
618
619  /**
620   * Retrieves the value of the specified attribute as a {@code Double} object.
621   *
622   * @param  attributeName  The name of the target attribute.
623   *
624   * @return  The {@code Double} object parsed from the specified attribute, or
625   *          {@code null} if the attribute does not exist in the entry or it
626   *          cannot be parsed as a {@code Double} value.
627   */
628  @Nullable()
629  protected final Double getDouble(@NotNull final String attributeName)
630  {
631    final String valueStr = entry.getAttributeValue(attributeName);
632    if (valueStr == null)
633    {
634      if (Debug.debugEnabled(DebugType.MONITOR))
635      {
636        Debug.debugMonitor(entry, "No value for Double attribute " +
637             attributeName);
638      }
639
640      return null;
641    }
642    else
643    {
644      try
645      {
646        return Double.parseDouble(valueStr);
647      }
648      catch (final Exception e)
649      {
650        Debug.debugException(e);
651
652        if (Debug.debugEnabled(DebugType.MONITOR))
653        {
654          Debug.debugMonitor(entry,
655               "Invalid value '" + valueStr + "' for Double attribute " +
656                    attributeName);
657        }
658
659        return null;
660      }
661    }
662  }
663
664
665
666  /**
667   * Retrieves the value of the specified attribute as an {@code Integer}
668   * object.
669   *
670   * @param  attributeName  The name of the target attribute.
671   *
672   * @return  The {@code Integer} object parsed from the specified attribute, or
673   *          {@code null} if the attribute does not exist in the entry or it
674   *          cannot be parsed as an {@code Integer} value.
675   */
676  @Nullable()
677  protected final Integer getInteger(@NotNull final String attributeName)
678  {
679    final String valueStr = entry.getAttributeValue(attributeName);
680    if (valueStr == null)
681    {
682      if (Debug.debugEnabled(DebugType.MONITOR))
683      {
684        Debug.debugMonitor(entry, "No value for Integer attribute " +
685             attributeName);
686      }
687
688      return null;
689    }
690    else
691    {
692      try
693      {
694        return Integer.parseInt(valueStr);
695      }
696      catch (final Exception e)
697      {
698        Debug.debugException(e);
699
700        if (Debug.debugEnabled(DebugType.MONITOR))
701        {
702          Debug.debugMonitor(entry,
703               "Invalid value '" + valueStr + "' for Integer attribute " +
704                    attributeName);
705        }
706
707        return null;
708      }
709    }
710  }
711
712
713
714  /**
715   * Retrieves the value of the specified attribute as a {@code Long} object.
716   *
717   * @param  attributeName  The name of the target attribute.
718   *
719   * @return  The {@code Long} object parsed from the specified attribute, or
720   *          {@code null} if the attribute does not exist in the entry or it
721   *          cannot be parsed as a {@code Long} value.
722   */
723  @Nullable()
724  protected final Long getLong(@NotNull final String attributeName)
725  {
726    final String valueStr = entry.getAttributeValue(attributeName);
727    if (valueStr == null)
728    {
729      if (Debug.debugEnabled(DebugType.MONITOR))
730      {
731        Debug.debugMonitor(entry,
732             "No value for Long attribute " + attributeName);
733      }
734
735      return null;
736    }
737    else
738    {
739      try
740      {
741        return Long.parseLong(valueStr);
742      }
743      catch (final Exception e)
744      {
745        Debug.debugException(e);
746
747        if (Debug.debugEnabled(DebugType.MONITOR))
748        {
749          Debug.debugMonitor(entry,
750               "Invalid value '" + valueStr + "' for Long attribute " +
751                    attributeName);
752        }
753
754        return null;
755      }
756    }
757  }
758
759
760
761  /**
762   * Retrieves the value of the specified attribute as a string.
763   *
764   * @param  attributeName  The name of the target attribute.
765   *
766   * @return  The string value of the specified attribute, or {@code null} if it
767   *          does not exist in the entry.
768   */
769  @Nullable()
770  protected final String getString(@NotNull final String attributeName)
771  {
772    final String valueStr = entry.getAttributeValue(attributeName);
773    if ((valueStr == null) && Debug.debugEnabled(DebugType.MONITOR))
774    {
775      Debug.debugMonitor(entry,
776           "No value for string attribute " + attributeName);
777    }
778
779    return valueStr;
780  }
781
782
783
784  /**
785   * Retrieves the set of values of the specified attribute as a string list.
786   *
787   * @param  attributeName  The name of the target attribute.
788   *
789   * @return  The string values of the specified attribute, or an empty list if
790   *          the specified attribute does not exist in the entry.
791   */
792  @NotNull()
793  protected final List<String> getStrings(@NotNull final String attributeName)
794  {
795    final String[] valueStrs = entry.getAttributeValues(attributeName);
796    if (valueStrs == null)
797    {
798      if (Debug.debugEnabled(DebugType.MONITOR))
799      {
800        Debug.debugMonitor(entry,
801             "No values for string attribute " + attributeName);
802      }
803
804      return Collections.emptyList();
805    }
806
807    return Collections.unmodifiableList(Arrays.asList(valueStrs));
808  }
809
810
811
812  /**
813   * Adds a new monitor attribute to the specified map using the provided
814   * information.
815   *
816   * @param  attrs        The attribute map to which the information should be
817   *                      added.
818   * @param  name         The name to use for this monitor attribute.  It must
819   *                      be unique among all other monitor attribute names for
820   *                      the associated monitor entry.
821   * @param  displayName  The human-readable display name for the monitor
822   *                      attribute.
823   * @param  description  The human-readable description for the monitor
824   *                      attribute.
825   * @param  value        The value for the monitor attribute.
826   */
827  protected static void addMonitorAttribute(
828                 @NotNull final Map<String,MonitorAttribute> attrs,
829                 @NotNull final String name,
830                 @NotNull final String displayName,
831                 @Nullable final String description,
832                 @NotNull final Boolean value)
833  {
834    final String lowerName = StaticUtils.toLowerCase(name);
835
836    final MonitorAttribute a =
837         new MonitorAttribute(lowerName, displayName, description, value);
838    attrs.put(lowerName, a);
839  }
840
841
842
843  /**
844   * Adds a new monitor attribute to the specified map using the provided
845   * information.
846   *
847   * @param  attrs        The attribute map to which the information should be
848   *                      added.
849   * @param  name         The name to use for this monitor attribute.  It must
850   *                      be unique among all other monitor attribute names for
851   *                      the associated monitor entry.
852   * @param  displayName  The human-readable display name for the monitor
853   *                      attribute.
854   * @param  description  The human-readable description for the monitor
855   *                      attribute.
856   * @param  value        The value for the monitor attribute.
857   */
858  protected static void addMonitorAttribute(
859                 @NotNull final Map<String,MonitorAttribute> attrs,
860                 @NotNull final String name,
861                 @NotNull final String displayName,
862                 @Nullable final String description,
863                 @NotNull final Date value)
864  {
865    final String lowerName = StaticUtils.toLowerCase(name);
866
867    final MonitorAttribute a =
868         new MonitorAttribute(lowerName, displayName, description, value);
869    attrs.put(lowerName, a);
870  }
871
872
873
874  /**
875   * Adds a new monitor attribute to the specified map using the provided
876   * information.
877   *
878   * @param  attrs        The attribute map to which the information should be
879   *                      added.
880   * @param  name         The name to use for this monitor attribute.  It must
881   *                      be unique among all other monitor attribute names for
882   *                      the associated monitor entry.
883   * @param  displayName  The human-readable display name for the monitor
884   *                      attribute.
885   * @param  description  The human-readable description for the monitor
886   *                      attribute.
887   * @param  value        The value for the monitor attribute.
888   */
889  protected static void addMonitorAttribute(
890                 @NotNull final Map<String,MonitorAttribute> attrs,
891                 @NotNull final String name,
892                 @NotNull final String displayName,
893                 @Nullable final String description,
894                 @NotNull final Double value)
895  {
896    final String lowerName = StaticUtils.toLowerCase(name);
897
898    final MonitorAttribute a =
899         new MonitorAttribute(lowerName, displayName, description, value);
900    attrs.put(lowerName, a);
901  }
902
903
904
905  /**
906   * Adds a new monitor attribute to the specified map using the provided
907   * information.
908   *
909   * @param  attrs        The attribute map to which the information should be
910   *                      added.
911   * @param  name         The name to use for this monitor attribute.  It must
912   *                      be unique among all other monitor attribute names for
913   *                      the associated monitor entry.
914   * @param  displayName  The human-readable display name for the monitor
915   *                      attribute.
916   * @param  description  The human-readable description for the monitor
917   *                      attribute.
918   * @param  value        The value for the monitor attribute.
919   */
920  protected static void addMonitorAttribute(
921                 @NotNull final Map<String,MonitorAttribute> attrs,
922                 @NotNull final String name,
923                 @NotNull final String displayName,
924                 @Nullable final String description,
925                 @NotNull final Integer value)
926  {
927    final String lowerName = StaticUtils.toLowerCase(name);
928
929    final MonitorAttribute a =
930         new MonitorAttribute(lowerName, displayName, description, value);
931    attrs.put(lowerName, a);
932  }
933
934
935
936  /**
937   * Adds a new monitor attribute to the specified map using the provided
938   * information.
939   *
940   * @param  attrs        The attribute map to which the information should be
941   *                      added.
942   * @param  name         The name to use for this monitor attribute.  It must
943   *                      be unique among all other monitor attribute names for
944   *                      the associated monitor entry.
945   * @param  displayName  The human-readable display name for the monitor
946   *                      attribute.
947   * @param  description  The human-readable description for the monitor
948   *                      attribute.
949   * @param  value        The value for the monitor attribute.
950   */
951  protected static void addMonitorAttribute(
952                 @NotNull final Map<String,MonitorAttribute> attrs,
953                 @NotNull final String name,
954                 @NotNull final String displayName,
955                 @Nullable final String description,
956                 @NotNull final Long value)
957  {
958    final String lowerName = StaticUtils.toLowerCase(name);
959
960    final MonitorAttribute a =
961         new MonitorAttribute(lowerName, displayName, description, value);
962    attrs.put(lowerName, a);
963  }
964
965
966
967  /**
968   * Adds a new monitor attribute to the specified map using the provided
969   * information.
970   *
971   * @param  attrs        The attribute map to which the information should be
972   *                      added.
973   * @param  name         The name to use for this monitor attribute.  It must
974   *                      be unique among all other monitor attribute names for
975   *                      the associated monitor entry.
976   * @param  displayName  The human-readable display name for the monitor
977   *                      attribute.
978   * @param  description  The human-readable description for the monitor
979   *                      attribute.
980   * @param  value        The value for the monitor attribute.
981   */
982  protected static void addMonitorAttribute(
983                 @NotNull final Map<String,MonitorAttribute> attrs,
984                 @NotNull final String name,
985                 @NotNull final String displayName,
986                 @Nullable final String description,
987                 @NotNull final String value)
988  {
989    final String lowerName = StaticUtils.toLowerCase(name);
990
991    final MonitorAttribute a =
992         new MonitorAttribute(lowerName, displayName, description, value);
993    attrs.put(lowerName, a);
994  }
995
996
997
998  /**
999   * Adds a new monitor attribute to the specified map using the provided
1000   * information.
1001   *
1002   * @param  attrs        The attribute map to which the information should be
1003   *                      added.
1004   * @param  name         The name to use for this monitor attribute.  It must
1005   *                      be unique among all other monitor attribute names for
1006   *                      the associated monitor entry.
1007   * @param  displayName  The human-readable display name for the monitor
1008   *                      attribute.
1009   * @param  description  The human-readable description for the monitor
1010   *                      attribute.
1011   * @param  values       The set of values for the monitor attribute.
1012   */
1013  protected static void addMonitorAttribute(
1014                 @NotNull final Map<String,MonitorAttribute> attrs,
1015                 @NotNull final String name,
1016                 @NotNull final String displayName,
1017                 @Nullable final String description,
1018                 @NotNull final List<String> values)
1019  {
1020    final String lowerName = StaticUtils.toLowerCase(name);
1021
1022    final MonitorAttribute a =
1023         new MonitorAttribute(lowerName, displayName, description,
1024                              values.toArray(new String[values.size()]));
1025    attrs.put(lowerName, a);
1026  }
1027
1028
1029
1030  /**
1031   * Retrieves a string representation of this monitor entry.
1032   *
1033   * @return  A string representation of this monitor entry.
1034   */
1035  @Override()
1036  @NotNull()
1037  public final String toString()
1038  {
1039    final StringBuilder buffer = new StringBuilder();
1040    toString(buffer);
1041    return buffer.toString();
1042  }
1043
1044
1045
1046  /**
1047   * Appends a string representation of this monitor entry to the provided
1048   * buffer.
1049   *
1050   * @param  buffer  The buffer to which the information should be appended.
1051   */
1052  public final void toString(@NotNull final StringBuilder buffer)
1053  {
1054    buffer.append("MonitorEntry(dn='");
1055    buffer.append(entry.getDN());
1056    buffer.append("', monitorClass='");
1057    buffer.append(monitorClass);
1058    buffer.append('\'');
1059
1060    final Iterator<MonitorAttribute> iterator =
1061         getMonitorAttributes().values().iterator();
1062    while (iterator.hasNext())
1063    {
1064      buffer.append(iterator.next());
1065      if (iterator.hasNext())
1066      {
1067        buffer.append(", ");
1068      }
1069    }
1070
1071    buffer.append(')');
1072  }
1073}