换了几个较小的包。缩了下 server 大小
This commit is contained in:
@@ -3,6 +3,7 @@ package fun.asgc.neutrino.proxy.server;
|
||||
import fun.asgc.solon.extend.job.annotation.EnableJob;
|
||||
import org.noear.solon.Solon;
|
||||
import org.noear.solon.annotation.Controller;
|
||||
import org.noear.solon.annotation.SolonMain;
|
||||
import org.noear.solon.web.cors.CrossFilter;
|
||||
|
||||
/**
|
||||
@@ -11,7 +12,7 @@ import org.noear.solon.web.cors.CrossFilter;
|
||||
* @date: 2022/6/16
|
||||
*/
|
||||
@EnableJob
|
||||
@Controller
|
||||
@SolonMain
|
||||
public class ProxyServer {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
+2
@@ -48,6 +48,7 @@ public class DBInitialize implements EventListener<AppLoadEndEvent> {
|
||||
private static List<String> initDataTableNameList = Lists.newArrayList("user", "license", "port_pool", "port_mapping", "job_info");
|
||||
@Inject
|
||||
private DbConfig dbConfig;
|
||||
|
||||
private DbTypeEnum dbTypeEnum;
|
||||
|
||||
@Init
|
||||
@@ -91,6 +92,7 @@ public class DBInitialize implements EventListener<AppLoadEndEvent> {
|
||||
|
||||
/**
|
||||
* 初始化数据
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
private void initDBData() throws Exception {
|
||||
|
||||
+11
-8
@@ -1,10 +1,10 @@
|
||||
package fun.asgc.neutrino.proxy.server.base.db;
|
||||
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.baomidou.mybatisplus.core.MybatisConfiguration;
|
||||
import com.baomidou.mybatisplus.core.MybatisSqlSessionFactoryBuilder;
|
||||
import com.baomidou.mybatisplus.core.config.GlobalConfig;
|
||||
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
|
||||
import com.zaxxer.hikari.HikariDataSource;
|
||||
import fun.asgc.neutrino.proxy.server.constant.DbTypeEnum;
|
||||
import org.apache.ibatis.solon.annotation.Db;
|
||||
import org.noear.solon.annotation.Bean;
|
||||
@@ -31,14 +31,17 @@ public class DbConfiguration {
|
||||
dataSource.setJournalMode(SQLiteConfig.JournalMode.WAL.getValue());
|
||||
return dataSource;
|
||||
} else if (DbTypeEnum.MYSQL == dbTypeEnum) {
|
||||
DruidDataSource dataSource = new DruidDataSource();
|
||||
HikariDataSource dataSource = new HikariDataSource();
|
||||
dataSource.setDriverClassName(dbConfig.getDriverClass());
|
||||
dataSource.setUrl(dbConfig.getUrl());
|
||||
dataSource.setInitialSize(5);
|
||||
dataSource.setMinIdle(5);
|
||||
dataSource.setMaxActive(20);
|
||||
dataSource.setMaxWait(60000);
|
||||
dataSource.setPoolPreparedStatements(true);
|
||||
dataSource.setJdbcUrl(dbConfig.getUrl());
|
||||
dataSource.setMinimumIdle(5);
|
||||
dataSource.setMaximumPoolSize(20);
|
||||
dataSource.setMaxLifetime(60000);
|
||||
// dataSource.setInitialSize(5);
|
||||
// dataSource.setMinIdle(5);
|
||||
// dataSource.setMaxActive(20);
|
||||
// dataSource.setMaxWait(60000);
|
||||
// dataSource.setPoolPreparedStatements(true);
|
||||
dataSource.setUsername(dbConfig.getUsername());
|
||||
dataSource.setPassword(dbConfig.getPassword());
|
||||
return dataSource;
|
||||
|
||||
+15
-10
@@ -11,6 +11,7 @@ import org.noear.solon.annotation.Bean;
|
||||
import org.noear.solon.annotation.Configuration;
|
||||
import org.noear.solon.annotation.Inject;
|
||||
import org.noear.solon.core.AopContext;
|
||||
import org.noear.solon.core.bean.LifecycleBean;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -20,16 +21,19 @@ import java.util.List;
|
||||
* @date: 2022/10/8
|
||||
*/
|
||||
@Configuration
|
||||
public class ProxyConfiguration {
|
||||
@Bean
|
||||
public void dispatcher(@Inject AopContext aopContext) {
|
||||
aopContext.lifecycle(() -> {
|
||||
List<ProxyMessageHandler> list = aopContext.getBeansOfType(ProxyMessageHandler.class);
|
||||
Dispatcher<ChannelHandlerContext, ProxyMessage> dispatcher = new DefaultDispatcher<>("消息调度器", list,
|
||||
proxyMessage -> ProxyDataTypeEnum.of((int)proxyMessage.getType()) == null ?
|
||||
null : ProxyDataTypeEnum.of((int)proxyMessage.getType()).getName());
|
||||
aopContext.wrapAndPut(Dispatcher.class, dispatcher);
|
||||
});
|
||||
public class ProxyConfiguration implements LifecycleBean {
|
||||
@Inject
|
||||
AopContext aopContext;
|
||||
|
||||
@Override
|
||||
public void start() throws Throwable {
|
||||
List<ProxyMessageHandler> list = aopContext.getBeansOfType(ProxyMessageHandler.class);
|
||||
|
||||
Dispatcher<ChannelHandlerContext, ProxyMessage> dispatcher = new DefaultDispatcher<>("消息调度器", list,
|
||||
proxyMessage -> ProxyDataTypeEnum.of((int)proxyMessage.getType()) == null ?
|
||||
null : ProxyDataTypeEnum.of((int)proxyMessage.getType()).getName());
|
||||
|
||||
aopContext.wrapAndPut(Dispatcher.class, dispatcher);
|
||||
}
|
||||
|
||||
@Bean("serverBossGroup")
|
||||
@@ -41,4 +45,5 @@ public class ProxyConfiguration {
|
||||
public NioEventLoopGroup serverWorkerGroup() {
|
||||
return new NioEventLoopGroup();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+3
@@ -74,17 +74,20 @@ public class BaseAuthInterceptor implements RouterInterceptor {
|
||||
|
||||
if (result instanceof Throwable) {
|
||||
log.error("全局异常", (Throwable) result);
|
||||
|
||||
if (result instanceof ServiceException) {
|
||||
ServiceException exception = (ServiceException) result;
|
||||
return new ResponseBody<>()
|
||||
.setCode(exception.getCode())
|
||||
.setMsg(exception.getMsg());
|
||||
}
|
||||
|
||||
return new ResponseBody<>()
|
||||
.setCode(ExceptionConstant.SYSTEM_ERROR.getCode())
|
||||
.setMsg(ExceptionConstant.SYSTEM_ERROR.getMsg())
|
||||
.setStack(ExceptionUtils.getStackTrace((Throwable) result));
|
||||
}
|
||||
|
||||
return new ResponseBody<>()
|
||||
.setCode(0)
|
||||
.setData(result);
|
||||
|
||||
+3
-1
@@ -24,13 +24,15 @@ public class GlobalExceptionFilter implements Filter {
|
||||
chain.doFilter(ctx);
|
||||
} catch (Throwable e) {
|
||||
log.error("全局异常", e);
|
||||
|
||||
if (e instanceof ServiceException) {
|
||||
ServiceException serviceException = (ServiceException)e;
|
||||
ServiceException serviceException = (ServiceException) e;
|
||||
ctx.render(new ResponseBody<>()
|
||||
.setCode(serviceException.getCode())
|
||||
.setMsg(serviceException.getMsg()));
|
||||
return;
|
||||
}
|
||||
|
||||
ctx.render(new ResponseBody<>()
|
||||
.setCode(ExceptionConstant.SYSTEM_ERROR.getCode())
|
||||
.setMsg(ExceptionConstant.SYSTEM_ERROR.getMsg())
|
||||
|
||||
Reference in New Issue
Block a user