RMI Notes

Remote object parameters rmi introduces a third type

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: the network wire. Object serialization essentially flattens an object and any objects it references. Serialized objects can be de-serialized in the memory of the remote JVM and made ready for use by a Java program. Remote Object Parameters RMI introduces a third type of parameter to consider: remote objects. As you have seen, a client program can obtain a reference to a remote object through the RMI Registry program. There is another way in which a client can obtain a remote reference, it can be returned to the client from a method call. In the following code, the BankManager service getAccount() method is used to obtain a remote reference to an Account remote service. BankManager bm; Account a; try { bm = (BankManager) Naming.lookup( "rmi://BankServer /BankManagerService" ); a = bm.getAccount( "ABC" ); // Code that uses the account } catch (RemoteException re) { } In the implementation of getAccount(), the method returns a (local) reference to the remote service. public Account getAccount(String accountName) { // Code to find the matching account AccountImpl ai = // return reference from search return ai; } 13 Manisha Akolkar INTERNATIONAL INSTITUTE OF INFORMATION TECHNOLOGY P-14, Pune Infotech Park, Hinjaw adi, Pune – 411 027 When a method returns a local reference to an exported remote object, RMI does not return that object. Instead, it substitutes another object (the remote proxy for that service) in the return stream. The following diagram illustrates how RMI method calls might be used to: Return a remote reference from Server to Client A Send the remote reference from Client A to Client B Send the remote reference from Client B back to Server Notice that when the AccountImpl object is returned to Client A, the Account proxy object is substituted. Subsequent method calls continue to send the reference first to Client B and then back to Server. During this process, the reference continues to refer to one instance of the remote service. It is particularly interesting to note that when the reference is returned to Server, it is not converted into a local reference to the implementation object. While this would result in a speed improvement, maintaining this indirection ensures that the semantics of using a remote reference is maintained. Distributed Garbage Collection One of the joys of programming for the Java platform is not worrying about memory allocation. The JVM has an automatic garbage collector that will reclaim the memory from any object that has been discarded by the running program. One of the design objectives for RMI was seamless integration into the Java programming language, which includes garbage collection. Designing an efficient single-machine garbage collector is hard; designing a distributed garbage collector is very hard. The RMI system provides a reference counting distributed garbage collection algorithm based on Modula-3's Network Objects. This system works by having the server keep track of which clients have requested access to remote objects running on the server. When a reference is made, the server marks the object as "dirty" and when a client drops the reference, it is marked as being "clean." The interface to the DGC (distributed garbage collector) is hidden in the stubs and skeletons layer. However, a remote object can implement the java.rmi.server.Unreferenced interface and get a notification via the unreferenced method when there are no longer any clients holding a live reference. In addition to the reference counting mechanism, a live client reference has a lease with a specified time. If a client does not refresh the connection to the remote object before the lease term expires, the reference is considered to be dead and the remote object may be garbage collected. The lease time is controlled by the system property java.rmi.dgc.leaseValue. The value is in milliseconds and defaults to 10 minutes. Because of these garbage collection semantics, a client must be prepared to deal with remote objects that have "disappeared." 14 Manisha Akolkar...
View Full Document

This note was uploaded on 07/15/2011 for the course ECO 2023 taught by Professor Mr.raza during the Summer '10 term at FAU.

Ask a homework question - tutors are online