use of com.code.server.gate.config.ServerConfig in project summer by foxsugar.
the class GateApplication method main.
public static void main(String[] args) throws RegisterFailedException {
SpringApplication.run(GateApplication.class, args);
SpringUtil.getBean(ServerConfig.class);
ServerConfig serverConfig = SpringUtil.getBean(ServerConfig.class);
ThreadPool.getInstance().executor.execute(new SocketServer());
if (serverConfig.getStartWebSocket() == 1) {
ThreadPool.getInstance().executor.execute(new WebSocketServer());
}
ServerState.isWork = true;
// 配置文件
// 注册服务
RedisManager.getGateRedisService().register(serverConfig.getServerType(), serverConfig.getServerId(), serverConfig.getHost(), serverConfig.getDomain(), serverConfig.getNetPort());
// 心跳
// 定时器
ThreadPool.execute(() -> GameTimer.getInstance().fire());
GameTimer.addTimerNode(IConstant.SECOND_5, true, () -> RedisManager.getGateRedisService().heart(serverConfig.getServerId()));
// //kafka消费者
// MsgConsumer.startAConsumer(IKafaTopic.GATE_TOPIC,serverConfig.getServerId(), new GateConsumer());
}
use of com.code.server.gate.config.ServerConfig in project summer by foxsugar.
the class SocketServer method start.
private void start() throws Exception {
ServerConfig serverConfig = SpringUtil.getBean(ServerConfig.class);
int port = serverConfig.getPort();
final SslContext sslCtx;
if (SSL) {
SelfSignedCertificate ssc = new SelfSignedCertificate();
sslCtx = SslContext.newServerContext(ssc.certificate(), ssc.privateKey());
} else {
sslCtx = null;
}
// Configure the server.
EventLoopGroup bossGroup = new NioEventLoopGroup(1);
EventLoopGroup workerGroup = new NioEventLoopGroup();
try {
ServerBootstrap b = new ServerBootstrap();
b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class).option(ChannelOption.SO_BACKLOG, 100).handler(new LoggingHandler(LogLevel.INFO)).childHandler(new SocketServerInitializer(sslCtx));
// .childHandler(new WebSocketServerInitializer());
// Start the server.
ChannelFuture f = b.bind(port).sync();
// Wait until the server socket is closed.
f.channel().closeFuture().sync();
} finally {
// Shut down all event loops to terminate all threads.
bossGroup.shutdownGracefully();
workerGroup.shutdownGracefully();
}
}
use of com.code.server.gate.config.ServerConfig in project summer by foxsugar.
the class WebSocketServer method start.
private void start() throws Exception {
ServerConfig serverConfig = SpringUtil.getBean(ServerConfig.class);
int port = serverConfig.getWebSocketPort();
final SslContext sslCtx;
if (SSL) {
SelfSignedCertificate ssc = new SelfSignedCertificate();
sslCtx = SslContext.newServerContext(ssc.certificate(), ssc.privateKey());
} else {
sslCtx = null;
}
// Configure the server.
EventLoopGroup bossGroup = new NioEventLoopGroup(1);
EventLoopGroup workerGroup = new NioEventLoopGroup();
try {
ServerBootstrap b = new ServerBootstrap();
b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class).option(ChannelOption.SO_BACKLOG, 100).handler(new LoggingHandler(LogLevel.INFO)).childHandler(new WebSocketServerInitializer());
// Start the server.
ChannelFuture f = b.bind(port).sync();
// Wait until the server socket is closed.
f.channel().closeFuture().sync();
} finally {
// Shut down all event loops to terminate all threads.
bossGroup.shutdownGracefully();
workerGroup.shutdownGracefully();
}
}
Aggregations