95-702 Distributed Systems Distributed Objects Using Java RMIObjectives • Understand distributed objects • Understand Java RMI • Be able to describe the functional and non-functional characteristics of distributed systems • Compare and contrast distributed objects with web services 95-702 Distributed SystemsReview from last week • Web applications are built to interact with browsers • Web services are built to interact with clients that may or may not be associated with a browser • Web service API styles: RPC, Messaging and Resource 95-702 Distributed SystemsReview from last week • Web service API styles: RPC, Messaging and Resource • RPC API’s use SOAP and include procedure names and parameters • Messaging API’s uses SOAP but includes a document to be handled on the server • Resource API’s take HTTP, URL’s Representations, and HATEOS seriously 95-702 Distributed Systems5!Review: What is Middleware? Applications!Middleware!layers! Request reply protocol!External data representation!Operating System!RMI, RPC and events!95-702 Distributed Systems • Applications (clients and services) speak to the middleware. • TCP/IP is provided by the operating system.6!Review: external data representation • External data representation – an agreed standard for the representation of data structures and primitive values • Marshalling – the process of taking a collection of data items and assembling them into a form suitable for transmission in a message • Unmarshalling – is the process of disassembling them on arrival into an equivalent representation at the destination • The marshalling and unmarshalling are intended to be carried out by the middleware layer 95-702 Distributed Systems7 Review: Examples of external data representation: • CORBA’s CDR binary data may be used by different programming languages when CORBA middleware is present • Java RMI and .Net Remoting use object serialization. These are platform specific (that is, Java on both sides or .Net on both sides) and binary. • XML and JSON are primarily textual formats, verbose when compared to binary but interoperable. Why? Not tied to a particular language or machine architecture • In these slides, we are looking at Java RMI 95-702 Distributed Systems8 95-702 Distributed Systems 95-702 Distributed Systems Information System Management 8 Review: Generic Request-Reply message structure messageType!requestId!objectReference!methodId!arguments!int (0=Request, 1= Reply)!int!RemoteObjectRef!int or Method!array of bytes!9 95-702 Distributed Systems 95-702 Distributed Systems Information System Management 9 Review: generic remote object reference Internet address! port number! time! object number!interface of !remote object!32 bits! 32 bits! 32 bits! 32 bits!A remote object reference is an identifier for a remote object. May be returned by or passed to a remote method in Java RMI. How do these references differ from local references?10!How would you build this? Dealer’s computer!Information!provider!Dealer!External!source!External!source!Information!provider!Dealer!Dealer!Dealer!Notification!Notification!Notification!Notification!Notification!Notification!Notification!Notification!Dealer’s computer!Dealer’s computer!Dealer’s computer!Notification!Notification!95-702 Distributed Systems11!Alternative architectures for distributed event notification subscriber!observer!object of interest!Event service!object of interest!object of interest! observer!subscriber!subscriber!3.!1.!2.!notification!notification!notification!notification!95-702 Distributed SystemsWhat are the goals of Java RMI? • Distributed Java • Almost the same syntax and semantics used by non-distributed applications • Promote separation of concerns – the implementation is separate from the interface • The transport layer is TCP/IP 95-702 Distributed SystemsWhat is an IDL? • Definition: An interface definition language (IDL) provides a notation for defining interfaces in which each of the parameters of a method may be described as for input or output in addition to having its type specified. • These may be used to allow objects written in different languages to invoke one another. • In Java RMI, we use a Java interface. • See also WSDL, WADL, and AIDL 95-702 Distributed SystemsThe traditional object model (OOP 101) • Each object is a set of data and a set of methods. • Object references are assigned to variables. • Interfaces define an object’s methods. • Actions are initiated by invoking methods. • Exceptions may be thrown for unexpected or illegal conditions. • Garbage collection may be handled by the developer (C++) or by the runtime (.NET and Java). • We want similar features in the distributed case 95-702 Distributed SystemsThe distributed object model • Having client and server objects in different processes enforces encapsulation. You must call a method to change its state. • Methods may be synchronized to protect against conflicting access by multiple clients. • Objects are accessed remotely through RMI or objects are copied to the local machine (if the object’s class is available locally) and used locally. • Remote object references are analogous to local ones in that: 1. The invoker uses the remote object reference to identify the object and 2. The remote object reference may be passed as an argument to or return value from a local or remote method. 95-702 Distributed SystemsWe may use both remote and local method invocations invocation! invocation!remote!invocation!remote!local!local!local!invocation!invocation!A!B!C!D!E!F!95-702 Distributed SystemsA remote object and its remote interface interface!remote!m1!m2!m3!m4!m5!m6!Data!implementation!remote!object!{!of methods!95-702 Distributed SystemsAn important RMI design issue • Level of Transparency Remote calls should have a syntax that is close to local calls. But it should probably be clear to the programmer that a remote call is being made. 95-702 Distributed SystemsGeneric RMI object A!object B!skeleton!Request!proxy for B!Reply!Communication!Remote !Remote reference!Communication! module! module!reference module! module!for
View Full Document