package org.nl.config.lucene.remote.coder;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.handler.timeout.IdleStateEvent;
import org.nl.config.lucene.remote.RemoteLogServer;

/*
 * @author ZZQ
 * @Date 2024/1/22 10:24
 */
public class LogConsumerHandler extends ChannelInboundHandlerAdapter {

    @Override
    public void channelInactive(ChannelHandlerContext ctx) throws Exception {
        System.out.println("断开连接---");
        RemoteLogServer.LOCAL_LOG = Boolean.TRUE;
        RemoteLogServer.server.doDestroy();
        //重新建立
        super.channelInactive(ctx);
    }

    @Override
    public void channelActive(ChannelHandlerContext ctx) throws Exception {
        System.out.println("连接");
        super.channelActive(ctx);
    }


    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
        System.out.println("接收到消息");
        super.channelRead(ctx, msg);
    }

    @Override
    public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
        if (evt instanceof IdleStateEvent){
            IdleStateEvent stateEvent = (IdleStateEvent) evt;
            System.out.println(stateEvent.state());
        }
        super.userEventTriggered(ctx, evt);
    }
}
