1 19 20 package org.apache.excalibur.instrument.manager.impl; 21 22 import java.io.PrintWriter ; 23 24 import org.apache.avalon.framework.configuration.Configuration; 25 import org.apache.avalon.framework.configuration.ConfigurationException; 26 27 import org.apache.excalibur.instrument.manager.DefaultInstrumentManager; 28 29 35 class MeanValueInstrumentSample 36 extends AbstractValueInstrumentSample 37 { 38 39 private long m_valueTotal; 40 41 44 55 MeanValueInstrumentSample( InstrumentProxy instrumentProxy, 56 String name, 57 long interval, 58 int size, 59 String description, 60 long lease ) 61 { 62 super( instrumentProxy, name, interval, size, description, lease ); 63 } 64 65 68 73 public int getType() 74 { 75 return DefaultInstrumentManager.INSTRUMENT_SAMPLE_TYPE_MEAN; 76 } 77 78 81 89 protected void advanceToNextSample( boolean reset ) 90 { 91 super.advanceToNextSample( reset ); 92 93 m_valueTotal = 0; 94 } 95 96 101 protected void writeStateAttributes( PrintWriter out ) 102 { 103 super.writeStateAttributes( out ); 104 105 out.print( " value-total=\"" ); 106 out.print( m_valueTotal ); 107 out.print( "\"" ); 108 } 109 110 121 protected void loadState( int value, Configuration state ) 122 throws ConfigurationException 123 { 124 super.loadState( value, state ); 125 126 m_valueTotal = state.getAttributeAsLong( "value-total" ); 127 } 128 129 132 139 protected void setValueInner( int value, long time ) 140 { 141 int sampleValue; 142 long sampleTime; 143 144 synchronized(this) 145 { 146 update( time, false ); 147 148 m_lastValue = value; 150 151 if ( m_valueCount > 0 ) 152 { 153 m_valueCount++; 155 m_valueTotal += value; 156 m_value = (int)(m_valueTotal / m_valueCount); 157 } 158 else 159 { 160 m_valueCount = 1; 162 m_valueTotal = m_value = value; 163 } 164 sampleValue = m_value; 165 sampleTime = m_time; 166 } 167 168 updateListeners( sampleValue, sampleTime ); 169 } 170 } 171 | Popular Tags |