Presentation is loading. Please wait.

Presentation is loading. Please wait.

COS 461 Fall 1997 Network Objects u first good implementation: DEC SRC Network Objects for Modula-3 u recent implementation: Java RMI (Remote Method Invocation)

Similar presentations


Presentation on theme: "COS 461 Fall 1997 Network Objects u first good implementation: DEC SRC Network Objects for Modula-3 u recent implementation: Java RMI (Remote Method Invocation)"— Presentation transcript:

1 COS 461 Fall 1997 Network Objects u first good implementation: DEC SRC Network Objects for Modula-3 u recent implementation: Java RMI (Remote Method Invocation) u idea: allow programs to treat remote objects just like local objects –remote references –remote invocation

2 COS 461 Fall 1997 Remote References u naming a remote object (“global address”) –machine (IP address) –port number –(boot time) –unique object ID number u works in protocol, but not for a Java program u for program, use stand-in proxy object

3 COS 461 Fall 1997 Proxy Objects proxyobject globalAddr real object programprogram

4 COS 461 Fall 1997 Proxy Objects u separate proxy object for each remote object that is referenced u proxy object looks just like real object –implements the same Java interface u proxy’s methods do RPC to real object –handle arguments, return values, exceptions correctly u proxy code generated by RMI compiler

5 COS 461 Fall 1997 Proxy Types u remote objects declared as having an interface type –no variables, only methods u proxy implements same interface as real object u remote interface types must extend java.rmi.Remote interface

6 COS 461 Fall 1997 Proxy Table u each process keeps a table of all proxy objects –maps global address to proxy object u use table to maintain one-to-one mapping from proxy object to remote object u interactions with garbage collection (later)

7 COS 461 Fall 1997 Remote Invocation u when a proxy method is invoked: –invocation message sent to remote process »contains global address of object, method ID, arguments –remote process invokes real object –return message sent back to proxy object »contains return value or exception –proxy method call returns correct value, or throws correct exception

8 COS 461 Fall 1997 RMI Service Code u runs in each process that exports objects u waits for incoming connections u accepts requests, passes them to per-class request handlers u request handler translates global address to local reference, calls method, gets return value or catches exception, sends reply u request handler code generated by RMI compiler

9 COS 461 Fall 1997 Passing Arguments u primitive types (int, boolean, etc.) and ordinary objects passed by copy u Remote objects passed by reference –send across global address –at destination, translate into »pointer to existing proxy object, if there is one »pointer to new proxy object, otherwise u remaining question: how to copy objects

10 COS 461 Fall 1997 Passing a Remote Reference (1) real object proxy object globalAddr proxy object globalAddr

11 COS 461 Fall 1997 Passing a Remote Reference (2) proxy object globalAddr real object

12 COS 461 Fall 1997 Copying Objects u use ObjectOutputStream, ObjectInputStream u write out fields one at a time u if field is an Object type, recurse two tricky cases

13 COS 461 Fall 1997 Copying Objects u output stream is a sequence of objects –sequence number on each object in stream u to send a reference to an object, send the corresponding sequence number u keep table mapping pointer to sequence number –add entries when new objects are sent

14 COS 461 Fall 1997 Example (1) [int] 42 [boolean] true [T] [int] 0 [boolean] false [T] null [T] [class] <code for T> [int] 0 0 0 42 [boolean] 1 [reference] 2 [class] <code for T> [int] 0 0 0 0 [boolean] 0 [null]

15 COS 461 Fall 1997 Example (2) [int] 42 [boolean] true [T] [U] [class] <code for T> [int] 0 0 0 42 [boolean] 1 [reference] 2 [class] <code for U> [reference] 1

16 COS 461 Fall 1997 Example (3) [int] 42 [boolean] true [T] [U] [class] [int] 0 0 0 42 [boolean] 1 [reference] 2 [class] [reference] 1 [T] [U] [class] <code for U> [reference] 1

17 COS 461 Fall 1997 Class Codes u two parts to class code –“unique” ID number »hash of class name, variable names and types, method names and signature –URL of Java bytecode for class »allows recipient to load code, if it wants u (possible security problem)

18 COS 461 Fall 1997 Java Serialization u generalizes argument-passing to allow any object to be turned into a byte-array, and vice versa u to use, declare object as implementing Serializable u details –“transient” fields ignored –can customize serialization/deserialization –versioning support

19 COS 461 Fall 1997 Dealing with Failure u What if net fails, or object’s owner crashes? –proxy object detects failure –proxy throws RemoteException

20 COS 461 Fall 1997 Using RMI u write interface (extends Remote) u write server class (extends UnicastRemoteObject, implements interface) u run stub compiler (rmic) on server class –creates glue classes, one for each side u write code that uses class, compile and run

21 COS 461 Fall 1997 Garbage Collection u ideal situation: extend Java’s garbage collector to “do the right thing” in the distributed case –very difficult and inefficient in practice u lesser goal: collect everything, except for non-local cycles of garbage

22 COS 461 Fall 1997 Garbage Collection u collecting proxy objects –when no more local references to proxy, garbage-collect proxy »done “automatically” by existing garbage-collector –afterward, inform remote object that we don’t hold a proxy any more

23 COS 461 Fall 1997 Garbage Collection u collecting remote objects –RMI support code keeps track of who has proxies to the object –support code pings proxies periodically to make sure they’re still alive –support code keeps a reference to the object as long as there are any proxies –existing garbage-collector unmodified

24 COS 461 Fall 1997 Finding Objects u Where do remote references come from? –passed or returned by remote calls u Where does the first one come from? –special “registry” object on each host –special call to get a reference to a Registry object »uses a hack

25 COS 461 Fall 1997 Security? u short answer: questionable u long answer –messages not encrypted or signed »modification of calls »unauthorized calls »corruption of garbage-collection algorithm –serialization allows illegal object tampering u challenging to fix!


Download ppt "COS 461 Fall 1997 Network Objects u first good implementation: DEC SRC Network Objects for Modula-3 u recent implementation: Java RMI (Remote Method Invocation)"

Similar presentations


Ads by Google