mirror of
https://gitee.com/huoyo/ko-time.git
synced 2025-12-06 08:48:30 +08:00
add static-token and some optimization
This commit is contained in:
parent
77540cad32
commit
d751ccaf19
@ -127,7 +127,7 @@ public class KoTimeController {
|
||||
}else if (line.indexOf("staticTokenVisitValue") > -1) {
|
||||
line = line.replace("staticTokenVisitValue", staticTokenVisit+"");
|
||||
}else if (line.indexOf("staticTokenValue") > -1) {
|
||||
line = line.replace("staticTokenValue", "'"+Context.getConfig().getStaticToken()+"'");
|
||||
line = line.replace("staticTokenValue", "'"+kotoken+"'");
|
||||
}
|
||||
stringBuilder.append(line + "\n");
|
||||
}
|
||||
|
||||
@ -7,11 +7,10 @@ import cn.langpy.kotime.service.MethodNodeService;
|
||||
import cn.langpy.kotime.util.Common;
|
||||
import cn.langpy.kotime.util.Context;
|
||||
import cn.langpy.kotime.util.MethodStack;
|
||||
import cn.langpy.kotime.util.RecordException;
|
||||
import cn.langpy.kotime.util.ThrowException;
|
||||
import org.aopalliance.intercept.MethodInterceptor;
|
||||
import org.aopalliance.intercept.MethodInvocation;
|
||||
|
||||
import java.lang.reflect.Parameter;
|
||||
|
||||
/**
|
||||
* zhangchang
|
||||
@ -24,7 +23,6 @@ public class RunTimeHandler implements MethodInterceptor {
|
||||
return invocation.proceed();
|
||||
}
|
||||
boolean exceptionEnable = Context.getConfig().getExceptionEnable();
|
||||
Parameter[] parameters = invocation.getMethod().getParameters();
|
||||
long begin = System.nanoTime();
|
||||
Object obj = null;
|
||||
MethodNode parent = MethodNodeService.getParentMethodNode();
|
||||
@ -32,32 +30,28 @@ public class RunTimeHandler implements MethodInterceptor {
|
||||
InvokedInfo invokedInfo = new InvokedInfo();
|
||||
try {
|
||||
obj = invocation.proceed();
|
||||
long end = System.nanoTime();
|
||||
invokedInfo = Common.getInvokedInfo(invocation, parent, ((end - begin) / 1000000.0));
|
||||
} catch (Exception te) {
|
||||
if (!exceptionEnable) {
|
||||
long end = System.nanoTime();
|
||||
invokedInfo = Common.getInvokedInfo(invocation, parent, ((end - begin) / 1000000.0));
|
||||
throw te;
|
||||
}
|
||||
Exception e = null;
|
||||
if (te instanceof RecordException) {
|
||||
e = ((RecordException) te).getOriginalException();
|
||||
}else {
|
||||
if (te instanceof ThrowException) {
|
||||
e = ((ThrowException) te).getOriginalException();
|
||||
} else {
|
||||
e = te;
|
||||
}
|
||||
long end = System.nanoTime();
|
||||
invokedInfo = Common.getInvokedInfoWithException(invocation,parent,e,((end - begin) / 1000000.0));
|
||||
if (!(te instanceof RecordException)) {
|
||||
throw te;
|
||||
}
|
||||
}finally {
|
||||
long end = System.nanoTime();
|
||||
MethodNode current = MethodNodeService.getCurrentMethodNode(invocation, ((end - begin) / 1000000.0));
|
||||
invokedInfo.setCurrent(current);
|
||||
invokedInfo.setParent(parent);
|
||||
invokedInfo.setNames(parameters);
|
||||
invokedInfo.setValues(invocation.getArguments());
|
||||
invokedInfo = Common.getInvokedInfoWithException(invocation, parent, e, ((end - begin) / 1000000.0));
|
||||
throw te;
|
||||
} finally {
|
||||
InvokedQueue.add(invokedInfo);
|
||||
InvokedQueue.wake();
|
||||
MethodStack.clear();
|
||||
return obj;
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
|
||||
@ -198,6 +198,16 @@ public class Common {
|
||||
return value == null || "".equals(value) || ((value instanceof String) && ((String) value).trim().length() == 0);
|
||||
}
|
||||
|
||||
public static InvokedInfo getInvokedInfo(MethodInvocation invocation, MethodNode parent, double runTime) {
|
||||
MethodNode current = MethodNodeService.getCurrentMethodNode(invocation, runTime);
|
||||
InvokedInfo invokedInfo = new InvokedInfo();
|
||||
invokedInfo.setCurrent(current);
|
||||
invokedInfo.setParent(parent);
|
||||
invokedInfo.setNames(invocation.getMethod().getParameters());
|
||||
invokedInfo.setValues(invocation.getArguments());
|
||||
return invokedInfo;
|
||||
}
|
||||
|
||||
public static InvokedInfo getInvokedInfoWithException(MethodInvocation invocation, MethodNode parent, Exception e, double runTime) {
|
||||
ExceptionNode exception = new ExceptionNode();
|
||||
exception.setName(e.getClass().getSimpleName());
|
||||
|
||||
@ -75,8 +75,8 @@ public class KoUtil {
|
||||
* this method will throw an exception named RecordException,and RunTimeHandler will receive it so that it can be record by ko-time
|
||||
*/
|
||||
public static void throwException(Exception e) {
|
||||
RecordException recordException = new RecordException(e);
|
||||
throw recordException;
|
||||
ThrowException throwException = new ThrowException(e);
|
||||
throw throwException;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
package cn.langpy.kotime.util;
|
||||
|
||||
public class RecordException extends RuntimeException {
|
||||
public class ThrowException extends RuntimeException {
|
||||
|
||||
private Exception originalException;
|
||||
|
||||
public RecordException(Exception originalException) {
|
||||
public ThrowException(Exception originalException) {
|
||||
this.originalException = originalException;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user