package cn.com.ty.lift.ud.neety.server;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

import cn.com.ty.lift.ud.chat.mapper.entity.ChatSessionEntity;
import org.springframework.beans.factory.annotation.Value;

import lombok.Data;
import lombok.extern.slf4j.Slf4j;

import java.util.*;

/**
 * @Author: chenyi
 * @Email: 228112142@qq.com
 * @Description: netty随项目启动
 */
@Data
@Slf4j
@WebListener
public class NettyListener implements ServletContextListener {

    /** 服务端口 */
    @Value("${netty.port}")
    private Integer port;

    /** 服务端新心跳检测时间 */
    @Value("${netty.readerIdleTime}")
    private Integer readerIdleTime;

    @Override
    public void contextInitialized(ServletContextEvent sce) {
        log.info("##--------------------->websocket starting!");
        new Thread() {
            @Override
            public void run() {
                try {
                    new ChatServer().start(port, readerIdleTime);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }.start();
        log.info("##--------------------->websocket started!");
    }

    @Override
    public void contextDestroyed(ServletContextEvent sce) {
        log.info("shut Dow.");
    }
}