use of io.transport.core.protocol.message.internal.ResultRespMessage.RetCode in project transporter by wang4ever.
the class TransportMessageHandler method channelRead.
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
if (logger.isDebugEnabled())
logger.debug("Read消息: {}", JSON.toJSONString(msg));
// 1.1 转发给具体业务方法
if (msg == null)
logger.warn("On channelRead(msg) is 'msg' null.");
else {
SubmitTaskExecutors.getLimitExecutor().submit(() -> {
// 结果码
RetCode retCode = RetCode.OK;
// 处理消息类型
String type = null;
// 异常信息
String err = null;
try {
this.dispatch(ctx, msg);
} catch (Exception e) {
err = ExceptionUtils.getRootCauseMessage(e).split("\\:")[1];
// 1.1 认证异常.
if (e instanceof TransportAuthenticationException) {
// 认证失败消息
retCode = RetCode.AUTH_FAIL;
type = String.valueOf(MsgType.CONNECT_IN.getActionId());
logger.warn("认证失败: {}", err);
} else {
// 系统异常结果码
retCode = RetCode.SYS_ERR;
logger.error("处理失败.{}", err);
}
} finally {
// 1.3 Echo系统错误消息
ChannelFuture cf = this.echoWrite(ctx, new ResultRespMessage(retCode, type, err));
if (retCode == RetCode.AUTH_FAIL) {
// 认证失败则关闭通道
cf.addListener((ChannelFuture f) -> {
if (f.isSuccess())
// 返回消息完成后再关闭通道
super.closeClient();
});
}
}
});
}
}
Aggregations