MessageAsmMethodBoost优化

This commit is contained in:
redkale
2024-08-12 23:49:25 +08:00
parent cebd463d58
commit aee5745172
11 changed files with 140 additions and 78 deletions

View File

@@ -171,7 +171,7 @@
<executions> <executions>
<execution> <execution>
<goals> <goals>
<goal>apply</goal> <goal>check</goal>
</goals> </goals>
<phase>compile</phase> <phase>compile</phase>
</execution> </execution>

View File

@@ -96,10 +96,10 @@ public abstract class AsmMethodBoost<T> {
* @param fieldPrefix 动态字段的前缀 * @param fieldPrefix 动态字段的前缀
* @param filterAnns 需要过滤的注解 * @param filterAnns 需要过滤的注解
* @param method 操作的方法 * @param method 操作的方法
* @param newMethodName 新的方法名, 可能为null * @param newMethod 新的方法名, 可能为null
* @return 下一个新的方法名不做任何处理应返回参数newMethodName * @return 下一个新的方法名不做任何处理应返回参数newMethodName
*/ */
public abstract String doMethod( public abstract AsmNewMethod doMethod(
ClassLoader classLoader, ClassLoader classLoader,
ClassWriter cw, ClassWriter cw,
Class serviceImplClass, Class serviceImplClass,
@@ -107,7 +107,7 @@ public abstract class AsmMethodBoost<T> {
String fieldPrefix, String fieldPrefix,
List<Class<? extends Annotation>> filterAnns, List<Class<? extends Annotation>> filterAnns,
Method method, Method method,
@Nullable String newMethodName); @Nullable AsmNewMethod newMethod);
/** /**
* 处理所有动态方法后调用 * 处理所有动态方法后调用
@@ -134,24 +134,24 @@ public abstract class AsmMethodBoost<T> {
} }
protected MethodVisitor createMethodVisitor( protected MethodVisitor createMethodVisitor(
ClassWriter cw, Method method, String newMethodName, AsmMethodBean methodBean) { ClassWriter cw, Method method, AsmNewMethod newMethod, int newMethodAcc, AsmMethodBean methodBean) {
return new MethodDebugVisitor(cw.visitMethod( return new MethodDebugVisitor(cw.visitMethod(
getAcc(method, newMethodName), getAcc(method, newMethod),
getNowMethodName(method, newMethodName), getNowMethodName(method, newMethod),
Type.getMethodDescriptor(method), Type.getMethodDescriptor(method),
getMethodSignature(method, methodBean), getMethodSignature(method, methodBean),
getMethodExceptions(method, methodBean))); getMethodExceptions(method, methodBean)));
} }
protected int getAcc(Method method, String newMethodName) { protected int getAcc(Method method, AsmNewMethod newMethod) {
if (newMethodName != null) { if (newMethod != null) {
return ACC_PRIVATE; return ACC_PRIVATE;
} }
return Modifier.isProtected(method.getModifiers()) ? ACC_PROTECTED : ACC_PUBLIC; return Modifier.isProtected(method.getModifiers()) ? ACC_PROTECTED : ACC_PUBLIC;
} }
protected String getNowMethodName(Method method, String newMethodName) { protected String getNowMethodName(Method method, AsmNewMethod newMethod) {
return newMethodName == null ? method.getName() : newMethodName; return newMethod == null ? method.getName() : newMethod.getMethodName();
} }
protected String getMethodSignature(Method method, AsmMethodBean methodBean) { protected String getMethodSignature(Method method, AsmMethodBean methodBean) {
@@ -175,13 +175,13 @@ public abstract class AsmMethodBoost<T> {
} }
protected void visitRawAnnotation( protected void visitRawAnnotation(
Method method, String newMethodName, MethodVisitor mv, Class selfAnnType, List filterAnns) { Method method, AsmNewMethod newMethod, MethodVisitor mv, Class skipAnnType, List skipAnns) {
if (newMethodName == null) { if (newMethod == null) {
// 给方法加上原有的Annotation // 给方法加上原有的Annotation
final Annotation[] anns = method.getAnnotations(); final Annotation[] anns = method.getAnnotations();
for (Annotation ann : anns) { for (Annotation ann : anns) {
if (ann.annotationType() != selfAnnType if (ann.annotationType() != skipAnnType
&& (filterAnns == null || !filterAnns.contains(ann.annotationType()))) { && (skipAnns == null || !skipAnns.contains(ann.annotationType()))) {
Asms.visitAnnotation( Asms.visitAnnotation(
mv.visitAnnotation(Type.getDescriptor(ann.annotationType()), true), mv.visitAnnotation(Type.getDescriptor(ann.annotationType()), true),
ann.annotationType(), ann.annotationType(),
@@ -305,7 +305,7 @@ public abstract class AsmMethodBoost<T> {
} }
@Override @Override
public String doMethod( public AsmNewMethod doMethod(
ClassLoader classLoader, ClassLoader classLoader,
ClassWriter cw, ClassWriter cw,
Class serviceImplClass, Class serviceImplClass,
@@ -313,22 +313,15 @@ public abstract class AsmMethodBoost<T> {
String fieldPrefix, String fieldPrefix,
List<Class<? extends Annotation>> filterAnns, List<Class<? extends Annotation>> filterAnns,
Method method, Method method,
String newMethodName) { AsmNewMethod newMethod) {
String newName = newMethodName; AsmNewMethod newResult = newMethod;
for (AsmMethodBoost item : items) { for (AsmMethodBoost item : items) {
if (item != null) { if (item != null) {
newName = item.doMethod( newResult = item.doMethod(
classLoader, classLoader, cw, serviceImplClass, newDynName, fieldPrefix, filterAnns, method, newResult);
cw,
serviceImplClass,
newDynName,
fieldPrefix,
filterAnns,
method,
newName);
} }
} }
return newName; return newResult;
} }
@Override @Override

View File

@@ -0,0 +1,47 @@
/*
*/
package org.redkale.asm;
import org.redkale.convert.json.JsonConvert;
/**
* 存放新方法的信息
*
* @since 2.8.0
*/
public class AsmNewMethod {
private String methodName;
private int methodAccs;
public AsmNewMethod() {}
public AsmNewMethod(String newName, int newAccs) {
this.methodName = newName;
this.methodAccs = newAccs;
}
public String getMethodName() {
return methodName;
}
public void setMethodName(String methodName) {
this.methodName = methodName;
}
public int getMethodAccs() {
return methodAccs;
}
public void setMethodAccs(int methodAccs) {
this.methodAccs = methodAccs;
}
@Override
public String toString() {
return JsonConvert.root().convertTo(this);
}
}

View File

@@ -1139,6 +1139,7 @@ public final class Application {
if (list == null) { if (list == null) {
return null; return null;
} }
Utility.sortPriority(list);
return list.size() == 1 ? list.get(0) : AsmMethodBoost.create(remote, list); return list.size() == 1 ? list.get(0) : AsmMethodBoost.create(remote, list);
} }

View File

@@ -16,6 +16,7 @@ import java.util.logging.Logger;
import org.redkale.asm.AnnotationVisitor; import org.redkale.asm.AnnotationVisitor;
import org.redkale.asm.AsmMethodBean; import org.redkale.asm.AsmMethodBean;
import org.redkale.asm.AsmMethodBoost; import org.redkale.asm.AsmMethodBoost;
import org.redkale.asm.AsmNewMethod;
import org.redkale.asm.Asms; import org.redkale.asm.Asms;
import org.redkale.asm.ClassWriter; import org.redkale.asm.ClassWriter;
import org.redkale.asm.FieldVisitor; import org.redkale.asm.FieldVisitor;
@@ -60,7 +61,7 @@ public class CachedAsmMethodBoost extends AsmMethodBoost {
} }
@Override @Override
public String doMethod( public AsmNewMethod doMethod(
final ClassLoader classLoader, final ClassLoader classLoader,
final ClassWriter cw, final ClassWriter cw,
final Class serviceImplClass, final Class serviceImplClass,
@@ -68,7 +69,7 @@ public class CachedAsmMethodBoost extends AsmMethodBoost {
final String fieldPrefix, final String fieldPrefix,
final List filterAnns, final List filterAnns,
final Method method, final Method method,
final String newMethodName) { final AsmNewMethod newMethod) {
Map<String, CachedAction> actions = this.actionMap; Map<String, CachedAction> actions = this.actionMap;
if (actions == null) { if (actions == null) {
actions = new LinkedHashMap<>(); actions = new LinkedHashMap<>();
@@ -76,13 +77,13 @@ public class CachedAsmMethodBoost extends AsmMethodBoost {
} }
Cached cached = method.getAnnotation(Cached.class); Cached cached = method.getAnnotation(Cached.class);
if (cached == null) { if (cached == null) {
return newMethodName; return newMethod;
}
if (!LoadMode.matches(remote, cached.mode())) {
return newMethodName;
} }
if (method.getAnnotation(DynForCached.class) != null) { if (method.getAnnotation(DynForCached.class) != null) {
return newMethodName; return newMethod;
}
if (!LoadMode.matches(remote, cached.mode())) {
return newMethod;
} }
if (Modifier.isFinal(method.getModifiers()) || Modifier.isStatic(method.getModifiers())) { if (Modifier.isFinal(method.getModifiers()) || Modifier.isStatic(method.getModifiers())) {
throw new RedkaleException( throw new RedkaleException(
@@ -102,12 +103,12 @@ public class CachedAsmMethodBoost extends AsmMethodBoost {
final AsmMethodBean methodBean = getMethodBean(method); final AsmMethodBean methodBean = getMethodBean(method);
{ // 定义一个新方法调用 this.rsMethodName { // 定义一个新方法调用 this.rsMethodName
final String cacheDynDesc = Type.getDescriptor(DynForCached.class); final String cacheDynDesc = Type.getDescriptor(DynForCached.class);
final MethodVisitor mv = createMethodVisitor(cw, method, newMethodName, methodBean); final MethodVisitor mv = createMethodVisitor(cw, method, newMethod, ACC_PRIVATE, methodBean);
// mv.setDebug(true); // mv.setDebug(true);
AnnotationVisitor av = mv.visitAnnotation(cacheDynDesc, true); AnnotationVisitor av = mv.visitAnnotation(cacheDynDesc, true);
av.visit("dynField", dynFieldName); av.visit("dynField", dynFieldName);
Asms.visitAnnotation(av, DynForCached.class, cached); Asms.visitAnnotation(av, DynForCached.class, cached);
visitRawAnnotation(method, newMethodName, mv, Cached.class, filterAnns); visitRawAnnotation(method, newMethod, mv, Cached.class, filterAnns);
Label l0 = new Label(); Label l0 = new Label();
mv.visitLabel(l0); mv.visitLabel(l0);
@@ -210,7 +211,7 @@ public class CachedAsmMethodBoost extends AsmMethodBoost {
"Lookup", "Lookup",
ACC_PUBLIC + ACC_FINAL + ACC_STATIC); ACC_PUBLIC + ACC_FINAL + ACC_STATIC);
} }
return rsMethodName; return new AsmNewMethod(rsMethodName, ACC_PRIVATE);
} }
@Override @Override

View File

@@ -10,6 +10,7 @@ import java.util.List;
import org.redkale.asm.AnnotationVisitor; import org.redkale.asm.AnnotationVisitor;
import org.redkale.asm.AsmMethodBean; import org.redkale.asm.AsmMethodBean;
import org.redkale.asm.AsmMethodBoost; import org.redkale.asm.AsmMethodBoost;
import org.redkale.asm.AsmNewMethod;
import org.redkale.asm.Asms; import org.redkale.asm.Asms;
import org.redkale.asm.ClassWriter; import org.redkale.asm.ClassWriter;
import org.redkale.asm.Label; import org.redkale.asm.Label;
@@ -36,7 +37,7 @@ public class LockedAsmMethodBoost extends AsmMethodBoost {
} }
@Override @Override
public String doMethod( public AsmNewMethod doMethod(
ClassLoader classLoader, ClassLoader classLoader,
ClassWriter cw, ClassWriter cw,
Class serviceImplClass, Class serviceImplClass,
@@ -44,16 +45,16 @@ public class LockedAsmMethodBoost extends AsmMethodBoost {
String fieldPrefix, String fieldPrefix,
List filterAnns, List filterAnns,
Method method, Method method,
final String newMethodName) { final AsmNewMethod newMethod) {
Locked locked = method.getAnnotation(Locked.class); Locked locked = method.getAnnotation(Locked.class);
if (locked == null) { if (locked == null) {
return newMethodName; return newMethod;
} }
if (!LoadMode.matches(remote, locked.mode())) { if (!LoadMode.matches(remote, locked.mode())) {
return newMethodName; return newMethod;
} }
if (method.getAnnotation(DynForLocked.class) != null) { if (method.getAnnotation(DynForLocked.class) != null) {
return newMethodName; return newMethod;
} }
if (Modifier.isFinal(method.getModifiers()) || Modifier.isStatic(method.getModifiers())) { if (Modifier.isFinal(method.getModifiers()) || Modifier.isStatic(method.getModifiers())) {
throw new RedkaleException( throw new RedkaleException(
@@ -70,14 +71,14 @@ public class LockedAsmMethodBoost extends AsmMethodBoost {
{ // 定义一个新方法调用 this.rsMethodName { // 定义一个新方法调用 this.rsMethodName
final AsmMethodBean methodBean = getMethodBean(method); final AsmMethodBean methodBean = getMethodBean(method);
final String lockDynDesc = Type.getDescriptor(DynForLocked.class); final String lockDynDesc = Type.getDescriptor(DynForLocked.class);
final MethodVisitor mv = createMethodVisitor(cw, method, newMethodName, methodBean); final MethodVisitor mv = createMethodVisitor(cw, method, newMethod, ACC_PRIVATE, methodBean);
// mv.setDebug(true); // mv.setDebug(true);
Label l0 = new Label(); Label l0 = new Label();
mv.visitLabel(l0); mv.visitLabel(l0);
AnnotationVisitor av = mv.visitAnnotation(lockDynDesc, true); AnnotationVisitor av = mv.visitAnnotation(lockDynDesc, true);
av.visit("dynField", dynFieldName); av.visit("dynField", dynFieldName);
Asms.visitAnnotation(av, DynForLocked.class, locked); Asms.visitAnnotation(av, DynForLocked.class, locked);
visitRawAnnotation(method, newMethodName, mv, Locked.class, filterAnns); visitRawAnnotation(method, newMethod, mv, Locked.class, filterAnns);
mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(ALOAD, 0);
List<Integer> insns = visitVarInsnParamTypes(mv, method, 0); List<Integer> insns = visitVarInsnParamTypes(mv, method, 0);
mv.visitMethodInsn(INVOKESPECIAL, newDynName, rsMethodName, Type.getMethodDescriptor(method), false); mv.visitMethodInsn(INVOKESPECIAL, newDynName, rsMethodName, Type.getMethodDescriptor(method), false);
@@ -85,7 +86,7 @@ public class LockedAsmMethodBoost extends AsmMethodBoost {
mv.visitMaxs(20, 20); mv.visitMaxs(20, 20);
mv.visitEnd(); mv.visitEnd();
} }
return rsMethodName; return new AsmNewMethod(rsMethodName, ACC_PRIVATE);
} }
@Override @Override

View File

@@ -21,8 +21,8 @@ import org.redkale.mq.MessageConsumer;
@Documented @Documented
@Target({TYPE}) @Target({TYPE})
@Retention(RUNTIME) @Retention(RUNTIME)
@Repeatable(DynForMessage.DynForMessages.class) @Repeatable(DynForMessaged.DynForMessageds.class)
public @interface DynForMessage { public @interface DynForMessaged {
Class<? extends MessageConsumer> value(); Class<? extends MessageConsumer> value();
@@ -30,8 +30,8 @@ public @interface DynForMessage {
@Documented @Documented
@Target({TYPE}) @Target({TYPE})
@Retention(RUNTIME) @Retention(RUNTIME)
@interface DynForMessages { @interface DynForMessageds {
DynForMessage[] value(); DynForMessaged[] value();
} }
} }

View File

@@ -16,6 +16,7 @@ import org.redkale.annotation.AutoLoad;
import org.redkale.asm.AnnotationVisitor; import org.redkale.asm.AnnotationVisitor;
import org.redkale.asm.AsmMethodBean; import org.redkale.asm.AsmMethodBean;
import org.redkale.asm.AsmMethodBoost; import org.redkale.asm.AsmMethodBoost;
import org.redkale.asm.AsmNewMethod;
import org.redkale.asm.Asms; import org.redkale.asm.Asms;
import org.redkale.asm.ClassWriter; import org.redkale.asm.ClassWriter;
import static org.redkale.asm.ClassWriter.COMPUTE_FRAMES; import static org.redkale.asm.ClassWriter.COMPUTE_FRAMES;
@@ -81,7 +82,7 @@ public class MessageAsmMethodBoost extends AsmMethodBoost {
} }
@Override @Override
public String doMethod( public AsmNewMethod doMethod(
ClassLoader classLoader, ClassLoader classLoader,
ClassWriter cw, ClassWriter cw,
Class serviceImplClass, Class serviceImplClass,
@@ -89,25 +90,30 @@ public class MessageAsmMethodBoost extends AsmMethodBoost {
String fieldPrefix, String fieldPrefix,
List filterAnns, List filterAnns,
Method method, Method method,
String newMethodName) { AsmNewMethod newMethod) {
if (serviceType.getAnnotation(DynForMessage.class) != null) { if (serviceType.getAnnotation(DynForMessaged.class) != null) {
return newMethodName; return newMethod;
} }
Messaged messaged = method.getAnnotation(Messaged.class); Messaged messaged = method.getAnnotation(Messaged.class);
if (messaged == null) { if (messaged == null) {
return newMethodName; return newMethod;
} }
if (!LoadMode.matches(remote, messaged.mode())) { if (!LoadMode.matches(remote, messaged.mode())) {
return newMethodName; return newMethod;
} }
if (Modifier.isFinal(method.getModifiers()) || Modifier.isStatic(method.getModifiers())) { if (Modifier.isFinal(method.getModifiers()) || Modifier.isStatic(method.getModifiers())) {
throw new RedkaleException( throw new RedkaleException(
"@" + Messaged.class.getSimpleName() + " cannot on final or static method, but on " + method); "@" + Messaged.class.getSimpleName() + " cannot on final or static method, but on " + method);
} }
if (Modifier.isProtected(method.getModifiers()) && Modifier.isFinal(method.getModifiers())) {
throw new RedkaleException(
"@" + Messaged.class.getSimpleName() + " cannot on protected final method, but on " + method);
}
if (!Modifier.isProtected(method.getModifiers()) && !Modifier.isPublic(method.getModifiers())) { if (!Modifier.isProtected(method.getModifiers()) && !Modifier.isPublic(method.getModifiers())) {
throw new RedkaleException( throw new RedkaleException(
"@" + Messaged.class.getSimpleName() + " must on protected or public method, but on " + method); "@" + Messaged.class.getSimpleName() + " must on protected or public method, but on " + method);
} }
int paramCount = method.getParameterCount(); int paramCount = method.getParameterCount();
if (paramCount != 1 && paramCount != 2) { if (paramCount != 1 && paramCount != 2) {
throw new RedkaleException( throw new RedkaleException(
@@ -135,9 +141,8 @@ public class MessageAsmMethodBoost extends AsmMethodBoost {
ConvertFactory factory = ConvertFactory factory =
ConvertFactory.findConvert(messaged.convertType()).getFactory(); ConvertFactory.findConvert(messaged.convertType()).getFactory();
factory.loadDecoder(messageType); factory.loadDecoder(messageType);
createInnerConsumer( createInnerConsumer(cw, method, paramKind, TypeToken.typeToClass(messageType), messaged, newDynName, newMethod);
cw, method, paramKind, TypeToken.typeToClass(messageType), messaged, newDynName, newMethodName); return newMethod;
return newMethodName;
} }
// paramKind: 1:单个MessageType; 2: MessageConext & MessageType; 3: MessageType & MessageConext; // paramKind: 1:单个MessageType; 2: MessageConext & MessageType; 3: MessageType & MessageConext;
@@ -148,7 +153,7 @@ public class MessageAsmMethodBoost extends AsmMethodBoost {
Class msgType, Class msgType,
Messaged messaged, Messaged messaged,
String newDynName, String newDynName,
String newMethodName) { AsmNewMethod newMethod) {
final String newDynDesc = "L" + newDynName + ";"; final String newDynDesc = "L" + newDynName + ";";
final String innerClassName = "Dyn" + MessageConsumer.class.getSimpleName() + index.incrementAndGet(); final String innerClassName = "Dyn" + MessageConsumer.class.getSimpleName() + index.incrementAndGet();
final String innerFullName = newDynName + "$" + innerClassName; final String innerFullName = newDynName + "$" + innerClassName;
@@ -221,7 +226,7 @@ public class MessageAsmMethodBoost extends AsmMethodBoost {
mv.visitEnd(); mv.visitEnd();
} }
{ {
String methodName = newMethodName == null ? method.getName() : newMethodName; String methodName = newMethod == null ? method.getName() : newMethod.getMethodName();
mv = cw.visitMethod( mv = cw.visitMethod(
ACC_PUBLIC, ACC_PUBLIC,
"onMessage", "onMessage",
@@ -325,7 +330,8 @@ public class MessageAsmMethodBoost extends AsmMethodBoost {
@Override @Override
public void doAfterMethods(ClassLoader classLoader, ClassWriter cw, String newDynName, String fieldPrefix) { public void doAfterMethods(ClassLoader classLoader, ClassWriter cw, String newDynName, String fieldPrefix) {
if (Utility.isNotEmpty(consumerBytes)) { if (Utility.isNotEmpty(consumerBytes)) {
AnnotationVisitor av = cw.visitAnnotation(org.redkale.asm.Type.getDescriptor(DynForMessage.class), true); AnnotationVisitor av =
cw.visitAnnotation(org.redkale.asm.Type.getDescriptor(DynForMessaged.class), true);
av.visit("value", org.redkale.asm.Type.getType("L" + newDynName.replace('.', '/') + ";")); av.visit("value", org.redkale.asm.Type.getType("L" + newDynName.replace('.', '/') + ";"));
av.visitEnd(); av.visitEnd();
} }
@@ -333,7 +339,7 @@ public class MessageAsmMethodBoost extends AsmMethodBoost {
@Override @Override
public void doInstance(ClassLoader classLoader, ResourceFactory resourceFactory, Object service) { public void doInstance(ClassLoader classLoader, ResourceFactory resourceFactory, Object service) {
DynForMessage[] dyns = service.getClass().getAnnotationsByType(DynForMessage.class); DynForMessaged[] dyns = service.getClass().getAnnotationsByType(DynForMessaged.class);
if (Utility.isEmpty(dyns)) { if (Utility.isEmpty(dyns)) {
return; return;
} }
@@ -358,12 +364,13 @@ public class MessageAsmMethodBoost extends AsmMethodBoost {
messageEngine.addMessageConsumer(consumer); messageEngine.addMessageConsumer(consumer);
} }
} else { } else {
for (DynForMessage item : dyns) { for (DynForMessaged item : dyns) {
Class<? extends MessageConsumer> clazz = item.value(); Class<? extends MessageConsumer> clazz = item.value();
MessageConsumer consumer = (MessageConsumer) clazz.getConstructors()[0].newInstance(service); MessageConsumer consumer = (MessageConsumer) clazz.getConstructors()[0].newInstance(service);
messageEngine.addMessageConsumer(consumer); messageEngine.addMessageConsumer(consumer);
} }
} }
} catch (Exception e) { } catch (Exception e) {
throw new RedkaleException(e); throw new RedkaleException(e);
} }

View File

@@ -658,9 +658,9 @@ public abstract class Sncp {
} }
methodKeys.add(mk); methodKeys.add(mk);
List<Class<? extends Annotation>> filterAnns = methodBoost.filterMethodAnnotations(method); List<Class<? extends Annotation>> filterAnns = methodBoost.filterMethodAnnotations(method);
String newMethodName = AsmNewMethod newMethod =
methodBoost.doMethod(classLoader, cw, clazz, newDynName, FIELDPREFIX, filterAnns, method, null); methodBoost.doMethod(classLoader, cw, clazz, newDynName, FIELDPREFIX, filterAnns, method, null);
if (newMethodName != null) { if (newMethod != null) {
String desc = Type.getMethodDescriptor(method); String desc = Type.getMethodDescriptor(method);
AsmMethodBean methodBean = AsmMethodBean.get(methodBeans, method); AsmMethodBean methodBean = AsmMethodBean.get(methodBeans, method);
String signature = null; String signature = null;
@@ -678,8 +678,8 @@ public abstract class Sncp {
exceptions = methodBean.getExceptions(); exceptions = methodBean.getExceptions();
} }
// 需要定义一个新方法调用 super.method // 需要定义一个新方法调用 super.method
mv = new MethodDebugVisitor( mv = new MethodDebugVisitor(cw.visitMethod(
cw.visitMethod(ACC_PRIVATE, newMethodName, desc, signature, exceptions)); newMethod.getMethodAccs(), newMethod.getMethodName(), desc, signature, exceptions));
Label l0 = new Label(); Label l0 = new Label();
mv.visitLabel(l0); mv.visitLabel(l0);
// mv.setDebug(true); // mv.setDebug(true);
@@ -1106,14 +1106,16 @@ public abstract class Sncp {
methodKeys.add(mk); methodKeys.add(mk);
int acc = ACC_PUBLIC; int acc = ACC_PUBLIC;
AsmNewMethod newMethod = null;
String newMethodName = null; String newMethodName = null;
if (methodBoost != null) { if (methodBoost != null) {
List<Class<? extends Annotation>> filterAnns = methodBoost.filterMethodAnnotations(method); List<Class<? extends Annotation>> filterAnns = methodBoost.filterMethodAnnotations(method);
newMethodName = methodBoost.doMethod( newMethod = methodBoost.doMethod(
classLoader, cw, serviceTypeOrImplClass, newDynName, FIELDPREFIX, filterAnns, method, null); classLoader, cw, serviceTypeOrImplClass, newDynName, FIELDPREFIX, filterAnns, method, null);
} }
if (newMethodName != null) { if (newMethod != null) {
acc = ACC_PRIVATE; acc = newMethod.getMethodAccs();
newMethodName = newMethod.getMethodName();
} else { } else {
newMethodName = method.getName(); newMethodName = method.getName();
} }

View File

@@ -3,7 +3,6 @@
package org.redkale.util; package org.redkale.util;
import java.util.*; import java.util.*;
import org.redkale.annotation.Priority;
/** /**
* 配置源Agent的Provider * 配置源Agent的Provider
@@ -22,11 +21,6 @@ public interface InstanceProvider<V> {
// 值大排前面 // 值大排前面
public static <P extends InstanceProvider> List<P> sort(List<P> providers) { public static <P extends InstanceProvider> List<P> sort(List<P> providers) {
Collections.sort(providers, (a, b) -> { return Utility.sortPriority(providers);
Priority p1 = a == null ? null : a.getClass().getAnnotation(Priority.class);
Priority p2 = b == null ? null : b.getClass().getAnnotation(Priority.class);
return (p2 == null ? 0 : p2.value()) - (p1 == null ? 0 : p1.value());
});
return providers;
} }
} }

View File

@@ -26,6 +26,7 @@ import java.util.zip.GZIPInputStream;
import javax.crypto.*; import javax.crypto.*;
import javax.crypto.spec.SecretKeySpec; import javax.crypto.spec.SecretKeySpec;
import org.redkale.annotation.ClassDepends; import org.redkale.annotation.ClassDepends;
import org.redkale.annotation.Priority;
import org.redkale.convert.json.JsonConvert; import org.redkale.convert.json.JsonConvert;
/** /**
@@ -1721,6 +1722,21 @@ public final class Utility {
return 0; return 0;
} }
/**
* 排序, 值大排前面
* @param <P> 泛型
* @param list 集合
* @return 排序后的集合
*/
public static <P> List<P> sortPriority(List<P> list) {
Collections.sort(list, (a, b) -> {
Priority p1 = a == null ? null : a.getClass().getAnnotation(Priority.class);
Priority p2 = b == null ? null : b.getClass().getAnnotation(Priority.class);
return (p2 == null ? 0 : p2.value()) - (p1 == null ? 0 : p1.value());
});
return list;
}
/** /**
* 将一个或多个新元素添加到数组开始,数组中的元素自动后移 * 将一个或多个新元素添加到数组开始,数组中的元素自动后移
* *