@Override public void onNext(Object value) { if (value instanceof Throwable) { callback.handleError((Throwable) value); } else { callback.handleResult((T) value); } }
@Override public void handleError(Throwable error) { callback.handleError(error); } }
/** * Sets the RPC response, and unblocks all threads waiting on {@link #get()} * or {@link #get(long, TimeUnit)}. * @param result the RPC result to set. */ @Override public void handleResult(T result) { this.result = result; latch.countDown(); if (chainedCallback != null) { chainedCallback.handleResult(result); } }
@Override public void onError(Throwable t) { callback.handleError(new AvroRuntimeException(t)); }
@Override public void messageReceived(ChannelHandlerContext ctx, final MessageEvent e) { NettyDataPack dataPack = (NettyDataPack)e.getMessage(); Callback<List<ByteBuffer>> callback = requests.get(dataPack.getSerial()); if (callback==null) { throw new RuntimeException("Missing previous call info"); } try { callback.handleResult(dataPack.getDatas()); } finally { requests.remove(dataPack.getSerial()); } }
/** * Called by {@link Requestor#request(String,Object,Callback)} for two-way messages using callbacks. */ public void transceive(List<ByteBuffer> request, Callback<List<ByteBuffer>> callback) throws IOException { // The default implementation works synchronously try { List<ByteBuffer> response = transceive(request); callback.handleResult(response); } catch (IOException e) { callback.handleError(e); } }
/** * Sets an error thrown during RPC execution, and unblocks all threads waiting * on {@link #get()} or {@link #get(long, TimeUnit)}. * @param error the RPC error to set. */ @Override public void handleError(Throwable error) { this.error = error; latch.countDown(); if (chainedCallback != null) { chainedCallback.handleError(error); } }
t.writeBuffers(request.getBytes()); if (callback != null) { callback.handleResult(null);
} catch (Exception e) { if (callback != null) { callback.handleError(e); callback.handleResult((T)responseObject);
@Override public void operationComplete(ChannelFuture future) throws Exception { if (!future.isSuccess() && (callback != null)) { callback.handleError( new IOException("Error writing buffers", future.getCause())); } } }
/** * Sets the RPC response, and unblocks all threads waiting on {@link #get()} * or {@link #get(long, TimeUnit)}. * @param result the RPC result to set. */ @Override public void handleResult(T result) { this.result = result; latch.countDown(); if (chainedCallback != null) { chainedCallback.handleResult(result); } }
/** * Called by {@link Requestor#request(String,Object,Callback)} for two-way messages using callbacks. */ public void transceive(List<ByteBuffer> request, Callback<List<ByteBuffer>> callback) throws IOException { // The default implementation works synchronously try { List<ByteBuffer> response = transceive(request); callback.handleResult(response); } catch (IOException e) { callback.handleError(e); } }
LOG.debug("Removing " + requestsToCancel.size() + " pending request(s)."); for (Callback<List<ByteBuffer>> request : requestsToCancel.values()) { request.handleError( cause != null ? cause : new IOException(getClass().getSimpleName() + " closed"));
@Override public void messageReceived(ChannelHandlerContext ctx, final MessageEvent e) { NettyDataPack dataPack = (NettyDataPack)e.getMessage(); Callback<List<ByteBuffer>> callback = requests.get(dataPack.getSerial()); if (callback==null) { throw new RuntimeException("Missing previous call info"); } try { callback.handleResult(dataPack.getDatas()); } finally { requests.remove(dataPack.getSerial()); } }
} catch (Exception e) { if (callback != null) { callback.handleError(e); callback.handleResult((T)responseObject);
@Override public void handleError(Throwable error) { callback.handleError(error); } }
t.writeBuffers(request.getBytes()); if (callback != null) { callback.handleResult(null);
/** * Sets an error thrown during RPC execution, and unblocks all threads waiting * on {@link #get()} or {@link #get(long, TimeUnit)}. * @param error the RPC error to set. */ @Override public void handleError(Throwable error) { this.error = error; latch.countDown(); if (chainedCallback != null) { chainedCallback.handleError(error); } }
@Override public void operationComplete(ChannelFuture future) throws Exception { if (!future.isSuccess() && (callback != null)) { callback.handleError( new IOException("Error writing buffers", future.getCause())); } } }
LOG.debug("Removing " + requestsToCancel.size() + " pending request(s)."); for (Callback<List<ByteBuffer>> request : requestsToCancel.values()) { request.handleError( cause != null ? cause : new IOException(getClass().getSimpleName() + " closed"));