1 19 20 package org.apache.excalibur.instrument.client; 21 22 import org.apache.avalon.framework.configuration.ConfigurationException; 23 24 31 public class InstrumentSampleUtils 32 { 33 42 public static int resolveInstrumentSampleType( String type ) 43 throws ConfigurationException { 44 45 if ( type.equalsIgnoreCase( "max" ) || type.equalsIgnoreCase( "maximum" ) ) 46 { 47 return InstrumentSampleElementData.INSTRUMENT_SAMPLE_TYPE_MAXIMUM; 48 } 49 else if ( type.equalsIgnoreCase( "min" ) || type.equalsIgnoreCase( "minimum" ) ) 50 { 51 return InstrumentSampleElementData.INSTRUMENT_SAMPLE_TYPE_MINIMUM; 52 } 53 else if ( type.equalsIgnoreCase( "mean" ) ) 54 { 55 return InstrumentSampleElementData.INSTRUMENT_SAMPLE_TYPE_MEAN; 56 } 57 else if ( type.equalsIgnoreCase( "ctr" ) || type.equalsIgnoreCase( "counter" ) ) 58 { 59 return InstrumentSampleElementData.INSTRUMENT_SAMPLE_TYPE_COUNTER; 60 } 61 else 62 { 63 throw new ConfigurationException( "'" + type + "' is not a valid sample type." ); 64 } 65 } 66 67 public static String getInstrumentSampleTypeName( int type ) 68 { 69 switch ( type ) 70 { 71 case InstrumentSampleElementData.INSTRUMENT_SAMPLE_TYPE_MAXIMUM: 72 return "maximum"; 73 74 case InstrumentSampleElementData.INSTRUMENT_SAMPLE_TYPE_MINIMUM: 75 return "minimum"; 76 77 case InstrumentSampleElementData.INSTRUMENT_SAMPLE_TYPE_MEAN: 78 return "mean"; 79 80 case InstrumentSampleElementData.INSTRUMENT_SAMPLE_TYPE_COUNTER: 81 return "counter"; 82 83 default: 84 return "unknown-" + type; 85 } 86 } 87 88 97 public static String generateInstrumentSampleName( int sampleType, 98 long sampleInterval, 99 int sampleSize ) 100 { 101 return getInstrumentSampleTypeName( sampleType ) + "_" + 102 sampleInterval + "_" + sampleSize; 103 } 104 105 115 public static String generateFullInstrumentSampleName( String instrumentName, 116 int sampleType, 117 long sampleInterval, 118 int sampleSize ) 119 { 120 return instrumentName + "." + 121 generateInstrumentSampleName( sampleType, sampleInterval, sampleSize ); 122 } 123 124 132 public static String getDefaultDescriptionForType( int type, long interval ) 133 { 134 StringBuffer sb = new StringBuffer (); 135 switch ( type ) 136 { 137 case InstrumentSampleElementData.INSTRUMENT_SAMPLE_TYPE_COUNTER: 138 sb.append( "Count each " ); 139 break; 140 141 case InstrumentSampleElementData.INSTRUMENT_SAMPLE_TYPE_MAXIMUM: 142 sb.append( "Max Value each " ); 143 break; 144 145 case InstrumentSampleElementData.INSTRUMENT_SAMPLE_TYPE_MEAN: 146 sb.append( "Mean Value each " ); 147 break; 148 149 case InstrumentSampleElementData.INSTRUMENT_SAMPLE_TYPE_MINIMUM: 150 sb.append( "Min Value each " ); 151 break; 152 153 default: 154 return "Unknown Type " + type; 155 } 156 157 if ( interval == 1000 ) 158 { 159 sb.append( "Second" ); 160 } 161 else if ( interval == 60000 ) 162 { 163 sb.append( "Minute" ); 164 } 165 else if ( interval == 3600000 ) 166 { 167 sb.append( "Hour" ); 168 } 169 else if ( interval == 86400000 ) 170 { 171 sb.append( "Day" ); 172 } 173 else if ( interval % 86400000 == 0 ) 174 { 175 sb.append( interval / 86400000 ); 176 sb.append( " Days" ); 177 } 178 else if ( interval % 3600000 == 0 ) 179 { 180 sb.append( interval / 3600000 ); 181 sb.append( " Hours" ); 182 } 183 else if ( interval % 60000 == 0 ) 184 { 185 sb.append( interval / 60000 ); 186 sb.append( " Minutes" ); 187 } 188 else if ( interval % 1000 == 0 ) 189 { 190 sb.append( interval / 1000 ); 191 sb.append( " Seconds" ); 192 } 193 else 194 { 195 sb.append( interval ); 196 sb.append( " Milliseconds" ); 197 } 198 199 return sb.toString(); 200 } 201 } 202 | Popular Tags |