001/*
002 * Copyright 2008-2021 Ping Identity Corporation
003 * All Rights Reserved.
004 */
005/*
006 * Copyright 2008-2021 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-2021 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
437    return new MonitorEntry(entry);
438  }
439
440
441
442  /**
443   * Gets the most appropriate monitor class from the provided entry.
444   *
445   * @param  entry  The entry from which to extract the monitor class.
446   *
447   * @return  The most appropriate monitor class from the provided entry, or the
448   *          generic monitor object class if no appropriate subclass could be
449   *          identified.
450   */
451  @NotNull()
452  private static String getMonitorClass(@NotNull final Entry entry)
453  {
454    String monitorOC = null;
455    final String[] ocNames = entry.getObjectClassValues();
456    for (final String oc : ocNames)
457    {
458      if (oc.equalsIgnoreCase("top") ||
459          oc.equalsIgnoreCase("extensibleObject") ||
460          oc.equalsIgnoreCase(GENERIC_MONITOR_OC))
461      {
462        // This isn't the class we're looking for.
463        continue;
464      }
465      else if (oc.equalsIgnoreCase(
466                    NumericGaugeMonitorEntry.NUMERIC_GAUGE_MONITOR_OC) ||
467               oc.equalsIgnoreCase(
468                    IndicatorGaugeMonitorEntry.INDICATOR_GAUGE_MONITOR_OC))
469      {
470        // These classes are subclasses of the base gauge monitor class.
471        // We'll allow them even if the monitor class is already set.
472        monitorOC = oc;
473      }
474      else if (oc.equalsIgnoreCase(GaugeMonitorEntry.GAUGE_MONITOR_OC))
475      {
476        // This is a superclass for the numeric and indicator gauge classes.
477        // We'll use it only if the monitor class isn't set, but we won't
478        // complain if the monitor class is already set.
479        if (monitorOC == null)
480        {
481          monitorOC = oc;
482        }
483      }
484      else
485      {
486        if (monitorOC != null)
487        {
488          if (Debug.debugEnabled(DebugType.MONITOR))
489          {
490            Debug.debugMonitor(entry,
491                 "Multiple monitor subclasses detected:  " + monitorOC +
492                      " and " + oc);
493          }
494        }
495
496        monitorOC = oc;
497      }
498    }
499
500    if (monitorOC == null)
501    {
502      if (entry.hasObjectClass(GENERIC_MONITOR_OC))
503      {
504        Debug.debugMonitor(entry, "No appropriate monitor subclass");
505      }
506      else
507      {
508        Debug.debugMonitor(entry, "Missing the generic monitor class");
509      }
510
511      return GENERIC_MONITOR_OC;
512    }
513    else
514    {
515      return monitorOC;
516    }
517  }
518
519
520
521  /**
522   * Retrieves the value of the specified attribute as a {@code Boolean} object.
523   *
524   * @param  attributeName  The name of the target attribute.
525   *
526   * @return  The {@code Boolean} object parsed from the specified attribute, or
527   *          {@code null} if the attribute does not exist in the entry or it
528   *          cannot be parsed as a {@code Boolean} value.
529   */
530  @Nullable()
531  protected final Boolean getBoolean(@NotNull final String attributeName)
532  {
533    final String valueStr = entry.getAttributeValue(attributeName);
534    if (valueStr == null)
535    {
536      if (Debug.debugEnabled(DebugType.MONITOR))
537      {
538        Debug.debugMonitor(entry, "No value for Boolean attribute " +
539             attributeName);
540      }
541
542      return null;
543    }
544    else if (valueStr.equalsIgnoreCase("true"))
545    {
546      return Boolean.TRUE;
547    }
548    else if (valueStr.equalsIgnoreCase("false"))
549    {
550      return Boolean.FALSE;
551    }
552    else
553    {
554      if (Debug.debugEnabled(DebugType.MONITOR))
555      {
556        Debug.debugMonitor(entry,
557             "Invalid value '" + valueStr + "' for Boolean attribute " +
558                  attributeName);
559      }
560
561      return null;
562    }
563  }
564
565
566
567  /**
568   * Retrieves the value of the specified attribute as a {@code Date} object.
569   *
570   * @param  attributeName  The name of the target attribute.
571   *
572   * @return  The {@code Date} object parsed from the specified attribute, or
573   *          {@code null} if the attribute does not exist in the entry or it
574   *          cannot be parsed as a {@code Date} value.
575   */
576  @Nullable()
577  protected final Date getDate(@NotNull final String attributeName)
578  {
579    final String valueStr = entry.getAttributeValue(attributeName);
580    if (valueStr == null)
581    {
582      if (Debug.debugEnabled(DebugType.MONITOR))
583      {
584        Debug.debugMonitor(entry, "No value for Date attribute " +
585             attributeName);
586      }
587
588      return null;
589    }
590    else
591    {
592      try
593      {
594        return StaticUtils.decodeGeneralizedTime(valueStr);
595      }
596      catch (final Exception e)
597      {
598        Debug.debugException(e);
599
600        if (Debug.debugEnabled(DebugType.MONITOR))
601        {
602          Debug.debugMonitor(entry,
603               "Invalid value '" + valueStr + "' for Date attribute " +
604                    attributeName);
605        }
606
607        return null;
608      }
609    }
610  }
611
612
613
614  /**
615   * Retrieves the value of the specified attribute as a {@code Double} object.
616   *
617   * @param  attributeName  The name of the target attribute.
618   *
619   * @return  The {@code Double} object parsed from the specified attribute, or
620   *          {@code null} if the attribute does not exist in the entry or it
621   *          cannot be parsed as a {@code Double} value.
622   */
623  @Nullable()
624  protected final Double getDouble(@NotNull final String attributeName)
625  {
626    final String valueStr = entry.getAttributeValue(attributeName);
627    if (valueStr == null)
628    {
629      if (Debug.debugEnabled(DebugType.MONITOR))
630      {
631        Debug.debugMonitor(entry, "No value for Double attribute " +
632             attributeName);
633      }
634
635      return null;
636    }
637    else
638    {
639      try
640      {
641        return Double.parseDouble(valueStr);
642      }
643      catch (final Exception e)
644      {
645        Debug.debugException(e);
646
647        if (Debug.debugEnabled(DebugType.MONITOR))
648        {
649          Debug.debugMonitor(entry,
650               "Invalid value '" + valueStr + "' for Double attribute " +
651                    attributeName);
652        }
653
654        return null;
655      }
656    }
657  }
658
659
660
661  /**
662   * Retrieves the value of the specified attribute as an {@code Integer}
663   * object.
664   *
665   * @param  attributeName  The name of the target attribute.
666   *
667   * @return  The {@code Integer} object parsed from the specified attribute, or
668   *          {@code null} if the attribute does not exist in the entry or it
669   *          cannot be parsed as an {@code Integer} value.
670   */
671  @Nullable()
672  protected final Integer getInteger(@NotNull final String attributeName)
673  {
674    final String valueStr = entry.getAttributeValue(attributeName);
675    if (valueStr == null)
676    {
677      if (Debug.debugEnabled(DebugType.MONITOR))
678      {
679        Debug.debugMonitor(entry, "No value for Integer attribute " +
680             attributeName);
681      }
682
683      return null;
684    }
685    else
686    {
687      try
688      {
689        return Integer.parseInt(valueStr);
690      }
691      catch (final Exception e)
692      {
693        Debug.debugException(e);
694
695        if (Debug.debugEnabled(DebugType.MONITOR))
696        {
697          Debug.debugMonitor(entry,
698               "Invalid value '" + valueStr + "' for Integer attribute " +
699                    attributeName);
700        }
701
702        return null;
703      }
704    }
705  }
706
707
708
709  /**
710   * Retrieves the value of the specified attribute as a {@code Long} object.
711   *
712   * @param  attributeName  The name of the target attribute.
713   *
714   * @return  The {@code Long} object parsed from the specified attribute, or
715   *          {@code null} if the attribute does not exist in the entry or it
716   *          cannot be parsed as a {@code Long} value.
717   */
718  @Nullable()
719  protected final Long getLong(@NotNull final String attributeName)
720  {
721    final String valueStr = entry.getAttributeValue(attributeName);
722    if (valueStr == null)
723    {
724      if (Debug.debugEnabled(DebugType.MONITOR))
725      {
726        Debug.debugMonitor(entry,
727             "No value for Long attribute " + attributeName);
728      }
729
730      return null;
731    }
732    else
733    {
734      try
735      {
736        return Long.parseLong(valueStr);
737      }
738      catch (final Exception e)
739      {
740        Debug.debugException(e);
741
742        if (Debug.debugEnabled(DebugType.MONITOR))
743        {
744          Debug.debugMonitor(entry,
745               "Invalid value '" + valueStr + "' for Long attribute " +
746                    attributeName);
747        }
748
749        return null;
750      }
751    }
752  }
753
754
755
756  /**
757   * Retrieves the value of the specified attribute as a string.
758   *
759   * @param  attributeName  The name of the target attribute.
760   *
761   * @return  The string value of the specified attribute, or {@code null} if it
762   *          does not exist in the entry.
763   */
764  @Nullable()
765  protected final String getString(@NotNull final String attributeName)
766  {
767    final String valueStr = entry.getAttributeValue(attributeName);
768    if ((valueStr == null) && Debug.debugEnabled(DebugType.MONITOR))
769    {
770      Debug.debugMonitor(entry,
771           "No value for string attribute " + attributeName);
772    }
773
774    return valueStr;
775  }
776
777
778
779  /**
780   * Retrieves the set of values of the specified attribute as a string list.
781   *
782   * @param  attributeName  The name of the target attribute.
783   *
784   * @return  The string values of the specified attribute, or an empty list if
785   *          the specified attribute does not exist in the entry.
786   */
787  @NotNull()
788  protected final List<String> getStrings(@NotNull final String attributeName)
789  {
790    final String[] valueStrs = entry.getAttributeValues(attributeName);
791    if (valueStrs == null)
792    {
793      if (Debug.debugEnabled(DebugType.MONITOR))
794      {
795        Debug.debugMonitor(entry,
796             "No values for string attribute " + attributeName);
797      }
798
799      return Collections.emptyList();
800    }
801
802    return Collections.unmodifiableList(Arrays.asList(valueStrs));
803  }
804
805
806
807  /**
808   * Adds a new monitor attribute to the specified map using the provided
809   * information.
810   *
811   * @param  attrs        The attribute map to which the information should be
812   *                      added.
813   * @param  name         The name to use for this monitor attribute.  It must
814   *                      be unique among all other monitor attribute names for
815   *                      the associated monitor entry.
816   * @param  displayName  The human-readable display name for the monitor
817   *                      attribute.
818   * @param  description  The human-readable description for the monitor
819   *                      attribute.
820   * @param  value        The value for the monitor attribute.
821   */
822  protected static void addMonitorAttribute(
823                 @NotNull final Map<String,MonitorAttribute> attrs,
824                 @NotNull final String name,
825                 @NotNull final String displayName,
826                 @Nullable final String description,
827                 @NotNull final Boolean value)
828  {
829    final String lowerName = StaticUtils.toLowerCase(name);
830
831    final MonitorAttribute a =
832         new MonitorAttribute(lowerName, displayName, description, value);
833    attrs.put(lowerName, a);
834  }
835
836
837
838  /**
839   * Adds a new monitor attribute to the specified map using the provided
840   * information.
841   *
842   * @param  attrs        The attribute map to which the information should be
843   *                      added.
844   * @param  name         The name to use for this monitor attribute.  It must
845   *                      be unique among all other monitor attribute names for
846   *                      the associated monitor entry.
847   * @param  displayName  The human-readable display name for the monitor
848   *                      attribute.
849   * @param  description  The human-readable description for the monitor
850   *                      attribute.
851   * @param  value        The value for the monitor attribute.
852   */
853  protected static void addMonitorAttribute(
854                 @NotNull final Map<String,MonitorAttribute> attrs,
855                 @NotNull final String name,
856                 @NotNull final String displayName,
857                 @Nullable final String description,
858                 @NotNull final Date value)
859  {
860    final String lowerName = StaticUtils.toLowerCase(name);
861
862    final MonitorAttribute a =
863         new MonitorAttribute(lowerName, displayName, description, value);
864    attrs.put(lowerName, a);
865  }
866
867
868
869  /**
870   * Adds a new monitor attribute to the specified map using the provided
871   * information.
872   *
873   * @param  attrs        The attribute map to which the information should be
874   *                      added.
875   * @param  name         The name to use for this monitor attribute.  It must
876   *                      be unique among all other monitor attribute names for
877   *                      the associated monitor entry.
878   * @param  displayName  The human-readable display name for the monitor
879   *                      attribute.
880   * @param  description  The human-readable description for the monitor
881   *                      attribute.
882   * @param  value        The value for the monitor attribute.
883   */
884  protected static void addMonitorAttribute(
885                 @NotNull final Map<String,MonitorAttribute> attrs,
886                 @NotNull final String name,
887                 @NotNull final String displayName,
888                 @Nullable final String description,
889                 @NotNull final Double value)
890  {
891    final String lowerName = StaticUtils.toLowerCase(name);
892
893    final MonitorAttribute a =
894         new MonitorAttribute(lowerName, displayName, description, value);
895    attrs.put(lowerName, a);
896  }
897
898
899
900  /**
901   * Adds a new monitor attribute to the specified map using the provided
902   * information.
903   *
904   * @param  attrs        The attribute map to which the information should be
905   *                      added.
906   * @param  name         The name to use for this monitor attribute.  It must
907   *                      be unique among all other monitor attribute names for
908   *                      the associated monitor entry.
909   * @param  displayName  The human-readable display name for the monitor
910   *                      attribute.
911   * @param  description  The human-readable description for the monitor
912   *                      attribute.
913   * @param  value        The value for the monitor attribute.
914   */
915  protected static void addMonitorAttribute(
916                 @NotNull final Map<String,MonitorAttribute> attrs,
917                 @NotNull final String name,
918                 @NotNull final String displayName,
919                 @Nullable final String description,
920                 @NotNull final Integer value)
921  {
922    final String lowerName = StaticUtils.toLowerCase(name);
923
924    final MonitorAttribute a =
925         new MonitorAttribute(lowerName, displayName, description, value);
926    attrs.put(lowerName, a);
927  }
928
929
930
931  /**
932   * Adds a new monitor attribute to the specified map using the provided
933   * information.
934   *
935   * @param  attrs        The attribute map to which the information should be
936   *                      added.
937   * @param  name         The name to use for this monitor attribute.  It must
938   *                      be unique among all other monitor attribute names for
939   *                      the associated monitor entry.
940   * @param  displayName  The human-readable display name for the monitor
941   *                      attribute.
942   * @param  description  The human-readable description for the monitor
943   *                      attribute.
944   * @param  value        The value for the monitor attribute.
945   */
946  protected static void addMonitorAttribute(
947                 @NotNull final Map<String,MonitorAttribute> attrs,
948                 @NotNull final String name,
949                 @NotNull final String displayName,
950                 @Nullable final String description,
951                 @NotNull final Long value)
952  {
953    final String lowerName = StaticUtils.toLowerCase(name);
954
955    final MonitorAttribute a =
956         new MonitorAttribute(lowerName, displayName, description, value);
957    attrs.put(lowerName, a);
958  }
959
960
961
962  /**
963   * Adds a new monitor attribute to the specified map using the provided
964   * information.
965   *
966   * @param  attrs        The attribute map to which the information should be
967   *                      added.
968   * @param  name         The name to use for this monitor attribute.  It must
969   *                      be unique among all other monitor attribute names for
970   *                      the associated monitor entry.
971   * @param  displayName  The human-readable display name for the monitor
972   *                      attribute.
973   * @param  description  The human-readable description for the monitor
974   *                      attribute.
975   * @param  value        The value for the monitor attribute.
976   */
977  protected static void addMonitorAttribute(
978                 @NotNull final Map<String,MonitorAttribute> attrs,
979                 @NotNull final String name,
980                 @NotNull final String displayName,
981                 @Nullable final String description,
982                 @NotNull final String value)
983  {
984    final String lowerName = StaticUtils.toLowerCase(name);
985
986    final MonitorAttribute a =
987         new MonitorAttribute(lowerName, displayName, description, value);
988    attrs.put(lowerName, a);
989  }
990
991
992
993  /**
994   * Adds a new monitor attribute to the specified map using the provided
995   * information.
996   *
997   * @param  attrs        The attribute map to which the information should be
998   *                      added.
999   * @param  name         The name to use for this monitor attribute.  It must
1000   *                      be unique among all other monitor attribute names for
1001   *                      the associated monitor entry.
1002   * @param  displayName  The human-readable display name for the monitor
1003   *                      attribute.
1004   * @param  description  The human-readable description for the monitor
1005   *                      attribute.
1006   * @param  values       The set of values for the monitor attribute.
1007   */
1008  protected static void addMonitorAttribute(
1009                 @NotNull final Map<String,MonitorAttribute> attrs,
1010                 @NotNull final String name,
1011                 @NotNull final String displayName,
1012                 @Nullable final String description,
1013                 @NotNull final List<String> values)
1014  {
1015    final String lowerName = StaticUtils.toLowerCase(name);
1016
1017    final MonitorAttribute a =
1018         new MonitorAttribute(lowerName, displayName, description,
1019                              values.toArray(new String[values.size()]));
1020    attrs.put(lowerName, a);
1021  }
1022
1023
1024
1025  /**
1026   * Retrieves a string representation of this monitor entry.
1027   *
1028   * @return  A string representation of this monitor entry.
1029   */
1030  @Override()
1031  @NotNull()
1032  public final String toString()
1033  {
1034    final StringBuilder buffer = new StringBuilder();
1035    toString(buffer);
1036    return buffer.toString();
1037  }
1038
1039
1040
1041  /**
1042   * Appends a string representation of this monitor entry to the provided
1043   * buffer.
1044   *
1045   * @param  buffer  The buffer to which the information should be appended.
1046   */
1047  public final void toString(@NotNull final StringBuilder buffer)
1048  {
1049    buffer.append("MonitorEntry(dn='");
1050    buffer.append(entry.getDN());
1051    buffer.append("', monitorClass='");
1052    buffer.append(monitorClass);
1053    buffer.append('\'');
1054
1055    final Iterator<MonitorAttribute> iterator =
1056         getMonitorAttributes().values().iterator();
1057    while (iterator.hasNext())
1058    {
1059      buffer.append(iterator.next());
1060      if (iterator.hasNext())
1061      {
1062        buffer.append(", ");
1063      }
1064    }
1065
1066    buffer.append(')');
1067  }
1068}