org.sape.carbon.services.instrumentation.statistics
Class DefaultStatisticsInterceptor.MethodStats

java.lang.Object
  |
  +--org.sape.carbon.services.instrumentation.statistics.DefaultStatisticsInterceptor.MethodStats
All Implemented Interfaces:
Serializable
Enclosing class:
DefaultStatisticsInterceptor

public static class DefaultStatisticsInterceptor.MethodStats
extends Object
implements Serializable

This inner class is used to track information about an individual method on a specific component. It is thread-safe by using thread-local to track the status of individual method calls from a single thread.

The two main methods are the start and stop method methods that begin and end the timing and tracking of the component method call. Failures, for a specific thread, are only detected apon the next call to the same method (within the same thread). This is the only way to track failures as the component system does not notify post listeners when there is a component failure.

See Also:
Serialized Form

Field Summary
private  long callCount
          Holds the number of times the method has been called.
private  long failures
          Holds the number of times the method has failed.
private  Method method
          Holds the method being instremented.
private  ThreadLocal methodCall
          This thread local storage stores the start time of a method call in order to know when the call began.
private  long totalExecutionDuration
          Holds the total execution duration for the method.
 
Constructor Summary
DefaultStatisticsInterceptor.MethodStats(Method method)
          Creates a new thread-safe method statistics tracking object.
 
Method Summary
 void endMethodCall(long time)
          Ends the call tracking to the method, calculating the duration and reseting the thread-local storage for the next round of tracking.
 void fail()
          Ends a call for the case of where the invocation failed.
 long getCallCount()
          Gets the number of times the current method was called.
 long getFailures()
          Gets the count of failures (exceptions thrown from) the component method being tracked.
 Method getMethod()
          Returns the tracked method.
 long getTotalExecutionDuration()
          Gets the total time in milleseconds spent in the tracked component.
protected  void setCallCount(long callCount)
           
protected  void setFailures(long failures)
           
protected  void setTotalExecutionDuration(long totalExecutionDuration)
           
 void startMethodCall(long time)
          Begins the method call tracking by placing the start time in a thread-local storage location.
 String toString()
          Converts the object into a simple String representation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

method

private Method method
Holds the method being instremented.


callCount

private long callCount
Holds the number of times the method has been called.


failures

private long failures
Holds the number of times the method has failed.


totalExecutionDuration

private long totalExecutionDuration
Holds the total execution duration for the method.


methodCall

private final ThreadLocal methodCall
This thread local storage stores the start time of a method call in order to know when the call began. If the time is greater than zero it is considered to be executing (or to have failed). Reentrancy would cause a false positive of failure at this point.

Constructor Detail

DefaultStatisticsInterceptor.MethodStats

public DefaultStatisticsInterceptor.MethodStats(Method method)
Creates a new thread-safe method statistics tracking object.

Parameters:
method - The method object of the method being tracked
Method Detail

startMethodCall

public void startMethodCall(long time)
Begins the method call tracking by placing the start time in a thread-local storage location. Also increments the call count and detects previous failures of the method by noticing the failure to call a matching "endMethodCall".

Parameters:
time - the time in milleseconds that the method call began

fail

public void fail()
Ends a call for the case of where the invocation failed.


endMethodCall

public void endMethodCall(long time)
Ends the call tracking to the method, calculating the duration and reseting the thread-local storage for the next round of tracking.

Parameters:
time - the time in milleseconds that the method call ended

getMethod

public Method getMethod()
Returns the tracked method.

Returns:
the method object for the tracked method

getCallCount

public long getCallCount()
Gets the number of times the current method was called.

Returns:
the count of calls to the tracked method

getFailures

public long getFailures()
Gets the count of failures (exceptions thrown from) the component method being tracked.

Returns:
The count of failures for the tracked method.

getTotalExecutionDuration

public long getTotalExecutionDuration()
Gets the total time in milleseconds spent in the tracked component. Note: Does not track the duration of time spent in method calls that fail. Only succesful calls can be counted.

Returns:
the time in milleseconds spent executing the tracked method.

setCallCount

protected void setCallCount(long callCount)

setFailures

protected void setFailures(long failures)

setTotalExecutionDuration

protected void setTotalExecutionDuration(long totalExecutionDuration)

toString

public String toString()
Converts the object into a simple String representation.

Overrides:
toString in class Object
Returns:
a simple String representation


Copyright 1999-2003 Sapient Corporation. All Rights Reserved.