@Override public void handleUpstream(ChannelHandlerContext ctx, ChannelEvent ce) throws Exception { if (!(ce instanceof MessageEvent)) { ctx.sendUpstream(ce); return; } MessageEvent e = (MessageEvent) ce; RedisConnection conn = (RedisConnection) e.getChannel().getAttachment(); ChannelBuffer cb = (ChannelBuffer) e.getMessage(); conn.replyFromBackend(cb.copy()); ctx.sendUpstream(ce); }
@Override public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception { e.getCause().printStackTrace(System.err); RedisConnection conn = (RedisConnection) ctx.getChannel().getAttachment(); conn.releaseBroken(); /* * ChannelFuture future = ctx.getChannel().disconnect(); * future.addListener(new ChannelFutureListener() { * * @Override public void operationComplete(ChannelFuture cf) throws * Exception { RedisConnection conn = * (RedisConnection)cf.getChannel().getAttachment(); * conn.releaseBroken(); } }); */ }
@Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { RedisConnection conn = (RedisConnection) e.getChannel().getAttachment(); conn.release(); }