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