服务端sdk日志优化

This commit is contained in:
远方夕阳 2022-04-14 17:13:45 +08:00
parent 16d5738451
commit 8f9d420ba2
4 changed files with 49 additions and 11 deletions

View File

@ -23,6 +23,7 @@ package com.farsunset.cim.coder.protobuf;
import com.farsunset.cim.constant.CIMConstant;
import com.farsunset.cim.constant.ChannelAttr;
import com.farsunset.cim.exception.ReadInvalidTypeException;
import com.farsunset.cim.model.Pong;
import com.farsunset.cim.model.SentBody;
import com.farsunset.cim.model.proto.SentBodyProto;
@ -65,28 +66,33 @@ public class AppMessageDecoder extends ByteToMessageDecoder {
return;
}
byte[] dataBytes = new byte[length];
buffer.readBytes(dataBytes);
byte[] content = new byte[length];
buffer.readBytes(content);
Object message = mappingMessageObject(dataBytes, type);
Object message = mappingMessageObject(content, type);
queue.add(message);
}
public Object mappingMessageObject(byte[] data, byte type) throws com.google.protobuf.InvalidProtocolBufferException {
private Object mappingMessageObject(byte[] data, byte type) throws com.google.protobuf.InvalidProtocolBufferException {
if (CIMConstant.DATA_TYPE_PONG == type) {
return Pong.getInstance();
}
SentBodyProto.Model bodyProto = SentBodyProto.Model.parseFrom(data);
SentBody body = new SentBody();
body.setData(bodyProto.getDataMap());
body.setKey(bodyProto.getKey());
body.setTimestamp(bodyProto.getTimestamp());
if (CIMConstant.DATA_TYPE_SENT == type) {
return body;
SentBodyProto.Model bodyProto = SentBodyProto.Model.parseFrom(data);
SentBody body = new SentBody();
body.setData(bodyProto.getDataMap());
body.setKey(bodyProto.getKey());
body.setTimestamp(bodyProto.getTimestamp());
return body;
}
throw new ReadInvalidTypeException(type);
}
/**

View File

@ -0,0 +1,29 @@
/*
* Copyright 2013-2019 Xia Jun(3979434@qq.com).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
***************************************************************************************
* *
* Website : http://www.farsunset.com *
* *
***************************************************************************************
*/
package com.farsunset.cim.exception;
public class ReadInvalidTypeException extends RuntimeException{
public ReadInvalidTypeException(byte type) {
super("Read invalid tag : " + type);
}
}

View File

@ -102,7 +102,10 @@ public class LoggingHandler extends io.netty.handler.logging.LoggingHandler {
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
logger.warn("EXCEPTION",cause);
String name = Thread.currentThread().getName();
setThreadName(ctx);
logger.warn(this.format(ctx, "EXCEPTION", cause), cause);
Thread.currentThread().setName(name);
}
private void setThreadName(ChannelHandlerContext context){