mirror of
https://github.com/tiennm99/zfoo.git
synced 2026-05-20 18:25:09 +00:00
perf[pojo]: 优化了事件和消息类的警告日志
This commit is contained in:
@@ -18,8 +18,11 @@ import com.zfoo.event.model.anno.EventReceiver;
|
||||
import com.zfoo.event.model.event.IEvent;
|
||||
import com.zfoo.event.model.vo.EnhanceUtils;
|
||||
import com.zfoo.event.model.vo.EventReceiverDefinition;
|
||||
import com.zfoo.protocol.collection.ArrayUtils;
|
||||
import com.zfoo.protocol.util.ReflectionUtils;
|
||||
import com.zfoo.protocol.util.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.config.BeanPostProcessor;
|
||||
|
||||
@@ -31,11 +34,21 @@ import java.lang.reflect.Modifier;
|
||||
*/
|
||||
public class EventRegisterProcessor implements BeanPostProcessor {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(EventRegisterProcessor.class);
|
||||
|
||||
@Override
|
||||
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
|
||||
var clazz = bean.getClass();
|
||||
var methods = ReflectionUtils.getMethodsByAnnoInPOJOClass(clazz, EventReceiver.class);
|
||||
if (ArrayUtils.isEmpty(methods)) {
|
||||
return bean;
|
||||
}
|
||||
|
||||
if (!ReflectionUtils.isPojoClass(clazz)) {
|
||||
logger.warn("事件注册类[{}]不是POJO类,父类的事件接收不会被扫描到", clazz);
|
||||
}
|
||||
|
||||
try {
|
||||
var clazz = bean.getClass();
|
||||
var methods = ReflectionUtils.getMethodsByAnnoInPOJOClass(clazz, EventReceiver.class);
|
||||
for (var method : methods) {
|
||||
var paramClazzs = method.getParameterTypes();
|
||||
if (paramClazzs.length != 1) {
|
||||
|
||||
@@ -15,12 +15,9 @@ import com.zfoo.protocol.collection.ArrayUtils;
|
||||
import com.zfoo.protocol.util.AssertionUtils;
|
||||
import com.zfoo.protocol.util.ReflectionUtils;
|
||||
import com.zfoo.protocol.util.StringUtils;
|
||||
import javassist.CannotCompileException;
|
||||
import javassist.NotFoundException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Modifier;
|
||||
|
||||
/**
|
||||
@@ -57,9 +54,12 @@ public abstract class PacketBus {
|
||||
var clazz = bean.getClass();
|
||||
|
||||
var methods = ReflectionUtils.getMethodsByAnnoInPOJOClass(clazz, PacketReceiver.class);
|
||||
if (ArrayUtils.isEmpty(methods)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (ArrayUtils.isNotEmpty(methods) && !ReflectionUtils.isPojoClass(clazz)) {
|
||||
logger.warn("消息注册类不是POJO类,父类的不会被扫描到");
|
||||
if (!ReflectionUtils.isPojoClass(clazz)) {
|
||||
logger.warn("消息注册类[{}]不是POJO类,父类的消息接收不会被扫描到", clazz);
|
||||
}
|
||||
|
||||
for (var method : methods) {
|
||||
@@ -111,7 +111,7 @@ public abstract class PacketBus {
|
||||
var receiverDefinition = new PacketReceiverDefinition(bean, method, packetClazz, attachmentClazz);
|
||||
var enhanceReceiverDefinition = EnhanceUtils.createPacketReceiver(receiverDefinition);
|
||||
packetReceiverList[protocolId] = enhanceReceiverDefinition;
|
||||
} catch (NoSuchFieldException | IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException | CannotCompileException | NotFoundException e) {
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user