/** Expert: Make multiple, parallel calls to a set of servers. */ public static Object[] call(Method method, Object[][] params, InetSocketAddress[] addrs, UserGroupInformation ticket, Configuration conf) throws IOException { Invocation[] invocations = new Invocation[params.length]; for (int i = 0; i < params.length; i++) invocations[i] = new Invocation(method, params[i]); Client client = CLIENTS.getClient(conf); try { Writable[] wrappedValues = client.call(invocations, addrs, method.getDeclaringClass(), ticket); if (method.getReturnType() == Void.TYPE) { return null; } Object[] values = (Object[])Array.newInstance(method.getReturnType(), wrappedValues.length); for (int i = 0; i < values.length; i++) if (wrappedValues[i] != null) values[i] = ((ObjectWritable)wrappedValues[i]).get(); return values; } finally { CLIENTS.stopClient(client); } }
String[] strings = (String[])RPC.call(echo, new String[][]{{"a"},{"b"}}, new InetSocketAddress[] {addr, addr}, conf); assertTrue(Arrays.equals(strings, new String[]{"a","b"})); Object[] voids = RPC.call(ping, new Object[][]{{},{}}, new InetSocketAddress[] {addr, addr}, conf); assertEquals(voids, null);