package com.cm.central.control.trigger;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.handler.timeout.IdleState;
import io.netty.handler.timeout.IdleStateEvent;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

/**
 * When you feel like quitting. Think about why you started
 * 当你想要放弃的时候，想想当初你为何开始
 *
 * @ClassName: MessageServerIdleStateTrigger
 * @Description: 消息服务器断链触发器
 * @Author: WangGeng
 * @Date: 2020/7/5 11:08 上午
 * @Version: 1.0
 **/
public class SocketServerIdleStateTrigger extends ChannelInboundHandlerAdapter {

    @Override
    public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
        if (evt instanceof IdleStateEvent) {
            IdleState idleState = ((IdleStateEvent) evt).state();
            if (idleState == IdleState.READER_IDLE) {
                ctx.close();
            }
            return;
        }
        super.userEventTriggered(ctx, evt);
    }
}
