Hadoop Note One Java RPC communication __hadoop

Source: Internet
Author: User

Objective:

In this case, the default is to create a MAVEN project in Eclipse and configure the Hadoop resource. The following is the configuration information for Pom.xml

Overview:

1: In one JVM one object can invoke the resources of another object, but it is necessary to do so by means of an RPC protocol if an object in multiple JVM,JVMA calls an object in JVMB.

: The 2:RPC protocol uses the CS structure, and the requester is equivalent to a client being requested by the server.

3:java uses interface Org.apache.hadoop.ipc.VersionedProtocol to accomplish this function when communicating with RPC protocol. Two methods are declared in this interface: Getprotocolversion returns the version number, Getprotocolsignature returns the signature.

Example:

In the example, the code is divided into four parts. Client, server, and server custom protocols, implementation of the server custom protocol

Figure 1, client code

Figure 2, server code

Figure 3, server-side inherited Versionedprotocol interface


Figure 4, server-side interface implementation


Run results

Start server side, start client side, view server and client console separately

Figure 5 Client Console


Figure 6 The server console, the server has not ended in a listening state


Code Summary:

Figure 1:client configures the IP address and port to be accessed and then gets a proxy that sends a request to the server side when the heartbeat method is invoked to pass the signature information and other parameters to the past, and accept the return end. Figure 5 is the output of the client.

Figure 2:server configures the IP address and port to be monitored and implements the Org.apache.hadoop.ipc.VersionedProtocol interface to complete its own logic, and when the request is sent, he receives the client-sent parameters and executes his own logic, then returns the return value to the Client. The client then ends up receiving the return value and the server continues to listen for the next visit.

In practice, the client can send its own status information to the server to be processed by the server for all the client.


Summarize:

Server implements an interface that declares a number of methods and exposes it externally, and client communicates with the server by calling the method declared in this interface to send information to the server. And we call this interface RPC communication protocol, of course, this is my understanding.

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.