1 19 20 package org.apache.excalibur.instrument.manager; 21 22 import org.apache.avalon.framework.configuration.ConfigurationException; 23 24 30 public class InstrumentSampleUtils 31 { 32 41 public static int resolveInstrumentSampleType( String type ) 42 throws ConfigurationException { 43 44 if ( type.equalsIgnoreCase( "max" ) || type.equalsIgnoreCase( "maximum" ) ) 45 { 46 return DefaultInstrumentManager.INSTRUMENT_SAMPLE_TYPE_MAXIMUM; 47 } 48 else if ( type.equalsIgnoreCase( "min" ) || type.equalsIgnoreCase( "minimum" ) ) 49 { 50 return DefaultInstrumentManager.INSTRUMENT_SAMPLE_TYPE_MINIMUM; 51 } 52 else if ( type.equalsIgnoreCase( "mean" ) ) 53 { 54 return DefaultInstrumentManager.INSTRUMENT_SAMPLE_TYPE_MEAN; 55 } 56 else if ( type.equalsIgnoreCase( "ctr" ) || type.equalsIgnoreCase( "counter" ) ) 57 { 58 return DefaultInstrumentManager.INSTRUMENT_SAMPLE_TYPE_COUNTER; 59 } 60 else 61 { 62 throw new ConfigurationException( "'" + type + "' is not a valid sample type." ); 63 } 64 } 65 66 public static String getInstrumentSampleTypeName( int type ) 67 { 68 switch ( type ) 69 { 70 case DefaultInstrumentManager.INSTRUMENT_SAMPLE_TYPE_MAXIMUM: 71 return "maximum"; 72 73 case DefaultInstrumentManager.INSTRUMENT_SAMPLE_TYPE_MINIMUM: 74 return "minimum"; 75 76 case DefaultInstrumentManager.INSTRUMENT_SAMPLE_TYPE_MEAN: 77 return "mean"; 78 79 case DefaultInstrumentManager.INSTRUMENT_SAMPLE_TYPE_COUNTER: 80 return "counter"; 81 82 default: 83 return "unknown-" + type; 84 } 85 } 86 87 96 public static String generateInstrumentSampleName( int sampleType, 97 long sampleInterval, 98 int sampleSize ) 99 { 100 return getInstrumentSampleTypeName( sampleType ) + "_" + 101 sampleInterval + "_" + sampleSize; 102 } 103 104 114 public static String generateFullInstrumentSampleName( String instrumentName, 115 int sampleType, 116 long sampleInterval, 117 int sampleSize ) 118 { 119 return instrumentName + "." + 120 generateInstrumentSampleName( sampleType, sampleInterval, sampleSize ); 121 } 122 } 123 | Popular Tags |