Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "CSC 480 Software Engineering Lab 6 – RMI Nov 8, 2002."— Presentation transcript:

1 CSC 480 Software 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 ClientServer send request data return response data

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

11 Inheritance Diagram Object RemoteObject RemoteStubRemoteServer Unicast RemoteObject Remote Product ProductImpl ProductImpl_ Stub

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


Download ppt "CSC 480 Software Engineering Lab 6 – RMI Nov 8, 2002."

Similar presentations


Ads by Google