[유치수] [NOBTS] change project type.

git-svn-id: http://svn.bds.nhncorp.com/pe/hippo-tomcat-profiler/trunk@431 84d0f5b1-2673-498c-a247-62c4ff18d310
This commit is contained in:
Chisu Yu
2012-06-27 02:21:11 +00:00
parent 3be294bc76
commit 34cb3fbd1e
62 changed files with 263 additions and 33 deletions
@@ -0,0 +1,75 @@
package com.profiler.modifier.db.dbcp;
import javassist.ClassPool;
import javassist.CtClass;
import javassist.CtMethod;
import com.profiler.config.TomcatProfilerConstant;
import com.profiler.modifier.AbstractModifier;
public class DBCPPoolModifier extends AbstractModifier{
public static byte[] modify(ClassPool classPool,ClassLoader classLoader,String javassistClassName,byte[] classFileBuffer) {
log("DBCPPoolModifier(PoolingDataSource$PoolGuardConnectionWrapper) modifing");
// printClassInfo(javassistClassName);
return changeMethod(classPool,classLoader,javassistClassName,classFileBuffer);
}
private static byte[] changeMethod(ClassPool classPool,ClassLoader classLoader,String javassistClassName,byte[] classfileBuffer) {
try {
CtClass cc = classPool.get(javassistClassName);
// updateGetConnectionMethod(classPool,cc);
updateCloseMethod(classPool,cc);
/*
CtMethod[] methods=cc.getDeclaredMethods();
for(CtMethod method:methods) {
// System.out.println(method.getLongName());
if(!method.isEmpty() ) {
String methodName=method.getName();
if(methodName.equals("getConnection")) {
// && !methodName.startsWith("version")) {
method.insertBefore("{System.out.println(\"-----DBCP "+method.getLongName()+" is started.\");}");
method.insertAfter("{System.out.println(\"-----DBCP "+method.getLongName()+" is finished.\");}");
System.out.println(method.getLongName());
}
} else {
log(method.getLongName()+" is empty !!!!!");
}
}
*/
byte[] newClassfileBuffer=null;
newClassfileBuffer= cc.toBytecode();
// cc.writeFile();
printClassConvertComplete(javassistClassName);
return newClassfileBuffer;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
private static void updateCloseMethod(ClassPool classPool,CtClass cc) throws Exception {
CtMethod serviceMethod=cc.getDeclaredMethod("close", null);
log("*** Changing close method ");
// serviceMethod.insertBefore(getCloseMethodBeforeInsertCode());
serviceMethod.insertAfter(getCloseMethodAfterInsertCode());
}
@SuppressWarnings("unused")
private static String getCloseMethodBeforeInsertCode() {
StringBuilder sb=new StringBuilder();
// sb.append("{");
// sb.append("System.out.println(\"-----PoolingDataSource$PoolGuardConnectionWrapper.close() method is called\");");
// sb.append("}");
return sb.toString();
}
private static String getCloseMethodAfterInsertCode() {
StringBuilder sb=new StringBuilder();
sb.append("{");
// sb.append("System.out.println(\"-----PoolingDataSource$PoolGuardConnectionWrapper.close() method is ended\");");
sb.append(TomcatProfilerConstant.CLASS_NAME_REQUEST_DATA_TRACER+".put("+TomcatProfilerConstant.REQ_DATA_TYPE_DB_CLOSE_CONNECTION+");");
sb.append("}");
return sb.toString();
}
}