• Like
Remote Method Invocation
Upcoming SlideShare
Loading in...5
×

Remote Method Invocation

  • 642 views
Uploaded on

Basic of Remote Method Invocation [ RMI ]

Basic of Remote Method Invocation [ RMI ]

More in: Education , Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
642
On Slideshare
0
From Embeds
0
Number of Embeds
1

Actions

Shares
Downloads
40
Comments
0
Likes
1

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. RMI ArchitectureProf. Ashish Bhatia,ast.bhatia@gmail.com,ashish@asbspace.in, Web: asbspace.in, M:9879009551 September 10, 2012
  • 2. OutLineBasic of RMIRMI ArchitectureRMI Architecture3 Common TermsStubSkeletonRemote Reference LayerRMI RegistryCreating RMI Base ApplicationCreating the interfaceCreating the interfaceImplementing the interfaceCreating the Server ProgramCreating the Client ProgramRunning the Program
  • 3. Basic of RMI Stands for Remote Method Procedure Call.
  • 4. Basic of RMI Stands for Remote Method Procedure Call. Enables to communicate two different objects in different Java Virtual Machine.
  • 5. Basic of RMI Stands for Remote Method Procedure Call. Enables to communicate two different objects in different Java Virtual Machine. Distributed Application Development and Remote Calling
  • 6. Basic of RMI Stands for Remote Method Procedure Call. Enables to communicate two different objects in different Java Virtual Machine. Distributed Application Development and Remote Calling CORBA - Common Object Request Broker Architectire, DCOM - Distributed Component Object Model.
  • 7. RMI Architecture
  • 8. RMI Architecture Mechanism by which client can programmer make a regular method call , without worrying about sending data across the network or parsing the response. The solution is to install the proxy object on the client. Proxy is an object located at client VM that appears to be client program. Client call proxy, making a regular method call. Client proxy contacts server using a network protocol [TCP] Same happen at server side. Proxy on server so that server don’t realize the network call.
  • 9. RMI Architecture Proxies at both the end communicated with each other and it shows / pretends that calls were regular calls not the remote call. How do Remote Call Works ? Java RMI CORBA [ IIOP ] Web Service [ SOAP ]
  • 10. RMI Architecture
  • 11. 3 Common Terms Marshalling :is a process in which parameters passed by client are converted to a format that can be transferred across a network.
  • 12. 3 Common Terms Marshalling :is a process in which parameters passed by client are converted to a format that can be transferred across a network. UnMarshalling : is a process in which marshaled parameters passed by the client-side RRL through the server-side RRL are converted to a format that the skeleton understands.
  • 13. 3 Common Terms Marshalling :is a process in which parameters passed by client are converted to a format that can be transferred across a network. UnMarshalling : is a process in which marshaled parameters passed by the client-side RRL through the server-side RRL are converted to a format that the skeleton understands. Serilization : is a general purpose mechanism for taking an object and encoding it as a stream of bytes. The underlying design rationale is fairly simple.
  • 14. Stub : Client Side Proxy Client invoke a method on a remote object -¿ Call to Proxy Object called STUB STUB knows how to contact to the server. It packages the parameters used in remote methods in to a block of bytes Process of Encoding is called Marshalling An identifier of the remote object to be used A description of the method to be called. The parameters. Objects are encoded using Serilaization
  • 15. Skeleton : Server Side Proxy It locates remote object to be called It calls the desired method, passing the supplied parameters. It captures the return value or exception of the call. It sends a package consisting of the marshaled return data back to the stub on the client.
  • 16. Remote Reference Layer Encapsulates the invocation semantic of the RMI connection. Provides java.rmi.server.RemoteRef object which handle remote service implmentation object. invoke() method is used by stub instance to forward method call. RRL extracts information about the remote server / remote client.
  • 17. RMI Registry It is a naming services used by RMI server program to bind the Java Object with names. Client retrieves object using the name from the RMI registry. By default it runs on the port 1099 to accept the queries. On a host machine, a server program creates a remote service by first creating a local object that implements that service. RMI creates a listening service that waits for clients to connect and request the service. On the client side, the RMI Registry is accessed through the static class Naming. It provides the method lookup() that a client uses to query a registry.
  • 18. Creating RMI Base Application 1. Create the interface. 2. Define a class that implements an interface. 3. Create the server process. 4. Create the client process.
  • 19. Creating the interface import java.rmi.*; public interface Hello extends Remote { public String sayDemo() throws RemoteException; }
  • 20. Creating the interface import java.rmi.*; public interface Hello extends Remote { public String sayDemo() throws RemoteException; }
  • 21. Implementing the interface import java.rmi.*; import java.rmi.server.*; public class HelloImpl extends UnicastRemoteObject implements Hello { public String sayDemo() throws RemoteException { return("Hello World"); } }
  • 22. Creating the Server Program import java.rmi.*; import java.rmi.server.*; public class HelloServer { public static void main(String args) { HelloImpl temp = new HelloImpl(); String rmiobjectname = "rmi://localhost/Hello"; Context namingContext=new InitialContext(); namingContext.bind(rmiobjectname,temp); System.out.println("Binding Complete ..."); } }
  • 23. Creating the Client Program import java.rmi.*; import java.rmi.server.*; public class HelloClient { public static void main(String args) { try { Context namingContext = new InitialContext(); Hello greeting = (Hello)namingContext.lookup("rmi://localhost/Hello"); System.out.println("Recvd Message ..." + greeting.getGreeting()); } catch(ConnectException e) { System.out.println("Error");
  • 24. Running the Program Compile all java files. Run rmic HelloImpl to generate Stub Files Create two folders Server anc Client Copy all class files except HelloClient.class and stub.class file in server folder Copy HelloClient.class, Hello.class and stub.class in client folder. Run rmiregistry through commandprompt. Run HelloServer followed by HelloClient.