
jizcode.netty.client.RtClientHandler Maven / Gradle / Ivy
package jizcode.netty.client;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import jizcode.base.util.JsonUtils;
import jizcode.netty.contract.RtDataFromServer;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
public class RtClientHandler extends ChannelInboundHandlerAdapter {
protected Log logger = LogFactory.getLog(this.getClass());
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
try {
RtDataFromServer data = JsonUtils.fromJson((String)msg,RtDataFromServer.class);
//logger.info("收到服务端的数据uniqueId:"+data.getUniqueId());
RtClient.getInstance().getResolveCallback().apply(data);
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
// client disconnect
//logger.info("断开连接");
RtClient.getInstance().reconnect();
ctx.fireChannelInactive();
}
@Override
public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
////logger.info("通道读取完毕!");
}
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
if(null != cause) cause.printStackTrace();
if(null != ctx) ctx.close();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy