@Override // TODO: Very like the super class implemenation. Can we shrink this down? protected Result rpcCall() throws Exception { if (getRpcController().isCanceled()) return null; if (Thread.interrupted()) { throw new InterruptedIOException(); } byte[] reg = location.getRegionInfo().getRegionName(); ClientProtos.GetRequest request = RequestConverter.buildGetRequest(reg, get); HBaseRpcController hrc = (HBaseRpcController)getRpcController(); hrc.reset(); hrc.setCallTimeout(rpcTimeout); hrc.setPriority(tableName); ClientProtos.GetResponse response = getStub().get(hrc, request); if (response == null) { return null; } return ProtobufUtil.toResult(response.getResult(), hrc.cellScanner()); } }
@Override public void setCellScanner(CellScanner cellScanner) { delegate.setCellScanner(cellScanner); }
static void resetController(HBaseRpcController controller, long timeoutNs) { controller.reset(); if (timeoutNs >= 0) { controller.setCallTimeout( (int) Math.min(Integer.MAX_VALUE, TimeUnit.NANOSECONDS.toMillis(timeoutNs))); } }
/** * Configure an hbase rpccontroller * @param controller to configure * @param channelOperationTimeout timeout for operation * @return configured controller */ static HBaseRpcController configureHBaseRpcController( RpcController controller, int channelOperationTimeout) { HBaseRpcController hrc; if (controller != null && controller instanceof HBaseRpcController) { hrc = (HBaseRpcController) controller; if (!hrc.hasCallTimeout()) { hrc.setCallTimeout(channelOperationTimeout); } } else { hrc = new HBaseRpcControllerImpl(); hrc.setCallTimeout(channelOperationTimeout); } return hrc; }
resetController(controller, Math.min(rpcTimeoutNs, remainingNs)); if (!cells.isEmpty()) { controller.setCellScanner(createCellScanner(cells)); if (controller.failed()) { onError(serverReq.actionsByRegion, tries, controller.getFailed(), sn); } else { try { onComplete(serverReq.actionsByRegion, tries, sn, ResponseConverter.getResults(req, rowMutationsIndexMap, resp, controller.cellScanner())); } catch (Exception e) { onError(serverReq.actionsByRegion, tries, e, sn);
@Override public void run(MultiResponse resp) { if (controller.failed()) { future.completeExceptionally(controller.getFailed()); } else { try { org.apache.hadoop.hbase.client.MultiResponse multiResp = ResponseConverter.getResults(req, resp, controller.cellScanner()); Throwable ex = multiResp.getException(regionName); if (ex != null) { future.completeExceptionally(ex instanceof IOException ? ex : new IOException( "Failed to mutate row: " + Bytes.toStringBinary(mutation.getRow()), ex)); } else { future.complete(respConverter .apply((Result) multiResp.getResults().get(regionName).result.get(0))); } } catch (IOException e) { future.completeExceptionally(e); } } } });
@Override public EchoResponseProto echo(RpcController controller, EchoRequestProto request) throws ServiceException { if (controller instanceof HBaseRpcController) { HBaseRpcController pcrc = (HBaseRpcController) controller; // If cells, scan them to check we are able to iterate what we were given and since this is an // echo, just put them back on the controller creating a new block. Tests our block building. CellScanner cellScanner = pcrc.cellScanner(); List<Cell> list = null; if (cellScanner != null) { list = new ArrayList<>(); try { while (cellScanner.advance()) { list.add(cellScanner.current()); } } catch (IOException e) { throw new ServiceException(e); } } cellScanner = CellUtil.createCellScanner(list); pcrc.setCellScanner(cellScanner); } return EchoResponseProto.newBuilder().setMessage(request.getMessage()).build(); }
Call call = new Call(nextCallId(), md, param, hrc.cellScanner(), returnType, hrc.getCallTimeout(), hrc.getPriority(), new RpcCallback<Call>() { @Override public void run(Call call) {
@Override public CellScanner cellScanner() { return delegate.cellScanner(); }
for (int i = 0; i < 10; i++) { HBaseRpcController pcrc = new HBaseRpcControllerImpl(); pcrc.setCallTimeout(timeout); BlockingRpcCallback<EmptyResponseProto> callback = new BlockingRpcCallback<>(); stub.pause(pcrc, PauseRequestProto.newBuilder().setMs(ms).build(), callback); assertTrue(pcrc.failed()); LOG.info("Caught expected exception: " + pcrc.getFailed()); IOException ioe = ProtobufUtil.handleRemoteException(pcrc.getFailed()); assertTrue(ioe.getCause() instanceof CallTimeoutException);
assertTrue(resp.getMoreResults()); assertTrue(resp.getMoreResultsInRegion()); assertEquals(0, ResponseConverter.getResults(hrc.cellScanner(), resp).length); long scannerId = resp.getScannerId(); int nextCallSeq = 0; hrc.reset(); resp = STUB.scan(hrc, req); assertTrue(resp.getMoreResults()); assertTrue(resp.getMoreResultsInRegion()); Result[] results = ResponseConverter.getResults(hrc.cellScanner(), resp); assertEquals(1, results.length); assertResult(i, results[0]); hrc.reset(); resp = STUB.scan(hrc, req); assertTrue(resp.getMoreResults()); assertTrue(resp.getMoreResultsInRegion()); assertEquals(0, ResponseConverter.getResults(hrc.cellScanner(), resp).length); for (int i = COUNT / 2; i < COUNT; i++) { req = RequestConverter.buildScanRequest(scannerId, 1, false, nextCallSeq++, false, false, -1); hrc.reset(); resp = STUB.scan(hrc, req); assertTrue(resp.getMoreResults()); assertEquals(i != COUNT - 1, resp.getMoreResultsInRegion()); Result[] results = ResponseConverter.getResults(hrc.cellScanner(), resp); assertEquals(1, results.length); assertResult(i, results[0]);
controller.setCallTimeout(call.getTimeout()); Message result = call.getService().callBlockingMethod(md, controller, param); long receiveTime = call.getReceiveTime(); responseSize); return new Pair<>(result, controller.cellScanner()); } catch (Throwable e) {
/** * Override that changes Exception from {@link Exception} to {@link IOException}. It also does * setup of an rpcController and calls through to the unimplemented * call(PayloadCarryingRpcController) method; implement this method to add your rpc invocation. */ @Override // Same trick as in RegionServerCallable so users don't have to copy/paste so much boilerplate // and so we contain references to protobuf. We can't set priority on the rpcController as // we do in RegionServerCallable because we don't always have a Table when we call. public T call(int callTimeout) throws IOException { this.controller = rpcControllerFactory.newController(); this.controller.setPriority(this.tableName); this.controller.setCallTimeout(callTimeout); try { return call(this.controller); } catch (Exception e) { throw ProtobufUtil.handleRemoteException(e); } }
@Test public void testAsyncEcho() throws IOException { Configuration conf = HBaseConfiguration.create(); RpcServer rpcServer = createRpcServer(null, "testRpcServer", Lists.newArrayList(new RpcServer.BlockingServiceAndInterface( SERVICE, null)), new InetSocketAddress("localhost", 0), CONF, new FifoRpcScheduler(CONF, 1)); try (AbstractRpcClient<?> client = createRpcClient(conf)) { rpcServer.start(); Interface stub = newStub(client, rpcServer.getListenerAddress()); int num = 10; List<HBaseRpcController> pcrcList = new ArrayList<>(); List<BlockingRpcCallback<EchoResponseProto>> callbackList = new ArrayList<>(); for (int i = 0; i < num; i++) { HBaseRpcController pcrc = new HBaseRpcControllerImpl(); BlockingRpcCallback<EchoResponseProto> done = new BlockingRpcCallback<>(); stub.echo(pcrc, EchoRequestProto.newBuilder().setMessage("hello-" + i).build(), done); pcrcList.add(pcrc); callbackList.add(done); } for (int i = 0; i < num; i++) { HBaseRpcController pcrc = pcrcList.get(i); assertFalse(pcrc.failed()); assertNull(pcrc.cellScanner()); assertEquals("hello-" + i, callbackList.get(i).get().getMessage()); } } finally { rpcServer.stop(); } }
@Override public void setCallTimeout(int callTimeout) { delegate.setCallTimeout(callTimeout); }
@Override public void reset() { delegate.reset(); }
@Override public int getCallTimeout() { return delegate.getCallTimeout(); }
@Override public boolean failed() { return delegate.failed(); }