A.1 RMI

 <  Day Day Up  >  

RMI support in Java 2 is provided by the java.rmi package and its four subpackages: java.rmi.activation , java.rmi.dgc , java.rmi.registry , and java.rmi.server . With RMI, an object, B , residing on the server may be manipulated by another object, A , on a remote client. Object B doesn't really exist on the client; rather, an alternative object is used as a kind of stunt double . This stub , or proxy object , provides the same interface as the real object B but under the covers uses the RMI services to pass method requests over the network to the real object B . Object A therefore doesn't need to know whether object B is local or remote (see Figure A.1).

Figure A.1. Invoking a Method with RMI

graphics/ap01fig01.gif

If another object, C , needs to be passed between the client and the server ”for instance, as a parameter for a method ”RMI uses a technique called object serialization to flatten the object, turning it into a stream of bytes. These bytes are sent to the RMI system on the remote machine, which rebuilds the object C and passes it into the method call. Return values from methods are handled in the same way.

A simple naming service, the RMI registry, is provided to connect clients and servers, using a URL-style of names , such as //host:port/ name . A client asks for the remote objects, and the remote server returns the stub object to the client. Developers use the rmic compiler to generate the matching stub and skeleton classes for a remote object.

This means that it becomes possible to write distributed applications, with little need to be aware of exactly where the software will be executed. A RemoteException may be thrown on error conditions; otherwise , the program need not be aware that portions are executing remotely.

 <  Day Day Up  >  


Enterprise Java Security. Building Secure J2EE Applications
Enterprise Javaв„ў Security: Building Secure J2EEв„ў Applications
ISBN: 0321118898
EAN: 2147483647
Year: 2004
Pages: 164

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net