2010/12/15 - Apache Excalibur has been retired.

For more information, please explore the Attic.

Extending the AbstractInstrumentable Base-Class

Under Construction.

                public class MyNiftyComponent
    extends AbstractInstrumentable
{
    private CounterInstrument m_instrumentPushes;
    private CounterInstrument m_instrumentPops;
    private ValueInstrument m_instrumentStackSize;
    private ValueInstrument m_instrumentProcessTime;
          
    public MyNiftyComponent()
    {
        addInstrument( m_instrumentPushes = new CounterInstrument( "pushes" ) );
        addInstrument( m_instrumentPops = new CounterInstrument( "pops" ) );
        addInstrument( m_instrumentStackSize = new ValueInstrument( "stack-size" ) );
        addInstrument( m_instrumentProcessTime = new ValueInstrument( "process-time" ) );
    }
    
    public void push( Object obj )
    {
        m_stack.push( obj );
        
        m_instrumentPushes.increment();
        m_instrumentStackSize.setValue( m_stack.size() );
    }
    
    public Object pop()
    {
        Object obj = m_stack.pop();
        
        m_instrumentPops.increment();
        m_instrumentStackSize.setValue( m_stack.size() );
        
        return obj;
    }
    
    public void process()
    {
        long start = System.currentTimeMillis();
        
        // Do something that takes a while.
        
        m_instrumentProcessTime.setValue( (int)( System.currentTimeMillis() - start ) );
    }
}