Search in sources :

Example 1 with ServerConfig

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());
}
Also used : ServerConfig(com.code.server.gate.config.ServerConfig) WebSocketServer(com.code.server.gate.bootstarp.WebSocketServer) WebSocketServer(com.code.server.gate.bootstarp.WebSocketServer) SocketServer(com.code.server.gate.bootstarp.SocketServer)

Example 2 with ServerConfig

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();
    }
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) ServerConfig(com.code.server.gate.config.ServerConfig) LoggingHandler(io.netty.handler.logging.LoggingHandler) SelfSignedCertificate(io.netty.handler.ssl.util.SelfSignedCertificate) EventLoopGroup(io.netty.channel.EventLoopGroup) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) NioServerSocketChannel(io.netty.channel.socket.nio.NioServerSocketChannel) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) ServerBootstrap(io.netty.bootstrap.ServerBootstrap) SslContext(io.netty.handler.ssl.SslContext)

Example 3 with ServerConfig

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();
    }
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) ServerConfig(com.code.server.gate.config.ServerConfig) LoggingHandler(io.netty.handler.logging.LoggingHandler) SelfSignedCertificate(io.netty.handler.ssl.util.SelfSignedCertificate) EventLoopGroup(io.netty.channel.EventLoopGroup) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) NioServerSocketChannel(io.netty.channel.socket.nio.NioServerSocketChannel) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) ServerBootstrap(io.netty.bootstrap.ServerBootstrap) SslContext(io.netty.handler.ssl.SslContext)

Aggregations

ServerConfig (com.code.server.gate.config.ServerConfig)3 ServerBootstrap (io.netty.bootstrap.ServerBootstrap)2 ChannelFuture (io.netty.channel.ChannelFuture)2 EventLoopGroup (io.netty.channel.EventLoopGroup)2 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)2 NioServerSocketChannel (io.netty.channel.socket.nio.NioServerSocketChannel)2 LoggingHandler (io.netty.handler.logging.LoggingHandler)2 SslContext (io.netty.handler.ssl.SslContext)2 SelfSignedCertificate (io.netty.handler.ssl.util.SelfSignedCertificate)2 SocketServer (com.code.server.gate.bootstarp.SocketServer)1 WebSocketServer (com.code.server.gate.bootstarp.WebSocketServer)1