001/*
002 * Copyright 2014-2018 Ping Identity Corporation
003 * All Rights Reserved.
004 */
005/*
006 * Copyright (C) 2015-2018 Ping Identity Corporation
007 *
008 * This program is free software; you can redistribute it and/or modify
009 * it under the terms of the GNU General Public License (GPLv2 only)
010 * or the terms of the GNU Lesser General Public License (LGPLv2.1 only)
011 * as published by the Free Software Foundation.
012 *
013 * This program is distributed in the hope that it will be useful,
014 * but WITHOUT ANY WARRANTY; without even the implied warranty of
015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
016 * GNU General Public License for more details.
017 *
018 * You should have received a copy of the GNU General Public License
019 * along with this program; if not, see <http://www.gnu.org/licenses>.
020 */
021package com.unboundid.ldap.sdk.unboundidds.monitors;
022
023
024
025import java.util.ArrayList;
026import java.util.Collections;
027import java.util.LinkedHashMap;
028import java.util.List;
029import java.util.Map;
030import java.util.StringTokenizer;
031
032import com.unboundid.ldap.sdk.Entry;
033import com.unboundid.util.NotMutable;
034import com.unboundid.util.ThreadSafety;
035import com.unboundid.util.ThreadSafetyLevel;
036
037import static com.unboundid.ldap.sdk.unboundidds.monitors.MonitorMessages.*;
038
039
040
041/**
042 * This class defines an indicator gauge monitor entry, which obtains its
043 * information from a non-numeric value in a monitor entry.
044 * <BR>
045 * <BLOCKQUOTE>
046 *   <B>NOTE:</B>  This class, and other classes within the
047 *   {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only
048 *   supported for use against Ping Identity, UnboundID, and
049 *   Nokia/Alcatel-Lucent 8661 server products.  These classes provide support
050 *   for proprietary functionality or for external specifications that are not
051 *   considered stable or mature enough to be guaranteed to work in an
052 *   interoperable way with other types of LDAP servers.
053 * </BLOCKQUOTE>
054 */
055@NotMutable()
056@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
057public final class IndicatorGaugeMonitorEntry
058       extends GaugeMonitorEntry
059{
060  /**
061   * The structural object class used in gauge monitor entries.
062   */
063  static final String INDICATOR_GAUGE_MONITOR_OC =
064       "ds-indicator-gauge-monitor-entry";
065
066
067
068  /**
069   * The serial version UID for this serializable class.
070   */
071  private static final long serialVersionUID = 6487368235968435879L;
072
073
074
075  // The set of observed values for the gauge.
076  private final List<String> observedValues;
077
078  // The current value for the gauge.
079  private final String currentValue;
080
081  // The previous value observed for the gauge.
082  private final String previousValue;
083
084
085
086  /**
087   * Creates a new indicator gauge monitor entry from the provided entry.
088   *
089   * @param  entry  The entry to be parsed as a indicator gauge monitor entry.
090   *                It must not be {@code null}.
091   */
092  public IndicatorGaugeMonitorEntry(final Entry entry)
093  {
094    super(entry);
095
096    currentValue = getString("value");
097    previousValue = getString("previous-value");
098
099    final String observedValuesStr = getString("observed-values");
100    if (observedValuesStr == null)
101    {
102      observedValues = Collections.emptyList();
103    }
104    else
105    {
106      final ArrayList<String> valueList = new ArrayList<>(10);
107      final StringTokenizer tokenizer =
108           new StringTokenizer(observedValuesStr, ",");
109      while (tokenizer.hasMoreTokens())
110      {
111        valueList.add(tokenizer.nextToken());
112      }
113      observedValues = Collections.unmodifiableList(valueList);
114    }
115  }
116
117
118
119  /**
120   * Retrieves the current value for the gauge, if available.
121   *
122   * @return The current value for the gauge, or {@code null} if it was not
123   *          included in the monitor entry.
124   */
125  public String getCurrentValue()
126  {
127    return currentValue;
128  }
129
130
131
132  /**
133   * Retrieves the previous value for the gauge, if available.
134   *
135   * @return  The previous value for the gauge, or {@code null} if it was not
136   *          included in the monitor entry.
137   */
138  public String getPreviousValue()
139  {
140    return previousValue;
141  }
142
143
144
145  /**
146   * Retrieves the set of observed values for the gauge, if available.
147   *
148   * @return  The set of observed values for the gauge, or {@code null} if it
149   *          was not included in the monitor entry.
150   */
151  public List<String> getObservedValues()
152  {
153    return observedValues;
154  }
155
156
157
158  /**
159   * {@inheritDoc}
160   */
161  @Override()
162  public String getMonitorDisplayName()
163  {
164    return INFO_INDICATOR_GAUGE_MONITOR_DISPNAME.get();
165  }
166
167
168
169  /**
170   * {@inheritDoc}
171   */
172  @Override()
173  public String getMonitorDescription()
174  {
175    return INFO_INDICATOR_GAUGE_MONITOR_DESC.get();
176  }
177
178
179
180  /**
181   * {@inheritDoc}
182   */
183  @Override()
184  public Map<String,MonitorAttribute> getMonitorAttributes()
185  {
186    final Map<String,MonitorAttribute> superAttributes =
187         super.getMonitorAttributes();
188
189    final LinkedHashMap<String,MonitorAttribute> attrs =
190         new LinkedHashMap<>(superAttributes.size() + 3);
191    attrs.putAll(superAttributes);
192
193    if (currentValue != null)
194    {
195      addMonitorAttribute(attrs,
196           "value",
197           INFO_INDICATOR_GAUGE_DISPNAME_CURRENT_VALUE.get(),
198           INFO_INDICATOR_GAUGE_DESC_CURRENT_VALUE.get(),
199           currentValue);
200    }
201
202    if (previousValue != null)
203    {
204      addMonitorAttribute(attrs,
205           "previous-value",
206           INFO_INDICATOR_GAUGE_DISPNAME_PREVIOUS_VALUE.get(),
207           INFO_INDICATOR_GAUGE_DESC_PREVIOUS_VALUE.get(),
208           previousValue);
209    }
210
211    if (! observedValues.isEmpty())
212    {
213      addMonitorAttribute(attrs,
214           "observed-values",
215           INFO_INDICATOR_GAUGE_DISPNAME_OBSERVED_VALUES.get(),
216           INFO_INDICATOR_GAUGE_DESC_OBSERVED_VALUES.get(),
217           observedValues);
218    }
219
220    return Collections.unmodifiableMap(attrs);
221  }
222}