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 MaximumValueInstrumentSample 66 extends AbstractValueInstrumentSample 67 { 68 69 private int m_lastValue; 70 71 74 85 MaximumValueInstrumentSample( 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_MAXIMUM; 106 } 107 108 111 117 protected void advanceToNextSample() 118 { 119 m_value = m_lastValue; 121 m_valueCount = 0; 122 } 123 124 129 protected void saveState( DefaultConfiguration state ) 130 { 131 super.saveState( state ); 132 133 state.setAttribute( "last-value", Integer.toString( m_lastValue ) ); 134 } 135 136 147 protected void loadState( int value, Configuration state ) 148 throws ConfigurationException 149 { 150 super.loadState( value, state ); 151 152 m_lastValue = state.getAttributeAsInteger( "last-value" ); 153 } 154 155 159 protected void postSaveNeedsReset() 160 { 161 super.postSaveNeedsReset(); 162 163 m_lastValue = 0; 164 } 165 166 169 176 protected void setValueInner( int value, long time ) 177 { 178 boolean update; 179 int sampleValue; 180 long sampleTime; 181 182 synchronized(this) 183 { 184 update = update( time ); 185 186 m_lastValue = value; 188 189 if ( m_valueCount > 0 ) 190 { 191 m_valueCount++; 193 if ( value > m_value ) 194 { 195 m_value = value; 196 update = true; 197 } 198 } 199 else 200 { 201 m_valueCount = 1; 203 m_value = value; 204 update = true; 205 } 206 207 sampleValue = m_value; 208 sampleTime = m_time; 209 } 210 211 if ( update ) 212 { 213 updateListeners( sampleValue, sampleTime ); 214 } 215 } 216 } 217 | Popular Tags |