@Override public void onComplete(String streamId) throws IOException { try { streamHandler.onComplete(streamId); callback.onSuccess(ByteBuffer.allocate(0)); } catch (Exception ex) { IOException ioExc = new IOException("Failure post-processing complete stream;" + " failing this rpc and leaving channel active", ex); callback.onFailure(ioExc); streamHandler.onFailure(streamId, ioExc); } }
@Override public void receive(TransportClient client, ByteBuffer message, RpcResponseCallback callback) { callback.onSuccess(message); }
@Override public void onFailure(String streamId, Throwable cause) throws IOException { callback.onFailure(new IOException("Destination failed while reading stream", cause)); streamHandler.onFailure(streamId, cause); }
@Override public void receive(TransportClient client, ByteBuffer message, RpcResponseCallback callback) { callback.onSuccess(message); }
@Override void handleFailure(String errorMsg, Throwable cause) { handler.removeRpcRequest(rpcRequestId); callback.onFailure(new IOException(errorMsg, cause)); } }
@Override public void onComplete(String streamId) throws IOException { try { streamHandler.onComplete(streamId); callback.onSuccess(ByteBuffer.allocate(0)); } catch (Exception ex) { IOException ioExc = new IOException("Failure post-processing complete stream;" + " failing this rpc and leaving channel active", ex); callback.onFailure(ioExc); streamHandler.onFailure(streamId, ioExc); } }
@Override public void receive(TransportClient client, ByteBuffer message, RpcResponseCallback callback) { callback.onSuccess(message); }
@Override public void onFailure(String streamId, Throwable cause) throws IOException { callback.onFailure(new IOException("Destination failed while reading stream", cause)); streamHandler.onFailure(streamId, cause); }
@Override public void receive( TransportClient client, ByteBuffer message, RpcResponseCallback callback) { String msg = JavaUtils.bytesToString(message); String[] parts = msg.split("/"); if (parts[0].equals("hello")) { callback.onSuccess(JavaUtils.stringToBytes("Hello, " + parts[1] + "!")); } else if (parts[0].equals("return error")) { callback.onFailure(new RuntimeException("Returned: " + parts[1])); } else if (parts[0].equals("throw error")) { throw new RuntimeException("Thrown: " + parts[1]); } }
@Override public void receive( TransportClient client, ByteBuffer message, RpcResponseCallback callback) { try { semaphore.acquire(); callback.onSuccess(ByteBuffer.allocate(responseSize)); } catch (InterruptedException e) { // do nothing } }
@Override void handleFailure(String errorMsg, Throwable cause) { handler.removeRpcRequest(rpcRequestId); callback.onFailure(new IOException(errorMsg, cause)); } }
@Override public void receive( TransportClient client, ByteBuffer message, RpcResponseCallback callback) { String msg = JavaUtils.bytesToString(message); String[] parts = msg.split("/"); if (parts[0].equals("hello")) { callback.onSuccess(JavaUtils.stringToBytes("Hello, " + parts[1] + "!")); } else if (parts[0].equals("return error")) { callback.onFailure(new RuntimeException("Returned: " + parts[1])); } else if (parts[0].equals("throw error")) { throw new RuntimeException("Thrown: " + parts[1]); } }
@Override public void receive( TransportClient client, ByteBuffer message, RpcResponseCallback callback) { try { semaphore.acquire(); callback.onSuccess(ByteBuffer.allocate(responseSize)); } catch (InterruptedException e) { // do nothing } }
/** * Fire the failure callback for all outstanding requests. This is called when we have an * uncaught exception or pre-mature connection termination. */ private void failOutstandingRequests(Throwable cause) { for (Map.Entry<StreamChunkId, ChunkReceivedCallback> entry : outstandingFetches.entrySet()) { entry.getValue().onFailure(entry.getKey().chunkIndex, cause); } for (Map.Entry<Long, RpcResponseCallback> entry : outstandingRpcs.entrySet()) { entry.getValue().onFailure(cause); } // It's OK if new fetches appear, as they will fail immediately. outstandingFetches.clear(); outstandingRpcs.clear(); }
LOG.debug("Unexpected challenge message from client {}, closing channel.", channel.remoteAddress()); callback.onFailure(new IllegalArgumentException("Unknown challenge message.")); channel.close(); ByteBuf responseData = Unpooled.buffer(response.encodedLength()); response.encode(responseData); callback.onSuccess(responseData.nioBuffer()); engine.sessionCipher().addToChannel(channel); } catch (Exception e) { callback.onFailure(new IllegalArgumentException("Authentication failed.")); channel.close(); return;
@Override public void receive( TransportClient client, ByteBuffer message, RpcResponseCallback callback) { try { semaphore.acquire(); callback.onSuccess(ByteBuffer.allocate(responseSize)); } catch (InterruptedException e) { // do nothing } }
entry.getValue().onFailure(cause); } catch (Exception e) { logger.warn("RpcResponseCallback.onFailure throws exception", e);
LOG.debug("Unexpected challenge message from client {}, closing channel.", channel.remoteAddress()); callback.onFailure(new IllegalArgumentException("Unknown challenge message.")); channel.close(); ByteBuf responseData = Unpooled.buffer(response.encodedLength()); response.encode(responseData); callback.onSuccess(responseData.nioBuffer()); engine.sessionCipher().addToChannel(channel); } catch (Exception e) { callback.onFailure(new IllegalArgumentException("Authentication failed.")); channel.close(); return;
@Override public void receive( TransportClient client, ByteBuffer message, RpcResponseCallback callback) { try { semaphore.acquire(); callback.onSuccess(ByteBuffer.allocate(responseSize)); } catch (InterruptedException e) { // do nothing } }
@Override public void operationComplete(ChannelFuture future) throws Exception { if (future.isSuccess()) { if (isTraceEnabled) { long timeTaken = System.currentTimeMillis() - startTime; logger.trace("Sending request {} to {} took {} ms", requestId, getRemoteAddress(channel), timeTaken); } } else { String errorMsg = String.format("Failed to send RPC %s to %s: %s", requestId, getRemoteAddress(channel), future.cause()); logger.error(errorMsg, future.cause()); handler.removeRpcRequest(requestId); channel.close(); try { callback.onFailure(new IOException(errorMsg, future.cause())); } catch (Exception e) { logger.error("Uncaught exception in RPC response callback handler!", e); } } } });