/** * Makes a set of calls in parallel. Each parameter is sent to the corresponding address. When all * values are available, or have timed out or errored, the collected results are returned in an * array. The array contains nulls for calls that timed out or errored. */ public Writable[] call( Writable[] params, InetSocketAddress[] addresses, Class<? extends VersionedProtocol> protocol, User ticket) throws IOException, InterruptedException { if (addresses.length == 0) return new Writable[0]; ParallelResults results = new ParallelResults(params.length); // TODO this synchronization block doesnt make any sense, we should possibly fix it //noinspection SynchronizationOnLocalVariableOrMethodParameter synchronized (results) { for (int i = 0; i < params.length; i++) { ParallelCall call = new ParallelCall(params[i], results, i); try { Connection connection = getConnection(addresses[i], protocol, ticket, 0, call); connection.sendParam(call); // send each parameter } catch (IOException e) { // log errors LOG.info("Calling " + addresses[i] + " caught: " + e.getMessage(), e); results.size--; // wait for one fewer result } } while (results.count != results.size) { try { results.wait(); // wait for all results } catch (InterruptedException ignored) { } } return results.values; } }
/** Deliver result to result collector. */ @Override protected void callComplete() { results.callComplete(this); }