Step Two: Generate Stubs and Skeletons
Before you can use the client and server, you must generate the necessary stub. You may also need to generate-a skeleton. In the context of RMI, a stub is a Java object that . resides on the client machine. Its function is to present the same interfaces as the remote server. Remote method. calls initiated by the client are actually directed to the stub. The stub works with the other parts of the RMI system to formulate a request that is sent to the remote machine.
A remote method may accept arguments that arc simple types or objects. In the latter case, the object may have references to other objects ..AU of this Information must be sent to the remote machine. That is, an object passed as an argument to a remote . method call must be serialized and sent to the remote )nac;hlne. Recall from Chapter 17 that the serialization facilities also recursively process all referenced objects, Skeletons are not required by Java 2. However, they are required for the Java 1.1 RMI model. Because of the§, skeletons are still required for compatibility between Java 1.1 and Java 2. A skeleton is a Java object that resides on the server machine. It works with the other parts of the 1.1 RMI·system to receive requests, perform deserialization, and invoke the appropriate code on the server. Again, the skeleton mechanism is not required for Java 2 code that does-not require compatibility with 1,1. Because most readers will want to generate the skeleton, one is used by the example . If a response must be retumed. to the client, the process works in reverse, Note that the serialization and deserialization facilities are also used if objects are returned to a client.
This command generates two new files: AddServer ImpCSkel.c1as~ (skeleton) and AddServer mpC Stub.c1ass (stub). When using rmic, be sure that CLASSPATH is set to include the current directory. As you can see, by default, rmi generates both a stub and a skeleton file. If you do not need the skeleton, you have the option to suppress it: