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

import ch.qos.logback.classic.spi.LoggingEvent;
import com.alibaba.fastjson.JSONObject;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import org.nl.config.lucene.remote.RemoteLogServer;

/*
 * @author ZZQ
 * @Date 2024/1/22 10:24
 */
public class LogProviderHandler extends SimpleChannelInboundHandler<String> {

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

    @Override
    protected void channelRead0(ChannelHandlerContext ctx, String c){
        LoggingEvent event = JSONObject.parseObject(c, LoggingEvent.class);
        RemoteLogServer.asyncLuceneAppender.appendSync(event);
    }

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

}
