Analysis on using Hessian to send packets across Web sites

Source: Internet
Author: User

I don't play games for one months now. Yesterday happened to find that everyone is playing chicken, so curiosity, yesterday, unconsciously to 5 points more. I am now the computer configuration is 10 years ago, now the biggest expectation is to have a high-profile, beautiful appearance of the computer. OK, every day to idle a little bit actually very happy, also mainly is now the game mostly is the 3D experience feeling, the author Halo 3D renders (the configuration low computer more obvious), no way ah. Okay, that's nonsense. Now we implement a cross-web site of data push technology: from the current Web site to generate a data file package, and then push the data package to another Web site, to achieve real-time web site display effect push. For this, the author tries to use Hessian to solve the data push between servers across Web services.
Summarize Hessian:
1, compared to webservice,hessian more simple, fast.
2, the use of the binary RPC protocol
RPC refers to a remote procedure call protocol because it is a binary protocol, so it is good for sending binary data.
3. The object must be serialized
Because the data is transmitted using the binary RPC protocol, the object must be serialized to implement the Serializable interface
4. Initiate the request via the API provided by Hessian itself.
5, Hessian through its custom serialization mechanism to serialize the request information, resulting in a binary stream.
6, Hessian based on the Http protocol for transmission.
7. The response end receives the request according to the API provided by Hessian.
8, Hessian according to its private serialization mechanism to deserialize the request information, passed to the user is the corresponding request information object.
9. After processing, return directly, Hessian the result object to be serialized and transmitted to the caller.
The call side through the Hessianproxyfactory creation method is to create the interface proxy class, the class implements the interface, the JDK proxy class will automatically use the Invocationhandler implementation class (the class in the Hessian performance as Hessian Proxy) To populate the method body of the generated proxy class.
This remote procedure call from Hessian is fully implemented using dynamic proxies.
In addition to the encapsulation of spring, the caller is mainly through the Hessianproxyfactory create method is the proxy class that creates the interface, the class implements the interface, the JDK proxy class will automatically use the Invocationhandler implementation class (the class in the H The Invoke method body that is represented as Hessianproxy in Essian to populate the method body of the generated proxy class.
At the end of the call system startup:
Create agents based on serviceurl and Serviceinterface.
Hessianproxyfactorybean class
Hessianclientinterceptor class
Createhessianproxy (Hessianproxyfactory proxyfactory)
Hessianproxyfactory class
Public Object Create (Class API, String urlname)
When the caller calls the Hessian service:
Invoke (Object proxy, method method, Object []args) Hessianproxy class
String methodName = Method.getname ();//Get Method name
Object value = Args[0]; Get Incoming parameters
conn = SendRequest (Manglename, args); This method and the server side get the connection
Httpconn = (httpurlconnection) conn;
Code = Httpconn.getresponsecode (); Make a request
Wait for the called side to return the corresponding ...
is = Conn.getinputstream ();
Object value = In.readobject (Method.getreturntype ()); Get return value
URLConnection SendRequest (String methodName, Object []args) method for the Hessianproxy class:
URLConnection conn = _factory.openconnection (_url); Create URLConnection
OutputStream OS = Conn.getoutputstream ();
Abstracthessianoutput out = _factory.gethessianoutput (OS); Encapsulated as Hessian's own input and output API
Out.call (MethodName, args);
Return conn;
The callee receives the request and processes the request
The callee intercepts the corresponding request and gives it to:
Org.springframework.remoting.caucho.HessianServiceExporter
The specific processing steps are as follows:
A) Hessianserviceexporter class
(Hessianexporter) Invoke (Request.getinputstream (), Response.getoutputstream ());
b) Hessianexporter class
(Hessian2skeletoninvoker) This.skeletonInvoker.invoke (InputStream, OutputStream);
c) Hessian2skeletoninvoker class
Convert input and output seals into hessian2input and hessian2output that are unique to Hessian
Hessian2input in = new Hessian2input (istouse);
In.setserializerfactory (this.serializerfactory);
Abstracthessianoutput out = null;
int major = In.read ();
int minor = In.read ();
out = new Hessian2output (ostouse);
out = new Hessianoutput (ostouse);
Out.setserializerfactory (this.serializerfactory);
(Hessianskeleton) This.skeleton.invoke (in, out);
D) Hessianskeleton class
Read Method name
String methodName = In.readmethod ();
method = GetMethod (MethodName);
Read method parameters
Class []args = Method.getparametertypes ();
Object []values = new Object[args.length];
Execute the appropriate method and get the results
result = Method.invoke (service, values);
Results written to the output stream
Out.writeobject (result);
Summary: By the above source analysis, the callee received processing requests are through Hessian own API. The input and output streams are encapsulated as Hessian own hessian2input and Hessian2output
I have always believed that simple code iterates over complex functions.
The next article continues, the field process of Hessian, data push across Web services.
Reference "Hessian Baidu Encyclopedia"

Analysis on using Hessian to send packets across Web sites

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.