...
|
...
|
@@ -6,6 +6,7 @@ import com.monitor.nginxsync.nio.service.LogService; |
|
|
import io.netty.buffer.ByteBuf;
|
|
|
import io.netty.channel.ChannelHandlerContext;
|
|
|
import io.netty.channel.SimpleChannelInboundHandler;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
...
|
...
|
@@ -21,23 +22,14 @@ public class LogMsgHandler extends SimpleChannelInboundHandler { |
|
|
@Override
|
|
|
protected void channelRead0(ChannelHandlerContext channelHandlerContext, Object msg) throws Exception {
|
|
|
|
|
|
ByteBuf result = (ByteBuf) msg;
|
|
|
String recvMsg = StringUtils.trim((String) msg);
|
|
|
|
|
|
byte[] resultWarp = new byte[result.readableBytes()];
|
|
|
DEBUG.info("recv log msg {}", recvMsg);
|
|
|
|
|
|
// msg中存储的是ByteBuf类型的数据,把数据读取到byte[]中
|
|
|
result.readBytes(resultWarp);
|
|
|
|
|
|
|
|
|
DEBUG.info("recv log msg {}", new String(resultWarp));
|
|
|
|
|
|
LogMsg logMsg = Constants.OBJECT_MAPPER.readValue(resultWarp, LogMsg.class);
|
|
|
LogMsg logMsg = Constants.OBJECT_MAPPER.readValue(recvMsg, LogMsg.class);
|
|
|
|
|
|
// 插入日志管理
|
|
|
LOG_SERVICE.inLogMsg(logMsg);
|
|
|
|
|
|
// 释放资源,这行很关键
|
|
|
result.release();
|
|
|
}
|
|
|
|
|
|
@Override
|
...
|
...
|
|