CacheAsmMethodBoost优化
This commit is contained in:
@@ -7,6 +7,7 @@ import java.lang.annotation.Annotation;
|
|||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
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;
|
||||||
@@ -19,6 +20,7 @@ import static org.redkale.asm.Opcodes.*;
|
|||||||
import org.redkale.asm.Type;
|
import org.redkale.asm.Type;
|
||||||
import org.redkale.cache.Cached;
|
import org.redkale.cache.Cached;
|
||||||
import org.redkale.util.RedkaleException;
|
import org.redkale.util.RedkaleException;
|
||||||
|
import org.redkale.util.TypeToken;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -26,6 +28,9 @@ import org.redkale.util.RedkaleException;
|
|||||||
*/
|
*/
|
||||||
public class CacheAsmMethodBoost extends AsmMethodBoost {
|
public class CacheAsmMethodBoost extends AsmMethodBoost {
|
||||||
|
|
||||||
|
private static final java.lang.reflect.Type FUTURE_VOID = new TypeToken<CompletableFuture<Void>>() {
|
||||||
|
}.getType();
|
||||||
|
|
||||||
private static final List<Class<? extends Annotation>> FILTER_ANN = List.of(Cached.class, DynForCache.class);
|
private static final List<Class<? extends Annotation>> FILTER_ANN = List.of(Cached.class, DynForCache.class);
|
||||||
|
|
||||||
public CacheAsmMethodBoost(Class serviceType) {
|
public CacheAsmMethodBoost(Class serviceType) {
|
||||||
@@ -47,11 +52,14 @@ public class CacheAsmMethodBoost extends AsmMethodBoost {
|
|||||||
return newMethodName;
|
return newMethodName;
|
||||||
}
|
}
|
||||||
if (Modifier.isFinal(method.getModifiers()) || Modifier.isStatic(method.getModifiers())) {
|
if (Modifier.isFinal(method.getModifiers()) || Modifier.isStatic(method.getModifiers())) {
|
||||||
throw new RedkaleException("@" + Cached.class.getSimpleName() + " can not on final or static method, but on " + method);
|
throw new RedkaleException("@" + Cached.class.getSimpleName() + " cannot on final or static 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("@" + Cached.class.getSimpleName() + " must on protected or public method, but on " + method);
|
throw new RedkaleException("@" + Cached.class.getSimpleName() + " must on protected or public method, but on " + method);
|
||||||
}
|
}
|
||||||
|
if (method.getReturnType() == void.class || FUTURE_VOID.equals(method.getGenericReturnType())) {
|
||||||
|
throw new RedkaleException("@" + Cached.class.getSimpleName() + " cannot on void method, but on " + method);
|
||||||
|
}
|
||||||
|
|
||||||
final String rsMethodName = method.getName() + "_afterCache";
|
final String rsMethodName = method.getName() + "_afterCache";
|
||||||
final String dynFieldName = fieldPrefix + "_" + method.getName() + "CacheAction" + fieldIndex.incrementAndGet();
|
final String dynFieldName = fieldPrefix + "_" + method.getName() + "CacheAction" + fieldIndex.incrementAndGet();
|
||||||
|
|||||||
Reference in New Issue
Block a user