



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
Material Type: Lab; Class: Operating Systems; Subject: Computer Science; University: University of Texas - San Antonio; Term: Unknown 2002;
Typology: Lab Reports
1 / 5
This page cannot be seen from the preview
Don't miss anything!
] Questions on Laboratory 1 ] Models of programming in distributed systems ] Objects and remote objects ] Java remote invocation (RMI) ] A simple “Hello World” application ] The registry ] A more complicated example
] Remote method invocation (RMI) – an object in one process can invoke methods of objects in another process ] Remote procedure call (RPC) – client calls the procedure in a server program that is running in a different process ] Event notification – objects receive notification of events at other objects for which they have registered
These mechanism must be location-transparent. The first two are traditional client-server (pull), while event notification is a push strategy
] Client or its proxy marshalls the information that would be used for local access (do operation, call, or invocation) into a message and sends to the remote server.
] The server or its proxy unmarshalls the message and performs the request as though it were made locally.
] The server or its proxy then marshalls the result into a message and sends it to the remote client.
] The client or its proxy unmarshalls the message and treats the result as though it were obtained locally.
What is a proxy and why might it be useful?
] marshalling – process of transforming a collection of data items into a form suitable for transmission as a message ] unmarshalling – process of disassembling a message into its pre-marshalled equivalent. The process requires a predefined format. Examples: \ XDR standardized external data representation (RPC) \ CORBA common data representation (CDR) \ Java object serialization (Java RMI) \ Convert to ASCII (HTTP) \ Microsoft’s format
Instructor’s Guide for Coulouris, Dollimore and Kindberg© Addison-Wesley Publishers 2000 Distributed Systems: Concepts and Design Edn. 3
Figure 5. Middleware layers
Applications
Middleware Request reply protocol layers External data representation Operating System
RMI, RPC and events
] Java RMI ] CORBA – Common Object Request Broker Architecture ] Microsoft’s Distributed Common Object Model (DCOM, now COM)
] An object encapsulates both data and methods
] Objects are accessed via object references
] Interfaces – provide definitions of signature of a set of methods
] Actions are performed in OO by having objects invoke methods of other objects, the invoker is called a “client” of the object
] Invocation can cause:
\ the state of the receiver to be changed (modifier methods) \ additional invocations of methods on other objects
] Exceptions are thrown when an error occurs. If object doesn’t “catch” the exception, the exception is delivered to the caller (similar to signals, but at the programming language level) Instructor’s Guide for Coulouris, Dollimore and Kindberg© Addison-Wesley Publishers 2000 Distributed Systems: Concepts and Design Edn. 3
Figure 5. Remote and local method invocations
invocation invocation
remote invocationremote
local local
local
invocation
invocation
A B
C
D
E F
Instructor’s Guide for Coulouris, Dollimore and Kindberg© Addison-Wesley Publishers 2000 Distributed Systems: Concepts and Design Edn. 3
Figure 5. A remote object and its remote interface
interface
remote m m m
m4m m
Data
implementation
remoteobject
] Specify procedures (methods) and variables that can be accessed in a module ] No information other than that specified by the interface can be communicated. ] Do not specify an implementation ] Types of interfaces: \ Service interface (RPC) \ Remote interface (RMI)
] CORBA – uses IDL to specify remote interfaces
] JAVA – uses ordinary interfaces that are extended by the keyword remote.
] The remote interface specifies the methods of an object that are available for remote invocation ] Input and output parameters are specified. The parameters may be objects ] Use: \ When the remote method is invoked, the actual arguments corresponding to the input parameters are marshalled into a packet and sent to the server. \ The server demarshals the packet, performs the procedure, remarshals the output arguments, and sends the return packet to the caller. \ Client demarshals the return packet \ Need a common format definition for how to pass objects (e.g., CORBA IDL or Java RMI)
] RMIRegistry is binder – maintains a mapping of textual names to remote object references
] Each computer that hosts remote objects must have this program running
] The remote object references are given URL-style:
//computerName:port/objectName
] Clients must direct their lookup to particular hosts (not a system- wide binding)
Instructor’s Guide for Coulouris, Dollimore and Kindberg© Addison-Wesley Publishers 2000 Distributed Systems: Concepts and Design Edn. 3
Figure 5. The Naming class of Java RMIregistry
void rebind (String name, Remote obj) This method is used by a server to register the identifier of a remote object by name, as shown in Figure 15.13, line 3. void bind (String name, Remote obj) This method can alternatively be used by a server to register a remote object by name, but if the name is already bound to a remote object reference an exception is thrown. void unbind (String name, Remote obj) This method removes a binding. Remote lookup(String name) This method is used by clients to look up a remote object by name, as shown in Figure 15.15 line 1. A remote object reference is returned. String [] list() This method returns an array of Strings containing the names bound in the registry.
Instructor’s Guide for Coulouris, Dollimore and Kindberg© Addison-Wesley Publishers 2000 Distributed Systems: Concepts and Design Edn. 3
Figure 5. Java Remote interfaces Shape and ShapeList
import java.rmi.*; import java.util.Vector; public interface Shape extends Remote { int getVersion() throws RemoteException; GraphicalObject getAllState() throws RemoteException; 1 } public interface ShapeList extends Remote { Shape newShape(GraphicalObject g) throws RemoteException; 2 Vector allShapes() throws RemoteException; int getVersion() throws RemoteException; }
Instructor’s Guide for Coulouris, Dollimore and Kindberg© Addison-Wesley Publishers 2000 Distributed Systems: Concepts and Design Edn. 3
Figure 5. Java class ShapeListServer with main method
import java.rmi.*; public class ShapeListServer{ public static void main(String args[]){ System.setSecurityManager(new RMISecurityManager()); try{ ShapeList aShapeList = new ShapeListServant(); 1 Naming.rebind("Shape List", aShapeList ); 2 System.out.println("ShapeList server ready"); }catch(Exception e) { System.out.println("ShapeList server main " + e.getMessage());} } }
Instructor’s Guide for Coulouris, Dollimore and Kindberg© Addison-Wesley Publishers 2000 Distributed Systems: Concepts and Design Edn. 3
Figure 5. Java class ShapeListServant implements interface ShapeList
import java.rmi.*; import java.rmi.server.UnicastRemoteObject; import java.util.Vector; public class ShapeListServant extends UnicastRemoteObject implements ShapeList { private Vector theList; // contains the list of Shapes 1 private int version; public ShapeListServant()throws RemoteException{...} public Shape newShape(GraphicalObject g) throws RemoteException { 2 version++; Shape s = new ShapeServant( g, version); 3 theList.addElement(s); return s; } public Vector allShapes()throws RemoteException{...} public int getVersion() throws RemoteException { ... } } (^) Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3 © Addison-Wesley Publishers 2000
Figure 5. Java client of ShapeList
import java.rmi.; import java.rmi.server.; import java.util.Vector; public class ShapeListClient{ public static void main(String args[]){ System.setSecurityManager(new RMISecurityManager()); ShapeList aShapeList = null; try{ aShapeList = (ShapeList) Naming.lookup("//bruno.ShapeList") ; 1 Vector sList = aShapeList.allShapes(); 2 } catch(RemoteException e) {System.out.println(e.getMessage()); }catch(Exception e) {System.out.println("Client: " + e.getMessage());} } }
ShapeListClient.java
package examples.RMIShape; import java.rmi.; import java.rmi.server.; import java.util.Vector; import java.awt.Rectangle; import java.awt.Color; public class ShapeListClient{ public static void main(String args[]){ String option = "Read"; String shapeType = "Rectangle"; if(args.length > 0) option = args[0]; // read or write if(args.length > 1) shapeType = args[1]; // specify Circle, Line etc System.out.println("option = " + option + "shape = " + shapeType); if(System.getSecurityManager() == null){ System.setSecurityManager(new RMISecurityManager()); } else System.out.println("Already has a security manager, so cant set RMI SM"); ShapeList aShapeList = null;
ShapeListClient.java (cont.) try{ aShapeList = (ShapeList) Naming.lookup("//Jean.torriano.net/ShapeList"); System.out.println("Found server"); Vector sList = aShapeList.allShapes(); System.out.println("Got vector"); if(option.equals("Read")){ for(int i=0; i<sList.size(); i++){ GraphicalObject g = ((Shape)sList.elementAt(i)).getAllState(); g.print(); } } else { GraphicalObject g = new GraphicalObject(shapeType, new Rectangle(50,50,300,400), Color.red, Color.blue, false); System.out.println("Created graphical object"); aShapeList.newShape(g); System.out.println("Stored shape"); } }catch(RemoteException e) {System.out.println("allShapes: " + e.getMessage()); }catch(Exception e) {System.out.println("Lookup: " + e.getMessage());} }catch(RemoteException e) {System.out.println("allShapes: " + e.getMessage()); }catch(Exception e) {System.out.println("Lookup: " + e.getMessage());} } }
GraphicalObject.java
package examples.RMIShape; import java.awt.Rectangle; import java.awt.Color; import java.io.Serializable; public class GraphicalObject implements Serializable{ public String type; public Rectangle enclosing; public Color line; public Color fill; public boolean isFilled; public GraphicalObject() { } public GraphicalObject(String aType, Rectangle anEnclosing, Color aLine,Color aFill, boolean anIsFilled) { type = aType; enclosing = anEnclosing; line = aLine; fill = aFill; isFilled = anIsFilled; } public void print(){ System.out.print(type); System.out.print(enclosing.x + " , " + enclosing.y + " , " + enclosing.width
ShapeListServant.java package examples.RMIShape; import java.rmi.*; import java.rmi.server.UnicastRemoteObject; import java.util.Vector; public class ShapeListServant extends UnicastRemoteObject implements ShapeList{ private Vector theList; private int version; public ShapeListServant()throws RemoteException{ theList = new Vector(); version = 0; } public Shape newShape(GraphicalObject g) throws RemoteException{ version++; Shape s = new ShapeServant( g, version); theList.addElement(s); return s; } public Vector allShapes()throws RemoteException{ return theList; } public int getVersion() throws RemoteException{ return version;} }
Instructor’s Guide for Coulouris, Dollimore and Kindberg© Addison-Wesley Publishers 2000 Distributed Systems: Concepts and Design Edn. 3
Figure 5. Classes supporting Java RMI
Read: ] CDK 5.5: Java RMI Case Study ] Core Java II Chapter 5: Remote Objects ] Core Java I Chapter 5: 224- (the Class class and reflection) ] Core Java I Chapter 12: 740- (object streams and serialization)