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