1 / 18

CSC 480 Software Engineering

CSC 480 Software Engineering. Lab 6 – RMI Nov 8, 2002. Remote Method Invocation. RMI applications are often comprised of a server creates some remote objects makes references to them accessible waits for clients to invoke methods on these remote objects a client

tyne
Télécharger la présentation

CSC 480 Software Engineering

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CSC 480Software Engineering Lab 6 – RMI Nov 8, 2002

  2. Remote Method Invocation • RMI applications are often comprised of • a server • creates some remote objects • makes references to them accessible • waits for clients to invoke methods on these remote objects • a client • gets a remote reference to one or more remote objects in the server and then • invokes methods on them.

  3. Distributed Object Application • RMI provides the mechanism by which the server and the client communicate and pass information back and forth. • Such an application is sometimes referred to as a distributed object application.

  4. Typical Activities • Distributed object applications need to • Locate remote objects • Communicate with remote objects • Load class bytecodes for objects that are passed around

  5. Locate Remote Objects • Applications can use one of two mechanisms to obtain references to remote objects. • Register its remote objects with RMI's simple naming facility, the rmiregistry, or • Pass and return remote object references as part of its normal operation.

  6. Communicate w/ Remote Objects • Details of communication between remote objects are handled by RMI • To the programmer, remote communication looks like a standard Java method invocation

  7. Load Class Bytecodes • Load class bytecodes for objects that are passed around: Because RMI allows a caller to pass objects to remote objects, RMI provides the necessary mechanisms for loading an object's code, as well as for transmitting its data.

  8. An Illustration

  9. Client-Server via Socket Client Server send request data return response data

  10. RMI client stub receiver server Call stub method locally Send marshalled parameters Call server method locally Send marshalled return value or exception return value or Throw exception

  11. Inheritance Diagram Object Remote RemoteObject Product RemoteStub RemoteServer Unicast RemoteObject ProductImpl_ Stub ProductImpl

  12. The Product Interface • The client will not have a copy of the remote object • It knows what the remote object can do from the interface shared between the client and the server import java.rmi.*; public interface Product extends Remote { String getDescription() throws RemoteException; }

  13. The ProductImpl Class • On the server side, the methods advertised in the remote interface should be implemented by a class named ProductImpl import java.rmi.*; import java.rmi.server.*; public class ProductImpl extends UnicastRemoteObject implements Product { public ProductImpl(String n) throws RemoteException { name = n; } public String getDescription() throws RemoteException { return "I am a " + name + ". Buy me!"; } private String name; }

  14. The Client Side • A stub class (ProductImpl_Stub.class) will be created when the ProductImpl class is compiled with rmic • A security policy file is needed to start the client • In the client program (ProductClient.java) a security manager need to be set up System.setSecurityManager(new RMISecurityManager());

  15. The ProductClient Class • Set up a security manage • Specify the server URL • Access the remote object String url = "rmi://localhost/"; try { Product c1 = (Product)Naming.lookup(url + "toaster"); } catch (Exception e) { System.out.println("Error " + e); }

  16. The Security Policy File • For security purpose, to let the client to connect to the RMI registry and the server object, a policy file is needed to grant the permissions grant { permission java.net.SocketPermission "*:1024-65535", "connect,accept"; permission java.net.SocketPermission "localhost:80", "connect"; };

  17. Compile the Application • Do a normal compile javac *.java • Run rmic on the implementation class rmic ProductImpl • You may also specify a version. With v1.2, no skeleton file will be generated rmic –v1.2 ProductImpl

  18. Running the Application • Start the RMI registry rmiregistry & • Start the server java ProductServer & • Run the client java –Djava.sercurity.policy= client.policy ProductClient

More Related