客户端ClientChannelHandler初始化逻辑优化

This commit is contained in:
aoshiguchen
2022-10-09 21:54:47 +08:00
parent e35adcca17
commit 3c8bcbf1f3
3 changed files with 37 additions and 26 deletions
@@ -0,0 +1,30 @@
package fun.asgc.neutrino.proxy.client.config;
import fun.asgc.neutrino.core.annotation.Bean;
import fun.asgc.neutrino.core.annotation.Component;
import fun.asgc.neutrino.core.annotation.Order;
import fun.asgc.neutrino.core.base.DefaultDispatcher;
import fun.asgc.neutrino.core.base.Dispatcher;
import fun.asgc.neutrino.core.base.Ordered;
import fun.asgc.neutrino.core.util.BeanManager;
import fun.asgc.neutrino.proxy.core.ProxyDataTypeEnum;
import fun.asgc.neutrino.proxy.core.ProxyMessage;
import fun.asgc.neutrino.proxy.core.ProxyMessageHandler;
import io.netty.channel.ChannelHandlerContext;
/**
* 代理配置
* @author: aoshiguchen
* @date: 2022/10/8
*/
@Order(Ordered.HIGHEST_PRECEDENCE)
@Component
public class ProxyConfiguration {
@Bean
public Dispatcher<ChannelHandlerContext, ProxyMessage> dispatcher() {
return new DefaultDispatcher<>("消息调度器",
BeanManager.getBeanListBySuperClass(ProxyMessageHandler.class),
proxyMessage -> ProxyDataTypeEnum.of((int)proxyMessage.getType()) == null ? null : ProxyDataTypeEnum.of((int)proxyMessage.getType()).getName());
}
}
@@ -22,13 +22,15 @@
package fun.asgc.neutrino.proxy.client.core;
import fun.asgc.neutrino.core.base.DefaultDispatcher;
import fun.asgc.neutrino.core.base.Dispatcher;
import fun.asgc.neutrino.core.util.BeanManager;
import fun.asgc.neutrino.core.util.LockUtil;
import fun.asgc.neutrino.proxy.client.util.ProxyUtil;
import fun.asgc.neutrino.proxy.core.*;
import io.netty.channel.*;
import fun.asgc.neutrino.proxy.core.Constants;
import fun.asgc.neutrino.proxy.core.ProxyMessage;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelOption;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.handler.timeout.IdleStateEvent;
import lombok.extern.slf4j.Slf4j;
@@ -44,17 +46,7 @@ public class ClientChannelHandler extends SimpleChannelInboundHandler<ProxyMessa
public ClientChannelHandler() {
try {
LockUtil.doubleCheckProcess(() -> null == dispatcher,
ClientChannelHandler.class,
() -> {
dispatcher = new DefaultDispatcher<>("消息调度器",
BeanManager.getBeanListBySuperClass(ProxyMessageHandler.class),
proxyMessage -> ProxyDataTypeEnum.of((int)proxyMessage.getType()) == null ? null : ProxyDataTypeEnum.of((int)proxyMessage.getType()).getName());
});
} catch (Exception e) {
e.printStackTrace();
}
dispatcher = BeanManager.getBean(Dispatcher.class);
}
@Override
@@ -45,17 +45,6 @@ public class ServerChannelHandler extends SimpleChannelInboundHandler<ProxyMessa
public ServerChannelHandler() {
dispatcher = BeanManager.getBean(Dispatcher.class);
// try {
// LockUtil.doubleCheckProcess(() -> null == dispatcher,
// ServerChannelHandler.class,
// () -> {
// dispatcher = new DefaultDispatcher<>("消息调度器",
// BeanManager.getBeanListBySuperClass(ProxyMessageHandler.class),
// proxyMessage -> ProxyDataTypeEnum.of((int)proxyMessage.getType()) == null ? null : ProxyDataTypeEnum.of((int)proxyMessage.getType()).getName());
// });
// } catch (Exception e) {
// e.printStackTrace();
// }
}
@Override