如何使用ChannelDuplexHandler而不是SimpleChannelInboundHandler

时间:2018-01-04 08:56:12

标签: java netty

我曾经像SimpleChannelInboundHandler那样创建我的业务逻辑处理程序

@Override
public void channelRead0(final ChannelHandlerContext ctx,final RpcRequest request) throws Exception {
    logger.debug("receive request",request);
    Response response = new RpcResponse(request.getRequestId());
    try {
        Object result = Server.handleRequest(request);
        response.setResult(result);
    } catch (Throwable throwable) {
        response.setError(throwable);
        logger.error("",throwable);
    }
    ctx.writeAndFlush(response).addListener((ChannelFutureListener)
            channelFuture -> logger.debug("Send Response for Request " + request.getRequestId()));
}

现在我想使用ChannelDuplexHandler将write与channelRead分开,但我不知道怎么做,很难找到关于ChannelOutBoundHandler的例子

0 个答案:

没有答案