mirror of
https://gitee.com/huoyo/ko-time.git
synced 2025-12-07 09:18:31 +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) {
|
}else if (line.indexOf("staticTokenVisitValue") > -1) {
|
||||||
line = line.replace("staticTokenVisitValue", staticTokenVisit+"");
|
line = line.replace("staticTokenVisitValue", staticTokenVisit+"");
|
||||||
}else if (line.indexOf("staticTokenValue") > -1) {
|
}else if (line.indexOf("staticTokenValue") > -1) {
|
||||||
line = line.replace("staticTokenValue", "'"+Context.getConfig().getStaticToken()+"'");
|
line = line.replace("staticTokenValue", "'"+kotoken+"'");
|
||||||
}
|
}
|
||||||
stringBuilder.append(line + "\n");
|
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.Common;
|
||||||
import cn.langpy.kotime.util.Context;
|
import cn.langpy.kotime.util.Context;
|
||||||
import cn.langpy.kotime.util.MethodStack;
|
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.MethodInterceptor;
|
||||||
import org.aopalliance.intercept.MethodInvocation;
|
import org.aopalliance.intercept.MethodInvocation;
|
||||||
|
|
||||||
import java.lang.reflect.Parameter;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* zhangchang
|
* zhangchang
|
||||||
@ -24,7 +23,6 @@ public class RunTimeHandler implements MethodInterceptor {
|
|||||||
return invocation.proceed();
|
return invocation.proceed();
|
||||||
}
|
}
|
||||||
boolean exceptionEnable = Context.getConfig().getExceptionEnable();
|
boolean exceptionEnable = Context.getConfig().getExceptionEnable();
|
||||||
Parameter[] parameters = invocation.getMethod().getParameters();
|
|
||||||
long begin = System.nanoTime();
|
long begin = System.nanoTime();
|
||||||
Object obj = null;
|
Object obj = null;
|
||||||
MethodNode parent = MethodNodeService.getParentMethodNode();
|
MethodNode parent = MethodNodeService.getParentMethodNode();
|
||||||
@ -32,32 +30,28 @@ public class RunTimeHandler implements MethodInterceptor {
|
|||||||
InvokedInfo invokedInfo = new InvokedInfo();
|
InvokedInfo invokedInfo = new InvokedInfo();
|
||||||
try {
|
try {
|
||||||
obj = invocation.proceed();
|
obj = invocation.proceed();
|
||||||
|
long end = System.nanoTime();
|
||||||
|
invokedInfo = Common.getInvokedInfo(invocation, parent, ((end - begin) / 1000000.0));
|
||||||
} catch (Exception te) {
|
} catch (Exception te) {
|
||||||
if (!exceptionEnable) {
|
if (!exceptionEnable) {
|
||||||
|
long end = System.nanoTime();
|
||||||
|
invokedInfo = Common.getInvokedInfo(invocation, parent, ((end - begin) / 1000000.0));
|
||||||
throw te;
|
throw te;
|
||||||
}
|
}
|
||||||
Exception e = null;
|
Exception e = null;
|
||||||
if (te instanceof RecordException) {
|
if (te instanceof ThrowException) {
|
||||||
e = ((RecordException) te).getOriginalException();
|
e = ((ThrowException) te).getOriginalException();
|
||||||
}else {
|
} else {
|
||||||
e = te;
|
e = te;
|
||||||
}
|
}
|
||||||
long end = System.nanoTime();
|
long end = System.nanoTime();
|
||||||
invokedInfo = Common.getInvokedInfoWithException(invocation,parent,e,((end - begin) / 1000000.0));
|
invokedInfo = Common.getInvokedInfoWithException(invocation, parent, e, ((end - begin) / 1000000.0));
|
||||||
if (!(te instanceof RecordException)) {
|
throw te;
|
||||||
throw te;
|
} finally {
|
||||||
}
|
|
||||||
}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());
|
|
||||||
InvokedQueue.add(invokedInfo);
|
InvokedQueue.add(invokedInfo);
|
||||||
InvokedQueue.wake();
|
InvokedQueue.wake();
|
||||||
MethodStack.clear();
|
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);
|
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) {
|
public static InvokedInfo getInvokedInfoWithException(MethodInvocation invocation, MethodNode parent, Exception e, double runTime) {
|
||||||
ExceptionNode exception = new ExceptionNode();
|
ExceptionNode exception = new ExceptionNode();
|
||||||
exception.setName(e.getClass().getSimpleName());
|
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
|
* 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) {
|
public static void throwException(Exception e) {
|
||||||
RecordException recordException = new RecordException(e);
|
ThrowException throwException = new ThrowException(e);
|
||||||
throw recordException;
|
throw throwException;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -1,10 +1,10 @@
|
|||||||
package cn.langpy.kotime.util;
|
package cn.langpy.kotime.util;
|
||||||
|
|
||||||
public class RecordException extends RuntimeException {
|
public class ThrowException extends RuntimeException {
|
||||||
|
|
||||||
private Exception originalException;
|
private Exception originalException;
|
||||||
|
|
||||||
public RecordException(Exception originalException) {
|
public ThrowException(Exception originalException) {
|
||||||
this.originalException = originalException;
|
this.originalException = originalException;
|
||||||
}
|
}
|
||||||
|
|
||||||
Loading…
x
Reference in New Issue
Block a user