perf[exception]: format the exception log

This commit is contained in:
godotg committed 2023-01-06 22:29:52 +08:00
1 parent d0aa341c06
commit 5ef04e0b17
10 files changed
+85 -72

No files matched your search

@@ -32,7 +32,6 @@ import com.zfoo.protocol.ProtocolManager;
import com.zfoo.protocol.collection.CollectionUtils;
import com.zfoo.protocol.registration.ProtocolModule;
import com.zfoo.protocol.util.JsonUtils;
import com.zfoo.protocol.util.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -109,8 +108,7 @@ public class Consumer implements IConsumer {
throw new ErrorResponseException((Error) responsePacket);
}
if (answerClass != null && answerClass != responsePacket.getClass()) {
throw new UnexpectedProtocolException(StringUtils.format("client expect protocol:[{}], but found protocol:[{}]"
, answerClass, responsePacket.getClass().getName()));
throw new UnexpectedProtocolException("client expect protocol:[{}], but found protocol:[{}]", answerClass, responsePacket.getClass().getName());
}
var syncAnswer = new SyncAnswer<>((T) responsePacket, clientSignalAttachment);
@@ -118,8 +116,7 @@ public class Consumer implements IConsumer {
loadBalancer.afterLoadBalancer(session, packet, clientSignalAttachment);
return syncAnswer;
} catch (TimeoutException e) {
throw new NetTimeOutException(StringUtils.format("syncAsk timeout exception, ask:[{}], attachment:[{}]"
, JsonUtils.object2String(packet), JsonUtils.object2String(clientSignalAttachment)));
throw new NetTimeOutException("syncAsk timeout exception, ask:[{}], attachment:[{}]", JsonUtils.object2String(packet), JsonUtils.object2String(clientSignalAttachment));
} finally {
SignalBridge.removeSignalAttachment(clientSignalAttachment);
}
@@ -205,12 +205,12 @@ public class Router implements IRouter {
throw new ErrorResponseException((Error) responsePacket);
}
if (answerClass != null && answerClass != responsePacket.getClass()) {
throw new UnexpectedProtocolException(StringUtils.format("client expect protocol:[{}], but found protocol:[{}]", answerClass, responsePacket.getClass().getName()));
throw new UnexpectedProtocolException("client expect protocol:[{}], but found protocol:[{}]", answerClass, responsePacket.getClass().getName());
}
return new SyncAnswer<>((T) responsePacket, clientSignalAttachment);
} catch (TimeoutException e) {
throw new NetTimeOutException(StringUtils.format("syncAsk timeout exception, ask:[{}], attachment:[{}]", JsonUtils.object2String(packet), JsonUtils.object2String(clientSignalAttachment)));
throw new NetTimeOutException("syncAsk timeout exception, ask:[{}], attachment:[{}]", JsonUtils.object2String(packet), JsonUtils.object2String(clientSignalAttachment));
} finally {
SignalBridge.removeSignalAttachment(clientSignalAttachment);
}
@@ -240,7 +240,7 @@ public class Router implements IRouter {
// 因此超时的情况,返回的是null
.completeOnTimeout(null, DEFAULT_TIMEOUT, TimeUnit.MILLISECONDS).thenApply(answer -> {
if (answer == null) {
throw new NetTimeOutException(StringUtils.format("async ask [{}] timeout exception", packet.getClass().getSimpleName()));
throw new NetTimeOutException("async ask [{}] timeout exception", packet.getClass().getSimpleName());
}
if (answer.protocolId() == Error.errorProtocolId()) {
@@ -276,7 +276,7 @@ public class Router implements IRouter {
asyncAnswer.setFuturePacket((T) answer);
asyncAnswer.consume();
} catch (Throwable throwable1) {
logger.error("异步回调方法[ask:{}][answer:{}]错误", packet.getClass().getSimpleName(), answer.getClass().getSimpleName(), throwable1);
logger.error("Asynchronous callback method [ask:{}][answer:{}] error", packet.getClass().getSimpleName(), answer.getClass().getSimpleName(), throwable1);
} finally {
if (serverSignalAttachment != null) {
serverReceiveSignalAttachmentThreadLocal.set(null);
@@ -13,14 +13,16 @@
package com.zfoo.net.router.exception;
import com.zfoo.protocol.exception.RunException;
/**
* @author godotg
* @version 3.0
*/
public class NetTimeOutException extends RuntimeException {
public class NetTimeOutException extends RunException {
public NetTimeOutException(String s) {
super(s);
public NetTimeOutException(String template, Object... args) {
super(template, args);
}
}
}
@@ -21,23 +21,8 @@ import com.zfoo.protocol.exception.RunException;
*/
public class UnexpectedProtocolException extends RunException {
public UnexpectedProtocolException(Throwable cause) {
super(cause);
}
public UnexpectedProtocolException(String message) {
super(message);
}
public UnexpectedProtocolException(String template, Object... args) {
super(template, args);
}
public UnexpectedProtocolException(Throwable cause, String message) {
super(cause, message);
}
public UnexpectedProtocolException(Throwable cause, String template, Object... args) {
super(cause, template, args);
}
}
@@ -123,7 +123,7 @@ public abstract class PacketBus {
ReflectionUtils.makeAccessible(receiverField);
ReflectionUtils.setField(receiverField, protocolRegistration, enhanceReceiverDefinition);
} catch (Throwable t) {
throw new RunException(t, "Registration protocol [class:{}] unknown exception", packetClazz.getSimpleName());
throw new RunException("Registration protocol [class:{}] unknown exception", packetClazz.getSimpleName(), t);
}
}
}