1 50 package org.apache.excalibur.instrument.manager; 51 52 import org.apache.avalon.framework.configuration.Configuration; 53 import org.apache.avalon.framework.configuration.ConfigurationException; 54 import org.apache.avalon.framework.configuration.DefaultConfiguration; 55 import org.apache.excalibur.instrument.manager.interfaces.InstrumentManagerClient; 56 57 65 class MeanValueInstrumentSample 66 extends AbstractValueInstrumentSample 67 { 68 69 private long m_valueTotal; 70 71 74 85 MeanValueInstrumentSample( InstrumentProxy instrumentProxy, 86 String name, 87 long interval, 88 int size, 89 String description, 90 long lease ) 91 { 92 super( instrumentProxy, name, interval, size, description, lease ); 93 } 94 95 98 103 public int getType() 104 { 105 return InstrumentManagerClient.INSTRUMENT_SAMPLE_TYPE_MEAN; 106 } 107 108 111 117 protected void advanceToNextSample() 118 { 119 m_valueCount = 0; 123 } 124 125 130 protected void saveState( DefaultConfiguration state ) 131 { 132 super.saveState( state ); 133 134 state.setAttribute( "value-total", Long.toString( m_valueTotal ) ); 135 } 136 137 148 protected void loadState( int value, Configuration state ) 149 throws ConfigurationException 150 { 151 super.loadState( value, state ); 152 153 m_valueTotal = state.getAttributeAsLong( "value-total" ); 154 } 155 156 160 protected void postSaveNeedsReset() 161 { 162 super.postSaveNeedsReset(); 163 164 m_valueTotal = 0; 165 } 166 167 170 177 protected void setValueInner( int value, long time ) 178 { 179 int sampleValue; 180 long sampleTime; 181 182 synchronized(this) 183 { 184 update( time ); 185 186 if ( m_valueCount > 0 ) 187 { 188 m_valueCount++; 190 m_valueTotal += value; 191 m_value = (int)(m_valueTotal / m_valueCount); 192 } 193 else 194 { 195 m_valueCount = 1; 197 m_valueTotal = m_value = value; 198 } 199 sampleValue = m_value; 200 sampleTime = m_time; 201 } 202 203 updateListeners( sampleValue, sampleTime ); 204 } 205 } 206 | Popular Tags |