Rmi

591 views

Published on

Rmi

Published in: Education, Technology
  • Be the first to comment

  • Be the first to like this

Rmi

  1. 1. ManimozhiVijay Kiran
  2. 2. Whats RMI ??The Java Remote Method InvocationApplication Programming Interface (API),Java RMI, is a Java API that performs theobject-oriented equivalent of remoteprocedure calls (RPC), with support fordirect transfer of Java objects over adistributed network.
  3. 3. RMI Vs RPCRPC is C based, and as such it has structuredprogramming semantics, on the other side, RMI is a Java based technology and its object orientedand can be used for complex applications.With RPC you can just call remote functions exported intoa server, RMI you can have references to remote objects andinvoke their methods, and also pass and return moreremote object references that can be distributed amongmany JVM instances, so its much more powerful.
  4. 4. Sockets Vs RMIIf your programming games, chat programs,streaming media, file transfer use socketsand read/write bytes. You have tighter controlover what is sent, you can optimize thestreams, by buffering, or compressing date.If you programming business applicationswhich require remote method calls, use RMI.Corba however would be useless for lets say,file transfer, or any streaming type app.
  5. 5. Architecture
  6. 6. Working of RMI
  7. 7. MarshallingDuring communication between two machinesthrough RPC or RMI, parameters are packedinto a message and then sent over the network.This packing of parameters into a message iscalled marshalling.On the other side these packed parameters areunpacked from the message which is calledunmarshalling.
  8. 8. RMI Application DevelopmentSteps for Developing the RMI Application• Define the remote interface• Define the class and implement the remoteinterface(methods) in this class• Define the Server side class• Define the Client side class• Compile the all four source(java) files• Generate the Stub/Skeleton class by command• Start the RMI remote Registry• Run the Server side class• Run the Client side class(at another JVM)
  9. 9. (1) Define the remote interface: This is an interface in which we are declaringthe methods as per our logic and furtherthese methods will be called using RMI.
  10. 10.  (2) Define the class and implement theremote interface(methods) in this class: The next step is to implement the interfaceso define a class(ServerImpl.java) andimplements the interface(Vinterface.java) sonow in the class we must define the body ofthose methods.This class run on the remoteserver.
  11. 11. (3) Define the Server side class: The server must bind its name to the registry by passing thereference link with remote object name. For that here we are going to use rebind method which has twoarguments: The first parameter is a URL to a registry that includes the nameof the application and The second parameter is an object namethat is access remotely in between the client and server. This rebind method is a method of the Naming class which isavailable in the java.rmi.* package. The server name is specified in URL as a application name andhere the name is (ServerImp) in our application.
  12. 12. Note: The general form of the URL: rmi://localhost:port/application_name Here, 1099 is the default RMI port and127.0.0.1 is a localhost-ip address.
  13. 13. (4) Define the Client side class: To access an object remotely by client sidethat is already bind at a server side by onereference URL we use the lookup methodwhich has one argument that is a samereference URL as already applied at serverside class. This lookup method is a method of theNaming class which is available in thejava.rmi.* package.
  14. 14. (5) Compile the all four source(java) files: javac InterfaceFile.java javac InterfaceFileImpl.java javac Client.java javac Server.javaAfter compiled, in the folder we can see the fourclass files such as InterfaceFile.class , InterfaceFileImpl.class Client.class , Server.class
  15. 15. (6) Generate the Stub/Skeleton class bycommand: There is a command rmic by which we cangenerate a Stub/Skeleton class. Syntax: rmic class_name Here the class_name is a java file in whichthe all methods are defined so in thisapplication the class nameis ServerImpl.java file.
  16. 16. (7) Start the RMI remote Registry: The references of the objects are registeredinto the RMI Registry So now you need tostart the RMI registry for that use thecommand start rmiregistry So the system will open rmiregistry.exe (likea blank command prompt)
  17. 17. (8) Run the Server side class: Now you need to run the RMI Server class.(9) Run the Client side class(at another JVM): Now open a new command prompt for the clientbecause current command prompt working as aserver and finally run the RMI client class. Here Client.java file is a working as a Client sofinally run this fie. java Client
  18. 18. Demo time

×