1 50 package org.apache.excalibur.instrument.manager.interfaces; 51 52 import org.apache.avalon.framework.configuration.ConfigurationException; 53 54 62 public class InstrumentSampleUtils 63 { 64 73 public static int resolveInstrumentSampleType( String type ) 74 throws ConfigurationException { 75 76 if ( type.equalsIgnoreCase( "max" ) || type.equalsIgnoreCase( "maximum" ) ) 77 { 78 return InstrumentManagerClient.INSTRUMENT_SAMPLE_TYPE_MAXIMUM; 79 } 80 else if ( type.equalsIgnoreCase( "min" ) || type.equalsIgnoreCase( "minimum" ) ) 81 { 82 return InstrumentManagerClient.INSTRUMENT_SAMPLE_TYPE_MINIMUM; 83 } 84 else if ( type.equalsIgnoreCase( "mean" ) ) 85 { 86 return InstrumentManagerClient.INSTRUMENT_SAMPLE_TYPE_MEAN; 87 } 88 else if ( type.equalsIgnoreCase( "ctr" ) || type.equalsIgnoreCase( "counter" ) ) 89 { 90 return InstrumentManagerClient.INSTRUMENT_SAMPLE_TYPE_COUNTER; 91 } 92 else 93 { 94 throw new ConfigurationException( "'" + type + "' is not a valid sample type." ); 95 } 96 } 97 98 public static String getInstrumentSampleTypeName( int type ) 99 { 100 switch ( type ) 101 { 102 case InstrumentManagerClient.INSTRUMENT_SAMPLE_TYPE_MAXIMUM: 103 return "maximum"; 104 105 case InstrumentManagerClient.INSTRUMENT_SAMPLE_TYPE_MINIMUM: 106 return "minimum"; 107 108 case InstrumentManagerClient.INSTRUMENT_SAMPLE_TYPE_MEAN: 109 return "mean"; 110 111 case InstrumentManagerClient.INSTRUMENT_SAMPLE_TYPE_COUNTER: 112 return "counter"; 113 114 default: 115 return "unknown-" + type; 116 } 117 } 118 119 128 public static String generateInstrumentSampleName( int sampleType, 129 long sampleInterval, 130 int sampleSize ) 131 { 132 return getInstrumentSampleTypeName( sampleType ) + "_" + 133 sampleInterval + "_" + sampleSize; 134 } 135 136 146 public static String generateFullInstrumentSampleName( String instrumentName, 147 int sampleType, 148 long sampleInterval, 149 int sampleSize ) 150 { 151 return instrumentName + "." + 152 generateInstrumentSampleName( sampleType, sampleInterval, sampleSize ); 153 } 154 } 155 | Popular Tags |