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