Hadoop Source Code Analysis (vi) rpc-client

Source: Internet
Author: User

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.

Follow the Superman Academy: Bj-crxy

For more information, please visit: http://bbs.superwu.cn


Hadoop Source Code Analysis (vi) rpc-client

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.