|
StatsValue |
|
1 package com.mccrory.scott.spumoni; 2 3 //////////////////////////////////////////////////////////////////////////////// 4 // Copyright (C) 2002 Scott McCrory 5 // 6 // This program is free software; you can redistribute it and/or 7 // modify it under the terms of the GNU General Public License 8 // as published by the Free Software Foundation; either version 2 9 // of the License, or (at your option) any later version. 10 // 11 // This program is distributed in the hope that it will be useful, 12 // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 // GNU General Public License for more details. 15 // 16 // You should have received a copy of the GNU General Public License 17 // along with this program; if not, write to the Free Software 18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 //////////////////////////////////////////////////////////////////////////////// 20 21 import java.io.IOException; 22 import java.io.ObjectInputStream; 23 import java.io.ObjectOutputStream; 24 25 /** 26 * <P><code>StatsValue</code> is a data object for a statistics program's single value. 27 * It also contains related attributes such as name, value, SNMP OID, trap min 28 * and trap max.</P> 29 * 30 * @author <a href="mailto:smccrory@users.sourceforge.net">Scott McCrory</a>. 31 * @version CVS $Id: StatsValue.java,v 1.8 2002/08/04 22:04:53 smccrory Exp $ 32 */ 33 public class StatsValue { 34 35 /** The name of this class to log context without introspection **/ 36 private static final String CLASS_NAME = "StatsValue"; 37 38 /** The version of this class (filled in by CVS) **/ 39 private static final String VERSION = "CVS $Revision: 1.8 $"; 40 41 /** A string defining an unset value **/ 42 private static final String UNSET_VALUE = "*!*Unset_Value*!*"; 43 44 /** The program value's name **/ 45 private String valueName = ""; 46 47 /** The program value's SNMP OID **/ 48 private String snmpOid = ""; 49 50 /** The program value's minimum before a trap is sent **/ 51 private int snmpTrapMin = -2147483648; 52 53 /** The program value's maximum before a trap is sent **/ 54 private int snmpTrapMax = 2147483647; 55 56 /** The program value's actual collected value **/ 57 private String value = UNSET_VALUE; 58 /** 59 * Basic StatsValue constructor. 60 */ 61 public StatsValue() { 62 super(); 63 } 64 65 /** 66 * A convenience StatsValue contructor to set all of the data elements 67 * at time of creation. 68 * 69 * @param newValueName The name of this stats value 70 * @param newSnmpOid The SNMP OID 71 * @param newSnmpTrapMin The minimum value before sending an SNMP Trap 72 * @param newSnmpTrapMax The maximum value before sending an SNMP Trap 73 */ 74 public StatsValue( 75 String newValueName, 76 String newSnmpOid, 77 int newSnmpTrapMin, 78 int newSnmpTrapMax) { 79 80 this(); 81 82 valueName = newValueName; 83 snmpOid = newSnmpOid; 84 snmpTrapMin = newSnmpTrapMin; 85 snmpTrapMax = newSnmpTrapMax; 86 87 } 88 89 /** 90 * We override the <code>clone</code> method here to prevent cloning of our class. 91 * 92 * @throws CloneNotSupportedException To indicate cloning is not allowed 93 * @return Nothing ever really returned since we throw a CloneNotSupportedException 94 **/ 95 public final Object clone() throws CloneNotSupportedException { 96 97 throw new CloneNotSupportedException(); 98 99 } 100 101 /** 102 * Returns the SNMP OID. 103 * @return java.lang.String 104 */ 105 public java.lang.String getSnmpOid() { 106 return snmpOid; 107 } 108 109 /** 110 * Returns the max acceptable value before an SMTP trap is sent. 111 * @return int 112 */ 113 public int getSnmpTrapMax() { 114 return snmpTrapMax; 115 } 116 117 /** 118 * Returns the min acceptable value before an SMTP trap is sent. 119 * @return int 120 */ 121 public int getSnmpTrapMin() { 122 return snmpTrapMin; 123 } 124 125 /** 126 * Gets the program value's actual collected value. 127 * @return java.lang.String 128 */ 129 public java.lang.String getValue() { 130 return value; 131 } 132 133 /** 134 * Returns the value name. 135 * @return java.lang.String 136 */ 137 public java.lang.String getValueName() { 138 return valueName; 139 } 140 141 /** 142 * Returns whether value is unset. 143 * @return boolean 144 */ 145 public boolean isUnset() { 146 147 if (value.equals(UNSET_VALUE)) { 148 return true; 149 } 150 else { 151 return false; 152 } 153 154 } 155 156 /** 157 * We override the <code>readObject</code> method here to prevent 158 * deserialization of our class for security reasons. 159 * 160 * @param in java.io.ObjectInputStream 161 * @throws IOException thrown if a problem occurs 162 **/ 163 private final void readObject(ObjectInputStream in) throws IOException { 164 165 throw new IOException("Object cannot be deserialized"); 166 167 } 168 169 /** 170 * Sets the SNMP OID. 171 * @param newSnmpOid java.lang.String 172 */ 173 public void setSnmpOid(java.lang.String newSnmpOid) { 174 snmpOid = newSnmpOid; 175 } 176 177 /** 178 * Sets the max acceptable value before an SMTP trap is sent. 179 * @param newSnmpTrapMax int 180 */ 181 public void setSnmpTrapMax(int newSnmpTrapMax) { 182 snmpTrapMax = newSnmpTrapMax; 183 } 184 185 /** 186 * Sets the min acceptable value before an SMTP trap is sent. 187 * @param newSnmpTrapMin int 188 */ 189 public void setSnmpTrapMin(int newSnmpTrapMin) { 190 snmpTrapMin = newSnmpTrapMin; 191 } 192 193 /** 194 * Sets the program value's actual collected value. 195 * @param newValue java.lang.String 196 */ 197 public void setValue(java.lang.String newValue) { 198 value = newValue; 199 } 200 201 /** 202 * Sets the value name. 203 * @param newValueName java.lang.String 204 */ 205 public void setValueName(java.lang.String newValueName) { 206 valueName = newValueName; 207 } 208 209 /** 210 * Returns a formatted String of this object's values 211 * @return java.lang.String 212 */ 213 public String toString() { 214 String s = 215 "valueName='" 216 + valueName 217 + "', " 218 + "value='" 219 + value 220 + "', " 221 + "snmpOid='" 222 + snmpOid 223 + "', " 224 + "snmpTrapMin='" 225 + snmpTrapMin 226 + "', " 227 + "snmpTrapMax='" 228 + snmpTrapMax 229 + "'"; 230 return s; 231 } 232 233 /** 234 * Unsets the value 235 */ 236 public void unset() { 237 238 value = UNSET_VALUE; 239 240 } 241 242 /** 243 * We override the <code>writeObject</code> method here to prevent 244 * serialization of our class for security reasons. 245 * 246 * @param out java.io.ObjectOutputStream 247 * @throws IOException thrown if a problem occurs 248 **/ 249 private final void writeObject(ObjectOutputStream out) throws IOException { 250 251 throw new IOException("Object cannot be serialized"); 252 253 } 254 255 }
|
StatsValue |
|