AsmMethodBoost接口
This commit is contained in:
35
src/main/java/org/redkale/asm/AsmMethodBoost.java
Normal file
35
src/main/java/org/redkale/asm/AsmMethodBoost.java
Normal file
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
*
|
||||
*/
|
||||
package org.redkale.asm;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import org.redkale.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* 生产动态字节码的方法扩展器, 可以进行方法加强动作
|
||||
*
|
||||
* @param <T> 泛型
|
||||
*
|
||||
* @since 2.8.0
|
||||
*/
|
||||
public interface AsmMethodBoost<T> {
|
||||
|
||||
/**
|
||||
* 对方法进行动态加强处理
|
||||
*
|
||||
* @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);
|
||||
}
|
||||
43
src/main/java/org/redkale/asm/AsmMethodBoosts.java
Normal file
43
src/main/java/org/redkale/asm/AsmMethodBoosts.java
Normal file
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
*
|
||||
*/
|
||||
package org.redkale.asm;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* 生产动态字节码的方法扩展器, 可以进行方法加强动作
|
||||
*
|
||||
* @param <T> 泛型
|
||||
*
|
||||
* @since 2.8.0
|
||||
*/
|
||||
public class AsmMethodBoosts<T> implements AsmMethodBoost<T> {
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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 + "'");
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -7,7 +7,7 @@ import java.lang.annotation.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* 定时任务标记,只能作用于Service的protected且无参数方法上, 功能类似Spring里的Scheduled注解
|
||||
* 定时任务标记,只能作用于Service的无参数方法上, 功能类似Spring里的Scheduled注解
|
||||
*
|
||||
*
|
||||
* <p>
|
||||
@@ -22,7 +22,7 @@ import java.util.concurrent.TimeUnit;
|
||||
public @interface Scheduled {
|
||||
|
||||
/**
|
||||
* 名称
|
||||
* 名称, 也可以用于第三方实现的定时任务组件的key
|
||||
*
|
||||
* @return 名称
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user