diff --git a/src/main/java/org/redkale/asm/AsmMethodBoost.java b/src/main/java/org/redkale/asm/AsmMethodBoost.java new file mode 100644 index 000000000..b98d1eca6 --- /dev/null +++ b/src/main/java/org/redkale/asm/AsmMethodBoost.java @@ -0,0 +1,35 @@ +/* + * + */ +package org.redkale.asm; + +import java.lang.reflect.Method; +import org.redkale.annotation.Nullable; + +/** + * 生产动态字节码的方法扩展器, 可以进行方法加强动作 + * + * @param 泛型 + * + * @since 2.8.0 + */ +public interface AsmMethodBoost { + + /** + * 对方法进行动态加强处理 + * + * @param cw 动态字节码Writer + * @param method 操作的方法 + * @param newMethodName 新的方法名, 可能为null + * + * @return 下一个新的方法名,不做任何处理应返回参数newMethodName + */ + public String doMethod(ClassWriter cw, Method method, @Nullable String newMethodName); + + /** + * 实例对象进行操作,通常用于给动态的字段赋值 + * + * @param service 实例对象 + */ + public void doInstance(T service); +} diff --git a/src/main/java/org/redkale/asm/AsmMethodBoosts.java b/src/main/java/org/redkale/asm/AsmMethodBoosts.java new file mode 100644 index 000000000..76fb8c9df --- /dev/null +++ b/src/main/java/org/redkale/asm/AsmMethodBoosts.java @@ -0,0 +1,43 @@ +/* + * + */ +package org.redkale.asm; + +import java.lang.reflect.Method; + +/** + * 生产动态字节码的方法扩展器, 可以进行方法加强动作 + * + * @param 泛型 + * + * @since 2.8.0 + */ +public class AsmMethodBoosts implements AsmMethodBoost { + + private final AsmMethodBoosts[] items; + + public AsmMethodBoosts(AsmMethodBoosts... items) { + this.items = items; + } + + @Override + public String doMethod(ClassWriter cw, Method method, String newMethodName) { + String newName = newMethodName; + for (AsmMethodBoosts item : items) { + if (item != null) { + newName = item.doMethod(cw, method, newName); + } + } + return newName; + } + + @Override + public void doInstance(T service) { + for (AsmMethodBoosts item : items) { + if (item != null) { + item.doInstance(service); + } + } + } + +} diff --git a/src/main/java/org/redkale/cache/spi/CacheManagerService.java b/src/main/java/org/redkale/cache/spi/CacheManagerService.java index ae28e2980..42726bd35 100644 --- a/src/main/java/org/redkale/cache/spi/CacheManagerService.java +++ b/src/main/java/org/redkale/cache/spi/CacheManagerService.java @@ -97,7 +97,7 @@ public class CacheManagerService implements CacheManager, Service { if (this.enabled) { this.localSource.init(conf); String remoteSourceName = conf.getValue("remote"); - if (remoteSource == null && application != null && Utility.isNotBlank(remoteSourceName)) { + if (Utility.isNotBlank(remoteSourceName)) { CacheSource source = application.loadCacheSource(remoteSourceName, false); if (source == null) { throw new RedkaleException("Not found CacheSource '" + remoteSourceName + "'"); diff --git a/src/main/java/org/redkale/net/http/Rest.java b/src/main/java/org/redkale/net/http/Rest.java index 6ec2de230..7d0921473 100644 --- a/src/main/java/org/redkale/net/http/Rest.java +++ b/src/main/java/org/redkale/net/http/Rest.java @@ -594,7 +594,7 @@ public final class Rest { { av0 = fv.visitAnnotation(resDesc, true); av0.visit("name", res != null ? res.name() : res2.name()); - av0.visit("required", res != null ? res.required() : true); + av0.visit("required", res == null || res.required()); av0.visitEnd(); } fv.visitEnd(); diff --git a/src/main/java/org/redkale/net/sncp/Sncp.java b/src/main/java/org/redkale/net/sncp/Sncp.java index c72bb34da..496272e10 100644 --- a/src/main/java/org/redkale/net/sncp/Sncp.java +++ b/src/main/java/org/redkale/net/sncp/Sncp.java @@ -31,6 +31,7 @@ import org.redkale.util.RedkaleClassLoader; import org.redkale.util.TypeToken; import org.redkale.util.Uint128; import org.redkale.util.Utility; +import static org.redkale.util.Utility.isEmpty; /** * Service Node Communicate Protocol @@ -271,11 +272,11 @@ public abstract class Sncp { //格式: sncp.req.module.user public static String generateSncpReqTopic(String resourceName, Class resourceType, int nodeid) { if (WebSocketNode.class.isAssignableFrom(resourceType)) { - return getSncpReqTopicPrefix() + "module.wsnode" + nodeid + (resourceName.isEmpty() ? "" : ("-" + resourceName)); + return getSncpReqTopicPrefix() + "module.wsnode" + nodeid + (isEmpty(resourceName) ? "" : ("-" + resourceName)); } return getSncpReqTopicPrefix() + "module." + resourceType.getSimpleName().replaceAll("Service.*$", "").toLowerCase() - + (resourceName.isEmpty() ? "" : ("-" + resourceName)); + + (isEmpty(resourceName) ? "" : ("-" + resourceName)); } public static String getSncpReqTopicPrefix() { @@ -729,7 +730,8 @@ public abstract class Sncp { throw new SncpException(serviceTypeOrImplClass + " is not Service type"); } if ((sncpRpcGroups == null || client == null) && agent == null) { - throw new SncpException("SncpRpcGroups/SncpClient and MessageAgent are both null"); + throw new SncpException(SncpRpcGroups.class.getSimpleName() + "/" + SncpClient.class.getSimpleName() + + " and " + MessageAgent.class.getSimpleName() + " are both null"); } ResourceFactory.checkResourceName(name); final int mod = serviceTypeOrImplClass.getModifiers(); diff --git a/src/main/java/org/redkale/schedule/Scheduled.java b/src/main/java/org/redkale/schedule/Scheduled.java index 2f67835c4..a6ad1b0d9 100644 --- a/src/main/java/org/redkale/schedule/Scheduled.java +++ b/src/main/java/org/redkale/schedule/Scheduled.java @@ -7,7 +7,7 @@ import java.lang.annotation.*; import java.util.concurrent.TimeUnit; /** - * 定时任务标记,只能作用于Service的protected且无参数方法上, 功能类似Spring里的Scheduled注解 + * 定时任务标记,只能作用于Service的无参数方法上, 功能类似Spring里的Scheduled注解 * * *

@@ -22,7 +22,7 @@ import java.util.concurrent.TimeUnit; public @interface Scheduled { /** - * 名称 + * 名称, 也可以用于第三方实现的定时任务组件的key * * @return 名称 */