A simple RPC mechanism.
A
is a Java interface. All parameters and return types must
be one of:
All methods in the protocol should throw only IOException. No field data of
the protocol instance is transmitted.
| Method from org.apache.hadoop.ipc.RPC Detail: |
public static Object[] call(Method method,
Object[][] params,
InetSocketAddress[] addrs,
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]);
Writable[] wrappedValues = getClient(conf).call(invocations, addrs);
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;
}
Expert: Make multiple, parallel calls to a set of servers. |
public static VersionedProtocol getProxy(Class protocol,
long clientVersion,
InetSocketAddress addr,
Configuration conf) throws IOException {
VersionedProtocol proxy = (VersionedProtocol) Proxy.newProxyInstance(
protocol.getClassLoader(),
new Class[] { protocol },
new Invoker(addr, conf));
long serverVersion = proxy.getProtocolVersion(protocol.getName(),
clientVersion);
if (serverVersion == clientVersion) {
return proxy;
} else {
throw new VersionMismatch(protocol.getName(), clientVersion,
serverVersion);
}
}
Construct a client-side proxy object that implements the named protocol,
talking to a server at the named address. |
public static RPC.Server getServer(Object instance,
String bindAddress,
int port,
Configuration conf) throws IOException {
return getServer(instance, bindAddress, port, 1, false, conf);
}
Construct a server for a protocol implementation instance listening on a
port and address. |
public static RPC.Server getServer(Object instance,
String bindAddress,
int port,
int numHandlers,
boolean verbose,
Configuration conf) throws IOException {
return new Server(instance, conf, bindAddress, port, numHandlers, verbose);
}
Construct a server for a protocol implementation instance listening on a
port and address. |
public static synchronized void stopClient() {
if (CLIENT != null) {
CLIENT.stop();
CLIENT = null;
}
}
Stop all RPC client connections |
public static VersionedProtocol waitForProxy(Class protocol,
long clientVersion,
InetSocketAddress addr,
Configuration conf) throws IOException {
while (true) {
try {
return getProxy(protocol, clientVersion, addr, conf);
} catch(ConnectException se) { // namenode has not been started
LOG.info("Server at " + addr + " not available yet, Zzzzz...");
} catch(SocketTimeoutException te) { // namenode is busy
LOG.info("Problem connecting to server: " + addr);
}
try {
Thread.sleep(1000);
} catch (InterruptedException ie) {
// IGNORE
}
}
}
|