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