/** 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); } }
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { final boolean logDebug = LOG.isDebugEnabled(); long startTime = 0; if (logDebug) { startTime = System.currentTimeMillis(); } ObjectWritable value = null; try { value = (ObjectWritable) client.call( new Invocation(method, args), getAddress(), protocol, ticket, rpcTimeout); } catch (RemoteException re) { throw re; } catch (ConnectException ce) { needCheckDnsUpdate = true; throw ce; } catch (NoRouteToHostException nrhe) { needCheckDnsUpdate = true; throw nrhe; } catch (PortUnreachableException pue) { needCheckDnsUpdate = true; throw pue; } catch (UnknownHostException uhe) { needCheckDnsUpdate = true; throw uhe; } if (logDebug) { long callTime = System.currentTimeMillis() - startTime; LOG.debug("Call: " + method.getName() + " " + callTime); } return value.get(); }
/** Test that, if the socket factory throws an IOE, it properly propagates to the client. */ public void testSocketFactoryException() throws Exception { SocketFactory mockFactory = mock(SocketFactory.class); doThrow(new IOException("Injected fault")).when(mockFactory).createSocket(); Client client = new Client(LongWritable.class, conf, mockFactory); InetSocketAddress address = new InetSocketAddress("127.0.0.1", 10); try { client.call(new LongWritable(RANDOM.nextLong()), address, null, null); fail("Expected an exception to have been thrown"); } catch (IOException e) { assertTrue(e.getMessage().contains("Injected fault")); } }
public void doAction(Client client, String[] values) throws Exception { HashMap<String, String> container = new HashMap<String, String>(); if (values.length != argNames.length) { throw new IllegalArgumentException( "The quantity of parameters should be " + argNames.length + "! But is " + values.length); } for (int i = 0; i < values.length; i++) { argNames[i].setArgs(container, values[i]); } SikuliScript script = client.call(getUrlData(container)); if (script.getStatus() == ScriptStatus.FAIL) { throw script.getFailure_reason(); } }
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { long startTime = 0; if (LOG.isDebugEnabled()) { startTime = Time.now(); } ObjectWritable value = (ObjectWritable) client.call(RPC.RpcKind.RPC_WRITABLE, new Invocation(method, args), remoteId); if (LOG.isDebugEnabled()) { long callTime = Time.now() - startTime; LOG.debug("Call: " + method.getName() + " " + callTime); } return value.get(); }
public void run() { for (int i = 0; i < count; i++) { try { LongWritable param = new LongWritable(RANDOM.nextLong()); LongWritable value = (LongWritable) client.call(param, server, null, null); if (!param.equals(value)) { LOG.fatal("Call failed!"); failed = true; break; } } catch (Exception e) { LOG.fatal("Caught: " + StringUtils.stringifyException(e)); failed = true; } } }
public void testStandAloneClient() throws Exception { testParallel(10, false, 2, 4, 2, 4, 100); Client client = new Client(LongWritable.class, conf); InetSocketAddress address = new InetSocketAddress("127.0.0.1", 10); try { client.call(new LongWritable(RANDOM.nextLong()), address, null, null); fail("Expected an exception to have been thrown"); } catch (IOException e) { String message = e.getMessage(); String addressText = address.toString(); assertTrue("Did not find " + addressText + " in " + message, message.contains(addressText)); Throwable cause = e.getCause(); assertNotNull("No nested exception in " + e, cause); String causeText = cause.getMessage(); assertTrue("Did not find " + causeText + " in " + message, message.contains(causeText)); } }
public void testErrorClient() throws Exception { // start server Server server = new TestServer(1, false); InetSocketAddress addr = NetUtils.getConnectAddress(server); server.start(); // start client Client client = new Client(LongErrorWritable.class, conf); try { client.call(new LongErrorWritable(RANDOM.nextLong()), addr, null, null); fail("Expected an exception to have been thrown"); } catch (IOException e) { // check error Throwable cause = e.getCause(); assertTrue(cause instanceof IOException); assertEquals(LongErrorWritable.ERR_MSG, cause.getMessage()); } }
public void run() { for (int i = 0; i < count; i++) { try { Writable[] params = new Writable[addresses.length]; for (int j = 0; j < addresses.length; j++) params[j] = new LongWritable(RANDOM.nextLong()); Writable[] values = client.call(params, addresses, null, null); for (int j = 0; j < addresses.length; j++) { if (!params[j].equals(values[j])) { LOG.fatal("Call failed!"); failed = true; break; } } } catch (Exception e) { LOG.fatal("Caught: " + StringUtils.stringifyException(e)); failed = true; } } }