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.excalibur.instrument.manager.interfaces.InstrumentManagerClient; 55 56 64 class CounterInstrumentSample 65 extends AbstractInstrumentSample 66 implements CounterInstrumentListener 67 { 68 69 protected int m_count; 70 71 74 85 CounterInstrumentSample( 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 m_count = 0; 96 } 97 98 101 106 public int getType() 107 { 108 return InstrumentManagerClient.INSTRUMENT_SAMPLE_TYPE_COUNTER; 109 } 110 111 119 public final int getInstrumentType() 120 { 121 return InstrumentManagerClient.INSTRUMENT_TYPE_COUNTER; 122 } 123 124 131 public int getValueInner() 132 { 133 return m_count; 134 } 135 136 139 145 protected void advanceToNextSample() 146 { 147 m_count = 0; 149 } 150 151 162 protected void loadState( int value, Configuration state ) 163 throws ConfigurationException 164 { 165 m_count = value; 166 } 167 168 172 protected void postSaveNeedsReset() 173 { 174 m_count = 0; 175 } 176 177 180 187 public void increment( String instrumentName, int count, long time ) 188 { 189 increment( count, time ); 191 } 192 193 196 202 private void increment( int count, long time ) 203 { 204 int sampleValue; 205 long sampleTime; 206 207 synchronized(this) 208 { 209 update( time ); 210 211 m_count += count; 212 213 sampleValue = m_count; 214 sampleTime = m_time; 215 } 216 217 updateListeners( sampleValue, sampleTime ); 218 } 219 } 220 | Popular Tags |