mirror of
https://gitee.com/farsunset/cim.git
synced 2025-07-25 01:01:47 +08:00
服务端sdk日志优化
This commit is contained in:
parent
16d5738451
commit
8f9d420ba2
Binary file not shown.
@ -23,6 +23,7 @@ package com.farsunset.cim.coder.protobuf;
|
|||||||
|
|
||||||
import com.farsunset.cim.constant.CIMConstant;
|
import com.farsunset.cim.constant.CIMConstant;
|
||||||
import com.farsunset.cim.constant.ChannelAttr;
|
import com.farsunset.cim.constant.ChannelAttr;
|
||||||
|
import com.farsunset.cim.exception.ReadInvalidTypeException;
|
||||||
import com.farsunset.cim.model.Pong;
|
import com.farsunset.cim.model.Pong;
|
||||||
import com.farsunset.cim.model.SentBody;
|
import com.farsunset.cim.model.SentBody;
|
||||||
import com.farsunset.cim.model.proto.SentBodyProto;
|
import com.farsunset.cim.model.proto.SentBodyProto;
|
||||||
@ -65,28 +66,33 @@ public class AppMessageDecoder extends ByteToMessageDecoder {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
byte[] dataBytes = new byte[length];
|
byte[] content = new byte[length];
|
||||||
buffer.readBytes(dataBytes);
|
|
||||||
|
|
||||||
|
buffer.readBytes(content);
|
||||||
|
|
||||||
Object message = mappingMessageObject(dataBytes, type);
|
Object message = mappingMessageObject(content, type);
|
||||||
|
|
||||||
queue.add(message);
|
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) {
|
if (CIMConstant.DATA_TYPE_PONG == type) {
|
||||||
return Pong.getInstance();
|
return Pong.getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
SentBodyProto.Model bodyProto = SentBodyProto.Model.parseFrom(data);
|
if (CIMConstant.DATA_TYPE_SENT == type) {
|
||||||
SentBody body = new SentBody();
|
|
||||||
body.setData(bodyProto.getDataMap());
|
|
||||||
body.setKey(bodyProto.getKey());
|
|
||||||
body.setTimestamp(bodyProto.getTimestamp());
|
|
||||||
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
@ -102,7 +102,10 @@ public class LoggingHandler extends io.netty.handler.logging.LoggingHandler {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
|
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){
|
private void setThreadName(ChannelHandlerContext context){
|
||||||
|
Loading…
x
Reference in New Issue
Block a user