基本拆分完,
只剩下ProxyConfig配置文件的获取要与spring兼容问题, 暂定使用ymlUtil
This commit is contained in:
+14
-98
@@ -1,27 +1,11 @@
|
||||
package org.dromara.neutrinoproxy.client.config;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import io.netty.bootstrap.Bootstrap;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.nio.NioEventLoopGroup;
|
||||
import org.dromara.neutrinoproxy.client.handler.BeanHandler;
|
||||
import org.dromara.neutrinoproxy.client.sdk.config.IBeanHandler;
|
||||
import org.dromara.neutrinoproxy.client.sdk.config.IProxyConfiguration;
|
||||
import org.dromara.neutrinoproxy.client.sdk.config.ProxyConfig;
|
||||
import org.dromara.neutrinoproxy.client.sdk.handler.*;
|
||||
import org.dromara.neutrinoproxy.client.sdk.solon.BeanHandler;
|
||||
import org.dromara.neutrinoproxy.core.ProxyDataTypeEnum;
|
||||
import org.dromara.neutrinoproxy.core.ProxyMessage;
|
||||
import org.dromara.neutrinoproxy.core.ProxyMessageHandler;
|
||||
import org.dromara.neutrinoproxy.core.aot.NeutrinoCoreRuntimeNativeRegistrar;
|
||||
import org.dromara.neutrinoproxy.core.dispatcher.DefaultDispatcher;
|
||||
import org.dromara.neutrinoproxy.core.dispatcher.Dispatcher;
|
||||
import org.dromara.neutrinoproxy.client.sdk.handler.ProxyMessageFactory;
|
||||
import org.noear.solon.Solon;
|
||||
import org.noear.solon.annotation.Bean;
|
||||
import org.noear.solon.annotation.Configuration;
|
||||
import org.noear.solon.annotation.Inject;
|
||||
import org.noear.solon.core.bean.LifecycleBean;
|
||||
|
||||
import java.util.List;
|
||||
import org.noear.solon.core.BeanWrap;
|
||||
|
||||
/**
|
||||
* 代理配置
|
||||
@@ -29,92 +13,24 @@ import java.util.List;
|
||||
* @date: 2022/10/8
|
||||
*/
|
||||
@Configuration
|
||||
public class ProxyConfiguration extends IProxyConfiguration implements LifecycleBean {
|
||||
@Inject
|
||||
private ProxyConfig proxyConfig;
|
||||
@Inject("tcpProxyTunnelBootstrap")
|
||||
private Bootstrap tcpProxyTunnelBootstrap;
|
||||
@Inject("realServerBootstrap")
|
||||
private Bootstrap realServerBootstrap;
|
||||
public class ProxyConfiguration extends ProxyMessageFactory {
|
||||
|
||||
@Override
|
||||
public void start() throws Throwable {
|
||||
List<ProxyMessageHandler> list = Lists.newArrayList(
|
||||
new ProxyMessageAuthHandler(proxyConfig),
|
||||
new ProxyMessageConnectHandler(tcpProxyTunnelBootstrap,realServerBootstrap,proxyConfig),
|
||||
new ProxyMessageDisconnectHandler(),
|
||||
new ProxyMessageErrorHandler(),
|
||||
new ProxyMessageTransferHandler(),
|
||||
new UdpProxyMessageConnectHandler(proxyConfig,tcpProxyTunnelBootstrap),
|
||||
new UdpProxyMessageTransferHandler()
|
||||
);
|
||||
Dispatcher<ChannelHandlerContext, ProxyMessage> dispatcher = new DefaultDispatcher<>("MessageDispatcher", list,
|
||||
proxyMessage -> ProxyDataTypeEnum.of((int)proxyMessage.getType()) == null ?
|
||||
null : ProxyDataTypeEnum.of((int)proxyMessage.getType()).getName());
|
||||
Solon.context().wrapAndPut(Dispatcher.class, dispatcher);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBeanHandler getBeanHandler() {
|
||||
return new BeanHandler();
|
||||
}
|
||||
@Bean("tunnelWorkGroup")
|
||||
public NioEventLoopGroup tunnelWorkGroup(@Inject ProxyConfig proxyConfig) {
|
||||
return super.tunnelWorkGroup(proxyConfig);
|
||||
|
||||
@Override
|
||||
public void beanInject(String beanName, Object bean) {
|
||||
//包装Bean(指定名字的)
|
||||
BeanWrap beanWrap = Solon.context().wrap(beanName, bean);
|
||||
//以名字注册
|
||||
Solon.context().putWrap(beanName, beanWrap);
|
||||
}
|
||||
|
||||
@Bean("tcpRealServerWorkGroup")
|
||||
public NioEventLoopGroup tcpRealServerWorkGroup(@Inject ProxyConfig proxyConfig) {
|
||||
// 暂时先公用此配置
|
||||
return super.tcpRealServerWorkGroup(proxyConfig);
|
||||
}
|
||||
|
||||
@Bean("udpServerGroup")
|
||||
public NioEventLoopGroup udpServerGroup(@Inject ProxyConfig proxyConfig) {
|
||||
// 暂时先公用此配置
|
||||
return super.udpServerGroup(proxyConfig);
|
||||
}
|
||||
|
||||
@Bean("udpWorkGroup")
|
||||
public NioEventLoopGroup udpWorkGroup(@Inject ProxyConfig proxyConfig) {
|
||||
// 暂时先公用此配置
|
||||
return super.udpWorkGroup(proxyConfig);
|
||||
}
|
||||
|
||||
@Bean("cmdTunnelBootstrap")
|
||||
public Bootstrap cmdTunnelBootstrap(@Inject ProxyConfig proxyConfig,
|
||||
@Inject("tunnelWorkGroup") NioEventLoopGroup tunnelWorkGroup) {
|
||||
return super.cmdTunnelBootstrap(proxyConfig,tunnelWorkGroup);
|
||||
}
|
||||
|
||||
@Bean("tcpProxyTunnelBootstrap")
|
||||
public Bootstrap tcpProxyTunnelBootstrap(@Inject ProxyConfig proxyConfig,
|
||||
@Inject("tunnelWorkGroup") NioEventLoopGroup tunnelWorkGroup) {
|
||||
return super.tcpProxyTunnelBootstrap(proxyConfig,tunnelWorkGroup);
|
||||
}
|
||||
|
||||
@Bean("udpProxyTunnelBootstrap")
|
||||
public Bootstrap udpProxyTunnelBootstrap(@Inject ProxyConfig proxyConfig,
|
||||
@Inject("tunnelWorkGroup") NioEventLoopGroup tunnelWorkGroup) {
|
||||
return super.udpProxyTunnelBootstrap(proxyConfig,tunnelWorkGroup);
|
||||
}
|
||||
|
||||
@Bean("realServerBootstrap")
|
||||
public Bootstrap realServerBootstrap(@Inject ProxyConfig proxyConfig,
|
||||
@Inject("tcpRealServerWorkGroup") NioEventLoopGroup tcpRealServerWorkGroup
|
||||
) {
|
||||
return super.realServerBootstrap(proxyConfig,tcpRealServerWorkGroup);
|
||||
}
|
||||
|
||||
@Bean("udpServerBootstrap")
|
||||
public Bootstrap udpServerBootstrap(@Inject ProxyConfig proxyConfig,
|
||||
@Inject("udpServerGroup") NioEventLoopGroup udpServerGroup,
|
||||
@Inject("udpWorkGroup") NioEventLoopGroup udpWorkGroup) {
|
||||
return super.udpServerBootstrap(proxyConfig,udpServerGroup,udpWorkGroup);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public NeutrinoCoreRuntimeNativeRegistrar neutrinoCoreRuntimeNativeRegistrar() {
|
||||
return super.neutrinoCoreRuntimeNativeRegistrar();
|
||||
@Override
|
||||
public Object getBean(String beanName) {
|
||||
return Solon.context().getBean(beanName);
|
||||
}
|
||||
}
|
||||
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
package org.dromara.neutrinoproxy.client.core;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.neutrinoproxy.client.config.ProxyConfiguration;
|
||||
import org.dromara.neutrinoproxy.client.sdk.config.ProxyConfig;
|
||||
import org.noear.solon.annotation.Component;
|
||||
import org.noear.solon.annotation.Init;
|
||||
import org.noear.solon.annotation.Inject;
|
||||
|
||||
/**
|
||||
* 代理客户端服务
|
||||
* @author: aoshiguchen
|
||||
* @date: 2022/6/16
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class ProxyClientService{
|
||||
@Inject
|
||||
private ProxyConfiguration proxyConfiguration;
|
||||
@Inject
|
||||
private ProxyConfig proxyConfig;
|
||||
@Init
|
||||
public void init() {
|
||||
log.info("启动中....");
|
||||
proxyConfiguration.start(proxyConfig);
|
||||
log.info("启动成功....");
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -7,9 +7,10 @@ import org.noear.solon.Solon;
|
||||
|
||||
|
||||
public class BeanHandler implements IBeanHandler {
|
||||
|
||||
@Override
|
||||
public Dispatcher getDispatcher(){
|
||||
return Solon.context().getBean(Dispatcher.class);
|
||||
return Solon.context().getBean("dispatcher");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user