package com.yfd.platform.component.nettyudpserver;


import com.yfd.platform.component.nettyserver.NettyServer;
import com.yfd.platform.utils.ExecutionJob;
import io.netty.channel.Channel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

@Component
@Order(value = 20)
public class NettyUdpRunner implements CommandLineRunner {
    private static final Logger logger = LoggerFactory.getLogger(NettyUdpRunner.class);

    @Override
    public void run(String... args) throws Exception {
        
        ExecutionJob.EXECUTOR.submit(() -> {
            NettyUdpServer server = null;
            try {
                server = new NettyUdpServer(9300);
                Channel channel = server.bind();
                logger.info("NettyUdpRunner running");
                channel.closeFuture().sync();
            } catch (Exception e) {
                logger.error(e.getMessage());
                ;
            } finally {
                if (server != null) {
                    server.stop();
                }
            }
        });
    }


}

