use of pers.cy.iris.commons.network.protocol.HeaderType in project iris by chicc999.
the class DefaultDispatcherHandler method channelRead0.
@Override
protected void channelRead0(ChannelHandlerContext ctx, Command command) throws Exception {
if (command == null) {
return;
}
logger.debug("dispatcher command : {} {}", command.getHeader().getHeaderType().toString(), command.getHeader().getTypeString());
HeaderType headerType = command.getHeader().getHeaderType();
switch(headerType) {
case REQUEST:
{
// 如果是请求命令, 做请求处理
try {
processRequest(ctx, command);
} catch (Exception e) {
logger.error(e.getMessage(), e);
//如果请求需要响应
if (command.getHeader().getAcknowledge() != Acknowledge.ACK_NO) {
//写出响应,如果出现异常则调用exceptionCaught打印异常关闭连接
ctx.writeAndFlush(new ErrorResponse(-1, e.toString(), command.getRequestId())).addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE);
}
}
break;
}
case RESPONSE:
{
// 如果是响应命令, 做响应处理
processResponse(ctx, command);
break;
}
}
}
Aggregations