@Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { try { callback.onFailure(cause); } catch (Throwable t) { LOG.error("Failed to notify callback about failure", t); } }
@Override public void channelInactive(ChannelHandlerContext ctx) throws Exception { // Only the client is expected to close the channel. Otherwise it // indicates a failure. Note that this will be invoked in both cases // though. If the callback closed the channel, the callback must be // ignored. try { callback.onFailure(new ClosedChannelException()); } catch (Throwable t) { LOG.error("Failed to notify callback about failure", t); } } }
@Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { try { ByteBuf buf = (ByteBuf) msg; MessageType msgType = MessageSerializer.deserializeHeader(buf); if (msgType == MessageType.REQUEST_RESULT) { long requestId = MessageSerializer.getRequestId(buf); RESP result = serializer.deserializeResponse(buf); callback.onRequestResult(requestId, result); } else if (msgType == MessageType.REQUEST_FAILURE) { RequestFailure failure = MessageSerializer.deserializeRequestFailure(buf); callback.onRequestFailure(failure.getRequestId(), failure.getCause()); } else if (msgType == MessageType.SERVER_FAILURE) { throw MessageSerializer.deserializeServerFailure(buf); } else { throw new IllegalStateException("Unexpected response type '" + msgType + "'"); } } catch (Throwable t1) { try { callback.onFailure(t1); } catch (Throwable t2) { LOG.error("Failed to notify callback about failure", t2); } } finally { ReferenceCountUtil.release(msg); } }
verify(callback, times(1)).onFailure(isA(RuntimeException.class)); verify(callback, times(1)).onFailure(isA(IllegalStateException.class)); assertEquals("Buffer not recycled", 0, buf.refCnt()); verify(callback, times(3)).onFailure(isA(RuntimeException.class)); verify(callback, times(1)).onFailure(isA(ClosedChannelException.class));
@Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { try { callback.onFailure(cause); } catch (Throwable t) { LOG.error("Failed to notify callback about failure", t); } }
@Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { try { callback.onFailure(cause); } catch (Throwable t) { LOG.error("Failed to notify callback about failure", t); } }
@Override public void channelInactive(ChannelHandlerContext ctx) throws Exception { // Only the client is expected to close the channel. Otherwise it // indicates a failure. Note that this will be invoked in both cases // though. If the callback closed the channel, the callback must be // ignored. try { callback.onFailure(new ClosedChannelException()); } catch (Throwable t) { LOG.error("Failed to notify callback about failure", t); } } }
@Override public void channelInactive(ChannelHandlerContext ctx) throws Exception { // Only the client is expected to close the channel. Otherwise it // indicates a failure. Note that this will be invoked in both cases // though. If the callback closed the channel, the callback must be // ignored. try { callback.onFailure(new ClosedChannelException()); } catch (Throwable t) { LOG.error("Failed to notify callback about failure", t); } } }
@Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { try { ByteBuf buf = (ByteBuf) msg; MessageType msgType = MessageSerializer.deserializeHeader(buf); if (msgType == MessageType.REQUEST_RESULT) { long requestId = MessageSerializer.getRequestId(buf); RESP result = serializer.deserializeResponse(buf); callback.onRequestResult(requestId, result); } else if (msgType == MessageType.REQUEST_FAILURE) { RequestFailure failure = MessageSerializer.deserializeRequestFailure(buf); callback.onRequestFailure(failure.getRequestId(), failure.getCause()); } else if (msgType == MessageType.SERVER_FAILURE) { throw MessageSerializer.deserializeServerFailure(buf); } else { throw new IllegalStateException("Unexpected response type '" + msgType + "'"); } } catch (Throwable t1) { try { callback.onFailure(t1); } catch (Throwable t2) { LOG.error("Failed to notify callback about failure", t2); } } finally { ReferenceCountUtil.release(msg); } }
@Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { try { ByteBuf buf = (ByteBuf) msg; MessageType msgType = MessageSerializer.deserializeHeader(buf); if (msgType == MessageType.REQUEST_RESULT) { long requestId = MessageSerializer.getRequestId(buf); RESP result = serializer.deserializeResponse(buf); callback.onRequestResult(requestId, result); } else if (msgType == MessageType.REQUEST_FAILURE) { RequestFailure failure = MessageSerializer.deserializeRequestFailure(buf); callback.onRequestFailure(failure.getRequestId(), failure.getCause()); } else if (msgType == MessageType.SERVER_FAILURE) { throw MessageSerializer.deserializeServerFailure(buf); } else { throw new IllegalStateException("Unexpected response type '" + msgType + "'"); } } catch (Throwable t1) { try { callback.onFailure(t1); } catch (Throwable t2) { LOG.error("Failed to notify callback about failure", t2); } } finally { ReferenceCountUtil.release(msg); } }