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.