since it is RPC, naturally there are clients and servers, of course, ORG.APACHE.HADOOP.RPC also have the class client and Class Server. Here we take a close examination
observe org.apache.hadoop.rpc.Client. The following diagram contains the key classes and key methods in Org.apache.hadoop.rpc.Client.
because the client may communicate with multiple servers, a typical HDFS read is required to deal with Namenode and to communicate with some/some datanode. It
means that one client needs to maintain multiple connections. At the same time, in order to reduce unnecessary connections, it is now the client's practice to take ConnectionID (the right
side) to be the ID of the connection. ConnectionID includes an inetsocketaddress (IP address + port number or hostname + port number) object and a
The user information object. This means that the same user's communication to the same inetsocketaddress will share the same connection.
The connection is encapsulated in the class client.connection, and all RPC calls are communicated through Connection. An RPC call that naturally has input parameters,
output parameters and possible exceptions, and in order to differentiate between different calls on the same connection, each call has a unique ID. Whether the call ends also requires
a tag, all of which are reflected in the object Client.call. The Connection object maintains all call on this connection through a hash table:
Java Code
1. Private Hashtable<integer, call> calls = new Hashtable<integer, call> ();
an RPC call is made through Addcall to add the request to connection. In order to be able to transfer the basic type of Java on this frame, String and writable are connected
The implementation class of the port, and the element as an array of the above types, we generally package the parameters that call requires into a Objectwritable object.
Client.connection will connect to the server via the socket, and verify the client/server version number (Client.connectionwriteheader ()) After successful connection
The writable object can be used to send/reply to the request after the validation is successful. Note that each client.connection will start a thread that constantly
to read the socket and unpack the received results, find the corresponding call, set up called and notify the result has been obtained.
call uses Obejct's wait and notify to turn asynchronous message interactions on the RPC to synchronous calls.
It is also important to note that a client will have multiple client.connection, which is a natural result.
Hadoop Source Code Analysis (vi) rpc-client