Browse Source
Merge in DESIGN/design from ~HARRISON/design:feature/x to feature/x * commit 'ece1c38e81d29325bafc50b4e7c3aaacad1164eb': 无 JIRA 任务,删掉代码 feat: KERNEL-10354 bytebuddy / 加解密性能优化 @Harrison 修复 FaultToleranceAdvice 的 Callable 问题feature/x
Harrison
3 years ago
4 changed files with 138 additions and 4 deletions
@ -0,0 +1,50 @@
|
||||
package com.fr.design.record.analyzer; |
||||
|
||||
import com.fr.record.analyzer.advice.AdviceCallable; |
||||
import com.fr.record.analyzer.advice.AdviceContext; |
||||
import com.fr.third.net.bytebuddy.asm.Advice; |
||||
import com.fr.third.net.bytebuddy.implementation.bytecode.assign.Assigner; |
||||
import com.fr.tolerance.FaultTolerance; |
||||
|
||||
import java.lang.reflect.Method; |
||||
import java.util.concurrent.Callable; |
||||
|
||||
/** |
||||
* created by Harrison on 2022/03/09 |
||||
**/ |
||||
public class TestCallableAdvice { |
||||
|
||||
@Advice.OnMethodEnter(skipOn = Advice.OnDefaultValue.class) |
||||
public static boolean onMethodEnter(@Advice.Local("context")AdviceContext adviceContext) { |
||||
|
||||
adviceContext = AdviceContext |
||||
.builder() |
||||
.onAdviceCall() |
||||
.build(); |
||||
// 如果是切面调用,则忽视当前方法
|
||||
return adviceContext.isOnAdviceCall(); |
||||
} |
||||
|
||||
@Advice.OnMethodExit(onThrowable = Exception.class) |
||||
public static void onMethodExit(@Advice.This(optional = true, typing = Assigner.Typing.DYNAMIC) Object self, |
||||
@Advice.Origin Method method, |
||||
@Advice.AllArguments(typing = Assigner.Typing.DYNAMIC) Object[] args, |
||||
@Advice.Return(readOnly = false, typing = Assigner.Typing.DYNAMIC) Object result, |
||||
@Advice.Local("context") AdviceContext adviceContext) throws Exception { |
||||
|
||||
// 如果是切面调用,则忽视不继续 exit
|
||||
if (adviceContext != null && adviceContext.isOnAdviceCall()) { |
||||
return; |
||||
} |
||||
|
||||
FaultTolerance faultTolerance = method.getAnnotation(FaultTolerance.class); |
||||
Callable<Object> callable = new AdviceCallable<Object>() { |
||||
@Override |
||||
public Object call() throws Exception { |
||||
return method.invoke(self, args); |
||||
} |
||||
}; |
||||
result = TestCallableHelper.test(callable); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,15 @@
|
||||
package com.fr.design.record.analyzer; |
||||
|
||||
import java.util.concurrent.Callable; |
||||
|
||||
/** |
||||
* created by Harrison on 2022/03/09 |
||||
**/ |
||||
public class TestCallableHelper { |
||||
|
||||
public static String test(Callable<Object> callable) throws Exception { |
||||
|
||||
callable.call(); |
||||
return "[test]Callable"; |
||||
} |
||||
} |
Loading…
Reference in new issue