package com.its.dsrc.xnettcp.center.handler;

import io.netty.channel.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

@Slf4j
@Component
@ChannelHandler.Sharable
public class CenterTcpServerOutboundHandler extends ChannelOutboundHandlerAdapter {

    @Override
    public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) {
        promise.addListener(new ChannelFutureListener() {
            @Override
            public void operationComplete(ChannelFuture f) {
                if (!f.isSuccess()) {
//                    f.cause().printStackTrace();
                    log.error("CenterTcpServerOutboundHandler.write error: {}", f.cause().getMessage());
                    f.channel().close();
                }
            }
        });
    }
}
