Java Remote Technology Introduction learning

Source: Internet
Author: User
Tags stub

Java Remote Technology Introduction learning RMI

"Remote Invoke method Invoke"
The implementation is that the class extend the Java.rmi.Remote interface, which is a remote object that exists on the server side, providing client access.
PS: extends the class of the remote interface or the method in other interfaces if the declaration throws a remoteexception exception, it indicates that the method can be called by the client for remote access.

While The remote object must implement the Java.rmi.server.UniCastRemoteObject class so that when the client accesses the remote object, the remote object will transmit a copy of itself to the client in the form of a socket, when the copy obtained by the client is called The "stub", and the remote object that already exists on the server side itself is called the "skeleton". In fact, the stub at this time is a client agent for communication with the server side, and the skeleton can also be considered a proxy on the server side, to receive the client's request after the call to the remote method to respond to the client's request.
Trading sequence Diagram:

Simple example

/** * Defines a remote interface that must inherit from the remote interface, where the method that requires the call must throw a RemoteException exception .  Public  interface Ihello extends Remote {     /** * Simple return "Hello world!" "Words * @return return" Hello world! The words * @throws java.rmi.RemoteException * *      PublicStringHelloWorld()throwsRemoteException;/** * A simple business method that returns the corresponding greeting according to the name of the incoming person * @param somebodyname name * @return return the appropriate greeting *
     
       @throws java.rmi.RemoteException *
      /      PublicStringSayhellotosomebody(String somebodyname)throwsRemoteException; }
/** The implementation of the remote interface * /  Public  class helloimpl extends unicastremoteobject implements Ihello  {     /** * Because the UnicastRemoteObject constructor throws a RemoteException exception, the default constructor must be written here, and you must declare a RemoteException exception to be thrown * @throws 
       remoteexception * /      Public Helloimpl()throwsRemoteException {}/** * Simple return "Hello world!" "The words * * @return return" Hello world! The words * @throws java.rmi.RemoteException * *      PublicStringHelloWorld()throwsremoteexception {return "Hello world!"; }/** * A simple business method that returns the corresponding greeting according to the name of the incoming person * @param somebodyname name * @return return the appropriate greeting *< c11> @throws java.rmi.RemoteException * /      PublicStringSayhellotosomebody(String somebodyname)throwsremoteexception {return "Hello,"+ Somebodyname +"!"; } }
/** * Create the RMI registry, start the RMI service, and register the remote object in the RMI registry. */  Public  class helloserver {      Public Static void Main(String args[]) {Try{//Create a remote objectIhello Rhello =NewHelloimpl ();///The remote object registry on the local host is an instance of registry and specifies that the port is 8888, which is essential (the Java default port is 1099), an indispensable step, the absence of registry creation, the inability to bind the object to the remote registryLocateregistry.createregistry (8888);//Add this program, you can not open the RMI registration program on the console, 1099 is the default port for RMI service monitoring            //Register the remote object on the RMI registration server and name it Rhello            the URL standard format for the//binding is: Rmi://host:port/name (where the protocol name can be omitted, the following two types of notation are correct)Naming.bind ("Rmi://localhost:8888/rhello", Rhello);//Naming.bind ("//localhost:8888/rhello", Rhello);System.out.println (">>>>>info: Remote Ihello object binding succeeded! "); }Catch(RemoteException e) {System.out.println ("An exception occurred creating the remote Object!" ");         E.printstacktrace (); }Catch(Alreadyboundexception e) {System.out.println ("A duplicate bound object exception occurred!" ");         E.printstacktrace (); }Catch(Malformedurlexception e) {System.out.println ("A malformed URL has occurred!" ");         E.printstacktrace (); }     } }
The /** client tests a remote method on the client that invokes the remote object and returns the result. */  Public  class helloclient {      Public Static void Main(String args[]) {Try{//Find an object named Rhello in the RMI service registry and invoke the method on itIhello Rhello = (Ihello) naming.lookup ("Rmi://localhost:8888/rhello");             System.out.println (Rhello.helloworld ()); System.out.println (Rhello.sayhellotosomebody ("Lava")); }Catch(Notboundexception e)         {E.printstacktrace (); }Catch(Malformedurlexception e)         {E.printstacktrace (); }Catch(RemoteException e)           {E.printstacktrace (); }     } }

PS:
RMI is very dependent on the IP address and port of the server, but is not aware of the future server IP and port at the time of development, but the client program relies on this IP and port.
One of the limitations of RMI, two solutions: one is to resolve through DNS, and the other is to expose IP to program code through encapsulation.
The second limitation of RMI is that RMI is a remote invocation of the Java language, the programming language must be Java implementation, the communication between different languages can be considered by the Web service or the Common Object Request Agent system (CORBA) to achieve.
"The above demo from: http://lavasoft.blog.51cto.com/62575/91679/"
"Other Knowledge: Http://www.blogjava.net/zhenyu33154/articles/320245.html has spring's support for RMI"

Cxf/axis2

Introduction:
Axis2 is a heavyweight webservice framework under Apache, which accurately says it is a web services/soap/wsdl engine that can produce and publish WebService, You can also generate Java and other language versions of WebService client and server-side code. But Bao's big, not good package deployment.
CXF is an Apache-heavy SOA simple framework that implements the ESB (Enterprise service Bus). CXF is a combined product of the Xfire and Celtix projects.
"CXF supports SPRING,AXIS2 support for other languages"
[As for the remote technology of these two frameworks, ╮ (╯_╰) ╭ no matter]
"Source: http://www.cnblogs.com/growup/archive/2011/03/06/1972464.html"

Hessian

Introduction:
Hessian is a lightweight remoting onhttp tool that provides RMI functionality in an easy-to-use way.
The binary RPC protocol is used because the binary protocol is used, so it is well suited for sending binary data.
Support n multi-language!
implementation matters:
-The server implements interface functions, configures Web. XML and the corresponding servlet. "Objects must be serialized, and complex objects are passed using map methods"
-The client needs to include the Hessian (service-side service). jar, and then use Hessianproxyfactory to invoke the remote interface.

"It can be integrated with spring (but I don't think there's anything to use ╮ (╯_╰) ╭)"
[Source Address: http://www.cnblogs.com/yjmyzz/p/hessian-helloworld.html]

Thrift

* * Introduction:
Support for multi-lingual remote service invocation framework. Support multiple data transfer protocols, code generation engine? (Compiler code generation).
Transferring data using binary format has some advantages over high concurrency and large data volumes. **
Website address: thrift.apache.org
Implementation method:
-Write the thrift file file, generated by the compiler directory files and so on.
-After writing the interface, implementation, service of Dongdong.
-it's probably jiangzi.

"Source: http://www.micmiu.com/soa/rpc/thrift-sample/"
[Source: http://www.ibm.com/developerworks/cn/java/j-lo-apachethrift/#ibm-pcon]

Mina

Introduction:
Is Apache Mina is a framework that helps users develop high-performance and highly scalable network applications. It provides an abstract, event-driven, asynchronous APIbased on the TCP/IP and UDP/IP Protocols of Java NIO technology.

This thing is strange, is to use the socket for connection communication, and then, Mina to the IO stream multi-socket conversion processing.
Do not know where this can be used? _?
[Source: http://www.cnblogs.com/xuekyo/archive/2013/03/06/2945826.html]

Other
    • Burlap
    • Spring-ws
    • Jms-activemq

2016-07-22 Friday: Clap:

Java Remote Technology Introduction learning

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.