/** * Increments the Instrument. This method is optimized to be extremely * light weight when an InstrumentManager is not present and there are no * registered CounterInstrumentListeners. */ public void increment() { InstrumentProxy proxy = getInstrumentProxy(); if( proxy != null ) { proxy.increment( 1 ); } }
/** * Called to increment the number of Instrumentables registered. */ void incrementInstrumentableCount() { int count; synchronized( m_semaphore ) { count = ++m_instrumentableCount; } m_instrumentablesInstrument.setValue( count ); }
public final void setInstrumentableName( final String name ) { if ( m_delegateFactory instanceof Instrumentable ) { ( (Instrumentable) m_delegateFactory ).setInstrumentableName( name ); } }
/** * Creates a new DefaultInstrumentManagerImpl. */ public DefaultInstrumentManagerImpl() { // Initialize the Instrumentable elements. m_totalMemoryInstrument = new ValueInstrument( "total-memory" ); m_freeMemoryInstrument = new ValueInstrument( "free-memory" ); m_memoryInstrument = new ValueInstrument( "memory" ); m_activeThreadCountInstrument = new ValueInstrument( "active-thread-count" ); m_registrationsInstrument = new CounterInstrument( "instrumentable-registrations" ); m_instrumentablesInstrument = new ValueInstrument( "instrumentables" ); m_instrumentsInstrument = new ValueInstrument( "instruments" ); m_samplesInstrument = new ValueInstrument( "samples" ); m_leasedSamplesInstrument = new ValueInstrument( "leased-samples" ); m_leaseRequestsInstrument = new CounterInstrument( "lease-requests" ); m_stateSavesInstrument = new CounterInstrument( "state-saves" ); m_stateSaveTimeInstrument = new ValueInstrument( "state-save-time" ); }
/** * Assign the instrumentables and InstrumentManageables */ public void create( final Object object, final Context context ) throws Exception { if ( m_instrumentEnabled && object instanceof Instrumentable ) { final String instrumentableName = (String) context.get( "component.name" ); final Instrumentable instrumentable = (Instrumentable) object; instrumentable.setInstrumentableName( instrumentableName ); // Get the name from the instrumentable in case it was changed since being set above. m_instrumentManager.registerInstrumentable( instrumentable, instrumentable.getInstrumentableName() ); } if ( m_instrumentEnabled && object instanceof InstrumentManageable ) { ( (InstrumentManageable) object ).setInstrumentManager( m_instrumentManager ); } } }
/** * Create a new poolable instance by by calling the newInstance method * on the pool's ObjectFactory. * <p> * This is the method to override when you need to enforce creational * policies. * <p> * This method is only called by threads that have m_semaphore locked. */ protected Poolable newPoolable() throws Exception { Object obj = m_factory.newInstance(); // Notify the InstrumentManager m_createsInstrument.increment(); // The size is incremented after this call in case an error is thrown. m_sizeInstrument.setValue( getSize() + 1 ); return (Poolable)obj; }
/** * Increment the lease requests. */ void incrementLeaseRequests() { m_leaseRequestsInstrument.increment(); }
public final String getInstrumentableName() { if ( m_delegateFactory instanceof Instrumentable ) { return ( (Instrumentable) m_delegateFactory ).getInstrumentableName(); } return ""; }
public final Instrument[] getInstruments() { if ( m_delegateFactory instanceof Instrumentable ) { return ( (Instrumentable) m_delegateFactory ).getInstruments(); } return new Instrument[]{}; }
public final Instrumentable[] getChildInstrumentables() { if ( m_delegateFactory instanceof Instrumentable ) { return ( (Instrumentable) m_delegateFactory ).getChildInstrumentables(); } return new Instrumentable[]{}; }
/** * Instrumentable to be registered with the instrument manager. Should be * called whenever an Instrumentable is created. The '.' character is * used to denote a child Instrumentable and can be used to register the * instrumentable at a specific point in an instrumentable hierarchy. * * @param instrumentable Instrumentable to register with the InstrumentManager. * @param instrumentableName The name to use when registering the Instrumentable. * * @throws Exception If there were any problems registering the Instrumentable. */ public void registerInstrumentable( Instrumentable instrumentable, String instrumentableName ) throws Exception { m_instrumentManager.registerInstrumentable( instrumentable, instrumentableName ); } }
/** * Sets the current value of the Instrument. This method is optimized * to be extremely light weight when an InstrumentManager is not present * and there are no registered ValueInstrumentListeners. * <p> * Note that in many cases is best to call this method even if the * isActive() method returns false. This is because the InstrumentManager * will remember the last value set and use it if the instrument ever * becomes active. For things like pool sizes which do not change often, * this behavior is critical so that users can begin monitoring the value * and see what it was before they connected. Setting the value is * very light weight, but its calculation may not be. It is up to the * user to weigh the benefits and consequences one way or the other. * * @param value The new value for the Instrument. */ public void setValue( int value ) { InstrumentProxy proxy = getInstrumentProxy(); if( proxy != null ) { proxy.setValue( value ); } } }
/** * Used by classes being profiled so that they can avoid unnecessary * code when the data from an Instrument is not being used. * * @return True if an InstrumentProxy has been set and is active. */ public boolean isActive() { return ( m_proxy != null ) && ( m_proxy.isActive() ); }
/** * Creates a new ComponentHandler. */ public ComponentHandler() { // Initialize the Instrumentable elements. setInstrumentableName( ExcaliburComponentManager.INSTRUMENTABLE_NAME + ".unnamed handler" ); addInstrument( m_referencesInstrument = new ValueInstrument( "references" ) ); addInstrument( m_getsInstrument = new CounterInstrument( "gets" ) ); addInstrument( m_putsInstrument = new CounterInstrument( "puts" ) ); }
/** * Called to increment the number of Instruments registered. */ void incrementInstrumentCount() { int count; synchronized( m_semaphore ) { count = ++m_instrumentCount; } m_instrumentsInstrument.setValue( count ); }
/** * Increments the Instrument by a specified count. This method is * optimized to be extremely light weight when an InstrumentManager is not * present and there are no registered CounterInstrumentListeners. * * @param count A positive integer to increment the counter by. * * @throws IllegalArgumentException If the count is not positive. */ public void increment( int count ) { // Check the count if( count <= 0 ) { throw new IllegalArgumentException( "Count must be a positive value." ); } InstrumentProxy proxy = getInstrumentProxy(); if( proxy != null ) { proxy.increment( count ); } } }
/** * Create a new AbstractComponentManagerServlet. * * @param referenceName A name which does not include any spaces or periods * that will be used to name the logger category and * instrumentable which represents this servlet. */ public AbstractComponentManagerServlet( String referenceName ) { //System.out.println( "AbstractComponentManagerServlet( " + referenceName + " )" ); m_referenceName = referenceName; // Set up Instrumentable like AbstractInstrumentable m_registered = false; m_instrumentList = new ArrayList(); m_childList = new ArrayList(); // Create the instruments setInstrumentableName( referenceName ); addInstrument( m_instrumentRequests = new CounterInstrument( "requests" ) ); addInstrument( m_instrumentTime = new ValueInstrument( "time" ) ); }
/** * Called to increment the number of Permanent Instrument Samples registered. */ void incrementPermanentSampleCount() { int count; synchronized( m_semaphore ) { count = ++m_permanentSampleCount + m_leasedSampleCount; } m_samplesInstrument.setValue( count ); }
/** * Called to increment the number of Leased Instrument Samples registered. */ void incrementLeasedSampleCount() { int count; int leasedCount; synchronized( m_semaphore ) { leasedCount = ++m_leasedSampleCount; count = m_permanentSampleCount + m_leasedSampleCount; } m_samplesInstrument.setValue( count ); m_leasedSamplesInstrument.setValue( leasedCount ); }
/** * Called to decrement the number of Leased Instrument Samples registered. */ void decrementLeasedSampleCount() { int count; int leasedCount; synchronized( m_semaphore ) { leasedCount = --m_leasedSampleCount; count = m_permanentSampleCount + m_leasedSampleCount; } m_samplesInstrument.setValue( count ); m_leasedSamplesInstrument.setValue( leasedCount ); }