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 import org.apache.excalibur.instrument.manager.ValueInstrumentListener; 29 30 38 abstract class AbstractValueInstrumentSample 39 extends AbstractInstrumentSample 40 implements ValueInstrumentListener 41 { 42 43 protected int m_value; 44 45 46 protected int m_valueCount; 47 48 49 protected int m_lastValue; 50 51 54 65 protected AbstractValueInstrumentSample( InstrumentProxy instrumentProxy, 66 String name, 67 long interval, 68 int size, 69 String description, 70 long lease ) 71 { 72 super( instrumentProxy, name, interval, size, description, lease ); 73 74 m_value = 0; 76 } 77 78 81 89 public final int getInstrumentType() 90 { 91 return DefaultInstrumentManager.INSTRUMENT_TYPE_VALUE; 92 } 93 94 103 public int getValueInner() 104 { 105 return m_value; 106 } 107 108 111 119 protected void advanceToNextSample( boolean reset ) 120 { 121 if ( reset ) 123 { 124 m_lastValue = 0; 125 } 126 m_value = m_lastValue; 127 m_valueCount = 0; 128 } 129 130 135 protected int getFillValue() 136 { 137 return m_lastValue; 138 } 139 140 145 protected void writeStateAttributes( PrintWriter out ) 146 { 147 super.writeStateAttributes( out ); 148 149 out.print( " value-count=\"" ); 150 out.print( m_valueCount ); 151 out.print( "\" last-value=\"" ); 152 out.print( m_lastValue ); 153 out.print( "\"" ); 154 } 155 156 167 protected void loadState( int value, Configuration state ) 168 throws ConfigurationException 169 { 170 m_value = value; 171 m_valueCount = state.getAttributeAsInteger( "value-count" ); 172 m_lastValue = state.getAttributeAsInteger( "last-value" ); 173 } 174 175 178 187 public void setValue( String instrumentName, int value, long time ) 188 { 189 setValueInner( value, time ); 192 } 193 194 195 198 204 protected abstract void setValueInner( int value, long time ); 205 } 206 | Popular Tags |