mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
refactor spring stat
This commit is contained in:
@@ -29,7 +29,7 @@ public class DruidStatInterceptor implements MethodInterceptor, InitializingBean
|
||||
public Object invoke(MethodInvocation invocation) throws Throwable {
|
||||
SpringMethodStat lastMethodStat = SpringMethodStat.current();
|
||||
|
||||
MethodInfo methodInfo = getMethodInfo(invocation);
|
||||
SpringMethodInfo methodInfo = getMethodInfo(invocation);
|
||||
|
||||
SpringMethodStat methodStat = springStat.getMethodStat(methodInfo, true);
|
||||
|
||||
@@ -60,16 +60,16 @@ public class DruidStatInterceptor implements MethodInterceptor, InitializingBean
|
||||
}
|
||||
}
|
||||
|
||||
public MethodInfo getMethodInfo(MethodInvocation invocation) {
|
||||
public SpringMethodInfo getMethodInfo(MethodInvocation invocation) {
|
||||
Object thisObject = invocation.getThis();
|
||||
Method method = invocation.getMethod();
|
||||
|
||||
if (thisObject == null) {
|
||||
return new MethodInfo(method.getDeclaringClass(), method);
|
||||
return new SpringMethodInfo(method.getDeclaringClass(), method);
|
||||
}
|
||||
|
||||
if (method.getDeclaringClass() == thisObject.getClass()) {
|
||||
return new MethodInfo(method.getDeclaringClass(), method);
|
||||
return new SpringMethodInfo(method.getDeclaringClass(), method);
|
||||
}
|
||||
|
||||
{
|
||||
@@ -89,7 +89,7 @@ public class DruidStatInterceptor implements MethodInterceptor, InitializingBean
|
||||
if (isCglibProxy || isJavassistProxy) {
|
||||
Class<?> superClazz = clazz.getSuperclass();
|
||||
|
||||
return new MethodInfo(superClazz, method);
|
||||
return new SpringMethodInfo(superClazz, method);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,9 +120,9 @@ public class DruidStatInterceptor implements MethodInterceptor, InitializingBean
|
||||
}
|
||||
|
||||
if (clazz == null) {
|
||||
return new MethodInfo(method.getDeclaringClass(), method);
|
||||
return new SpringMethodInfo(method.getDeclaringClass(), method);
|
||||
}
|
||||
|
||||
return new MethodInfo(clazz, method);
|
||||
return new SpringMethodInfo(clazz, method);
|
||||
}
|
||||
}
|
||||
|
||||
+28
-30
@@ -2,40 +2,32 @@ package com.alibaba.druid.support.spring.stat;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public class MethodInfo {
|
||||
public class SpringMethodInfo {
|
||||
|
||||
private String className;
|
||||
private String methodName;
|
||||
private final String signature;
|
||||
private String signature;
|
||||
|
||||
public MethodInfo(Class<?> instanceClass, Method method){
|
||||
this.className = instanceClass.getName();
|
||||
this.methodName = method.getName();
|
||||
signature = getMethodSignature(method);
|
||||
private Class<?> instanceClass;
|
||||
private Method method;
|
||||
|
||||
public SpringMethodInfo(Class<?> instanceClass, Method method){
|
||||
this.instanceClass = instanceClass;
|
||||
this.method = method;
|
||||
}
|
||||
|
||||
public String getClassName() {
|
||||
return className;
|
||||
}
|
||||
|
||||
public void setClassName(String className) {
|
||||
this.className = className;
|
||||
return instanceClass.getName();
|
||||
}
|
||||
|
||||
public String getMethodName() {
|
||||
return methodName;
|
||||
}
|
||||
|
||||
public void setMethodName(String methodName) {
|
||||
this.methodName = methodName;
|
||||
return method.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((className == null) ? 0 : className.hashCode());
|
||||
result = prime * result + ((signature == null) ? 0 : signature.hashCode());
|
||||
result = prime * result + instanceClass.getName().hashCode();
|
||||
result = prime * result + method.getName().hashCode();
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -53,21 +45,24 @@ public class MethodInfo {
|
||||
return false;
|
||||
}
|
||||
|
||||
MethodInfo other = (MethodInfo) obj;
|
||||
if (className == null) {
|
||||
if (other.className != null) {
|
||||
return false;
|
||||
}
|
||||
} else if (!className.equals(other.className)) {
|
||||
SpringMethodInfo other = (SpringMethodInfo) obj;
|
||||
|
||||
if (!instanceClass.getName().equals(other.instanceClass.getName())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (signature == null) {
|
||||
if (other.signature != null) {
|
||||
if (!method.getName().equals(other.method.getName())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (method.getParameterTypes().length != other.method.getParameterTypes().length) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int i = 0; i < method.getParameterTypes().length; ++i) {
|
||||
if (method.getParameterTypes()[i].getName().equals(other.method.getParameterTypes()[i].getName())) {
|
||||
return false;
|
||||
}
|
||||
} else if (!signature.equals(other.signature)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -88,6 +83,9 @@ public class MethodInfo {
|
||||
}
|
||||
|
||||
public String getSignature() {
|
||||
if (signature == null) {
|
||||
signature = getMethodSignature(method);
|
||||
}
|
||||
return signature;
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,7 @@ public class SpringMethodStat {
|
||||
|
||||
private final static ThreadLocal<SpringMethodStat> currentLocal = new ThreadLocal<SpringMethodStat>();
|
||||
|
||||
private final MethodInfo methodInfo;
|
||||
private final SpringMethodInfo methodInfo;
|
||||
|
||||
private final AtomicInteger runningCount = new AtomicInteger();
|
||||
private final AtomicInteger concurrentMax = new AtomicInteger();
|
||||
@@ -25,7 +25,7 @@ public class SpringMethodStat {
|
||||
private final AtomicLong jdbcCommitCount = new AtomicLong();
|
||||
private final AtomicLong jdbcRollbackCount = new AtomicLong();
|
||||
|
||||
public SpringMethodStat(MethodInfo methodInfo){
|
||||
public SpringMethodStat(SpringMethodInfo methodInfo){
|
||||
this.methodInfo = methodInfo;
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ public class SpringMethodStat {
|
||||
jdbcRollbackCount.set(0);
|
||||
}
|
||||
|
||||
public MethodInfo getMethodInfo() {
|
||||
public SpringMethodInfo getMethodInfo() {
|
||||
return methodInfo;
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
public class SpringStat {
|
||||
|
||||
private ConcurrentMap<MethodInfo, SpringMethodStat> methodStats = new ConcurrentHashMap<MethodInfo, SpringMethodStat>();
|
||||
private ConcurrentMap<SpringMethodInfo, SpringMethodStat> methodStats = new ConcurrentHashMap<SpringMethodInfo, SpringMethodStat>();
|
||||
|
||||
public SpringStat(){
|
||||
|
||||
@@ -20,7 +20,7 @@ public class SpringStat {
|
||||
}
|
||||
}
|
||||
|
||||
public SpringMethodStat getMethodStat(MethodInfo methodInfo, boolean create) {
|
||||
public SpringMethodStat getMethodStat(SpringMethodInfo methodInfo, boolean create) {
|
||||
SpringMethodStat methodStat = methodStats.get(methodInfo);
|
||||
if (methodStat != null) {
|
||||
return methodStat;
|
||||
|
||||
Reference in New Issue
Block a user