/** * Tries to execute a RPC defined as a {@link RpcCallable}, if error * happens in one execution, a reconnection will be tried through {@link #connect()} and the * action will be re-executed. * * @param rpc the {@link RpcCallable} to be executed * @param <V> type of return value of the RPC call * @return the return value of the RPC call * @throws IOException when retries exceeds {@link #RPC_MAX_NUM_RETRY} or {@link #close()} has * been called before calling this method or during the retry */ private <V> V retryRPC(RpcCallable<V> rpc) throws IOException { int retry = 0; while (!mClosed && (retry ++) <= RPC_MAX_NUM_RETRY) { connect(); try { return rpc.call(); } catch (TException e) { LOG.error(e.getMessage(), e); mConnected = false; } } throw new IOException("Failed after " + retry + " retries."); } }