@Override void handleFailure(String errorMsg, Throwable cause) throws Exception { callback.onFailure(streamId, new IOException(errorMsg, cause)); } };
@Override void handleFailure(String errorMsg, Throwable cause) throws Exception { callback.onFailure(streamId, new IOException(errorMsg, cause)); } };
@Override public void channelInactive() throws Exception { deactivateStream(); callback.onFailure(streamId, new ClosedChannelException()); }
@Override public void exceptionCaught(Throwable cause) throws Exception { deactivateStream(); callback.onFailure(streamId, cause); }
@Override public void channelInactive() throws Exception { deactivateStream(); callback.onFailure(streamId, new ClosedChannelException()); }
@Override public void exceptionCaught(Throwable cause) throws Exception { handler.deactivateStream(); callback.onFailure(streamId, cause); }
@Override public void channelInactive() throws Exception { handler.deactivateStream(); callback.onFailure(streamId, new ClosedChannelException()); }
@Override public void channelInactive() throws Exception { handler.deactivateStream(); callback.onFailure(streamId, new ClosedChannelException()); }
@Override public void exceptionCaught(Throwable cause) throws Exception { deactivateStream(); callback.onFailure(streamId, cause); }
@Override public void exceptionCaught(Throwable cause) throws Exception { handler.deactivateStream(); callback.onFailure(streamId, cause); }
@Override public void operationComplete(ChannelFuture future) throws Exception { if (future.isSuccess()) { if (isTraceEnabled) { long timeTaken = System.currentTimeMillis() - startTime; logger.trace("Sending request for {} to {} took {} ms", streamId, getRemoteAddress(channel), timeTaken); } } else { String errorMsg = String.format("Failed to send request for %s to %s: %s", streamId, getRemoteAddress(channel), future.cause()); logger.error(errorMsg, future.cause()); channel.close(); try { callback.onFailure(streamId, new IOException(errorMsg, future.cause())); } catch (Exception e) { logger.error("Uncaught exception in RPC response callback handler!", e); } } } });
entry.getValue().onFailure(entry.getKey(), cause); } catch (Exception e) { logger.warn("StreamCallback.onFailure throws exception", e);
@Override public boolean handle(ByteBuf buf) throws Exception { int toRead = (int) Math.min(buf.readableBytes(), byteCount - bytesRead); ByteBuffer nioBuffer = buf.readSlice(toRead).nioBuffer(); int available = nioBuffer.remaining(); callback.onData(streamId, nioBuffer); bytesRead += available; if (bytesRead > byteCount) { RuntimeException re = new IllegalStateException(String.format( "Read too many bytes? Expected %d, but read %d.", byteCount, bytesRead)); callback.onFailure(streamId, re); deactivateStream(); throw re; } else if (bytesRead == byteCount) { deactivateStream(); callback.onComplete(streamId); } return bytesRead != byteCount; }
@Override public boolean handle(ByteBuf buf) throws Exception { int toRead = (int) Math.min(buf.readableBytes(), byteCount - bytesRead); ByteBuffer nioBuffer = buf.readSlice(toRead).nioBuffer(); int available = nioBuffer.remaining(); callback.onData(streamId, nioBuffer); bytesRead += available; if (bytesRead > byteCount) { RuntimeException re = new IllegalStateException(String.format( "Read too many bytes? Expected %d, but read %d.", byteCount, bytesRead)); callback.onFailure(streamId, re); handler.deactivateStream(); throw re; } else if (bytesRead == byteCount) { handler.deactivateStream(); callback.onComplete(streamId); } return bytesRead != byteCount; }
@Override public boolean handle(ByteBuf buf) throws Exception { int toRead = (int) Math.min(buf.readableBytes(), byteCount - bytesRead); ByteBuffer nioBuffer = buf.readSlice(toRead).nioBuffer(); int available = nioBuffer.remaining(); callback.onData(streamId, nioBuffer); bytesRead += available; if (bytesRead > byteCount) { RuntimeException re = new IllegalStateException(String.format( "Read too many bytes? Expected %d, but read %d.", byteCount, bytesRead)); callback.onFailure(streamId, re); deactivateStream(); throw re; } else if (bytesRead == byteCount) { deactivateStream(); callback.onComplete(streamId); } return bytesRead != byteCount; }
@Override public boolean handle(ByteBuf buf) throws Exception { int toRead = (int) Math.min(buf.readableBytes(), byteCount - bytesRead); ByteBuffer nioBuffer = buf.readSlice(toRead).nioBuffer(); int available = nioBuffer.remaining(); callback.onData(streamId, nioBuffer); bytesRead += available; if (bytesRead > byteCount) { RuntimeException re = new IllegalStateException(String.format( "Read too many bytes? Expected %d, but read %d.", byteCount, bytesRead)); callback.onFailure(streamId, re); handler.deactivateStream(); throw re; } else if (bytesRead == byteCount) { handler.deactivateStream(); callback.onComplete(streamId); } return bytesRead != byteCount; }
@Test public void failOutstandingStreamCallbackOnException() throws Exception { Channel c = new LocalChannel(); c.pipeline().addLast(TransportFrameDecoder.HANDLER_NAME, new TransportFrameDecoder()); TransportResponseHandler handler = new TransportResponseHandler(c); StreamCallback cb = mock(StreamCallback.class); handler.addStreamCallback("stream-1", cb); handler.exceptionCaught(new IOException("Oops!")); verify(cb).onFailure(eq("stream-1"), isA(IOException.class)); } }
@Test public void failOutstandingStreamCallbackOnException() throws Exception { Channel c = new LocalChannel(); c.pipeline().addLast(TransportFrameDecoder.HANDLER_NAME, new TransportFrameDecoder()); TransportResponseHandler handler = new TransportResponseHandler(c); StreamCallback cb = mock(StreamCallback.class); handler.addStreamCallback("stream-1", cb); handler.exceptionCaught(new IOException("Oops!")); verify(cb).onFailure(eq("stream-1"), isA(IOException.class)); } }
@Test public void failOutstandingStreamCallbackOnClose() throws Exception { Channel c = new LocalChannel(); c.pipeline().addLast(TransportFrameDecoder.HANDLER_NAME, new TransportFrameDecoder()); TransportResponseHandler handler = new TransportResponseHandler(c); StreamCallback cb = mock(StreamCallback.class); handler.addStreamCallback("stream-1", cb); handler.channelInactive(); verify(cb).onFailure(eq("stream-1"), isA(IOException.class)); }
@Test public void failOutstandingStreamCallbackOnClose() throws Exception { Channel c = new LocalChannel(); c.pipeline().addLast(TransportFrameDecoder.HANDLER_NAME, new TransportFrameDecoder()); TransportResponseHandler handler = new TransportResponseHandler(c); StreamCallback cb = mock(StreamCallback.class); handler.addStreamCallback("stream-1", cb); handler.channelInactive(); verify(cb).onFailure(eq("stream-1"), isA(IOException.class)); }