FileDocCategorySizeDatePackage
MethodMonitor.javaAPI DocGlassfish v2 API5414Thu Jul 26 18:50:48 BST 2007com.sun.ejb.base.stats

MethodMonitor

public class MethodMonitor extends Object
A Class for providing stats for an EJB method All concrete S1AS containers instantiate one instance of this class for each EJB method.
author
Mahesh Kannan

Fields Summary
private String
methodName
private boolean
monitorOn
private static ThreadLocal
execThreadLocal
private Object
lock
private int
successCount
private int
errorCount
private int
invocationCount
private long
totalExecutionTime
private com.sun.enterprise.admin.monitor.stats.MutableTimeStatisticImpl
methodStat
Constructors Summary
public MethodMonitor(Method method, boolean prefixWithClassName)


         
        this.methodName = constructMethodName(method);
        if (prefixWithClassName) {
            String prefix = method.getDeclaringClass().getName();
            prefix = prefix.replace('.", '_");
            this.methodName = prefix + "_" + this.methodName;
        }
        this.monitorOn = true;
    
Methods Summary
public voidappendStats(java.lang.StringBuffer sbuf)

	sbuf.append("\n\t[Method ")
	    .append("name=").append(methodName).append("; ")
	    .append("invCount=").append(invocationCount).append("; ")
	    .append("success=").append(successCount).append("; ")
	    .append("errors=").append(errorCount).append("; ")
	    .append("totalTime=").append(totalExecutionTime).append("]");
    
private java.lang.StringconstructMethodName(java.lang.reflect.Method method)

	StringBuffer sbuf = new StringBuffer();
	sbuf.append(method.getName());
	Class[] paramTypes = method.getParameterTypes();
	int sz = paramTypes.length;
	if (sz > 0) {
	    String dash = "-";
	    for (int i=0; i<sz; i++) {
		sbuf.append(dash)
		    .append(paramTypes[i].getName());
	    }
	}
	return sbuf.toString();
    
public longgetExecutionTime()

	return totalExecutionTime;
    
public java.lang.StringgetMethodName()

	return this.methodName;
    
public intgetTotalInvocations()

	return invocationCount;
    
public intgetTotalNumErrors()

	return errorCount;
    
public intgetTotalNumSuccess()

	return successCount;
    
public voidpostInvoke(java.lang.Throwable th)

	if (monitorOn) {
	    ArrayList list = (ArrayList) execThreadLocal.get();
	    if ( (list != null) && (list.size() > 0) ) {
		int index = list.size();
		Long startTime = (Long) list.remove(index-1);
		synchronized(lock) {
		    if (th == null) {
			successCount++;
		    } else {
			errorCount++;
		    }
		    if (startTime != null) {
			long diff = System.currentTimeMillis()
			    - startTime.longValue();
			totalExecutionTime = diff;

			methodStat.incrementCount(diff);
		    }
		}
	    }
	}
    
public voidpreInvoke()

	if (monitorOn) {
	    ArrayList list = (ArrayList) execThreadLocal.get();
	    if (list == null) {
		list = new ArrayList(5);
		execThreadLocal.set(list);
	    }
	    list.add(new Long(System.currentTimeMillis()));
	    synchronized (lock) {
		invocationCount++;
	    }
	}
    
public voidresetAllStats(boolean monitorOn)

	successCount = 0;
	errorCount = 0;
	invocationCount = 0;
	totalExecutionTime = 0;
	this.monitorOn = monitorOn;
    
voidsetMutableTimeStatisticImpl(com.sun.enterprise.admin.monitor.stats.MutableTimeStatisticImpl methodStat)

	this.methodStat = methodStat;