with the client and server, it is natural to RPC. The next round is Rpc.java.
in general, distributed objects generally require the generation of stubs and frameworks based on interfaces. such as CORBA, you can generate stubs and frameworks through IDL. However, in
Org.apache.hadoop.rpc, we don't need such a step. The class diagram above.
in order to analyze invoker, we need to introduce some Java reflection to implement the background of dynamic Proxy.
The Dynamic Proxy is implemented by two classes: Java.lang.reflect.Proxy and Java.lang.reflect.InvocationHandler, which is a
interface. The so-called dynamic Proxy is a class that is generated at run time, and you must provide a set of interface to it when it is generated, and then
the class declares that it implements these interface.
This dynamic proxy is actually a typical proxy mode, it does not work for you, you must provide a handler when generating its instance,
by it takes over the actual work. This handler, in the RPC of Hadoop, is the Invoker object.
we can simply understand that you can generate a class from an interface, and all of the method calls on that class will be passed to you when you generate the class .
the Invocationhandler implementation.
in the RPC for Hadoop, Invoker implements the Invocationhandler invoke method (the Invoke method is also the only way to Invocationhandler).
Invoker will pack all the calling method names, parameter type lists, parameter lists associated with this call, and then use the client that we analyzed earlier, through the socket
delivered to the server side. That is, any calls you have on the proxy class are sent to a remote server through the client.
Invoker use invocation. Invocation encapsulates all the relevant information for a remote invocation, and its main properties are: MethodName, calling the method name,
Parameterclasses, invokes the method argument's type list and parameters, calling the method parameter. Note that it implements the writable interface, which can be serialized.
RPC. The server implements the Org.apache.hadoop.ipc.Server, you can put an object through RPC, upgrade to become a server. Requests received by the server (via invocation),
after the serialization, it becomes the method name, the method parameter list and the parameter list. With Java reflection, we can invoke the method of the corresponding object. The result of the call is then passed through the socket, returning
back to the client, the client will be able to return to the user of dynamic Proxy after unpacking the result.
More about sharing please note: http://bbs.superwu.cn
Focus on the two-dimensional code of Superman Academy:
Hadoop source Code Analysis----RPC Reflection mechanism