Search in sources :

Example 1 with HeaderType

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;
            }
    }
}
Also used : HeaderType(pers.cy.iris.commons.network.protocol.HeaderType) UnknowCommandException(pers.cy.iris.commons.exception.UnknowCommandException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) ServiceTooBusyException(pers.cy.iris.commons.exception.ServiceTooBusyException) ErrorResponse(pers.cy.iris.commons.network.protocol.response.ErrorResponse)

Aggregations

RejectedExecutionException (java.util.concurrent.RejectedExecutionException)1 ServiceTooBusyException (pers.cy.iris.commons.exception.ServiceTooBusyException)1 UnknowCommandException (pers.cy.iris.commons.exception.UnknowCommandException)1 HeaderType (pers.cy.iris.commons.network.protocol.HeaderType)1 ErrorResponse (pers.cy.iris.commons.network.protocol.response.ErrorResponse)1