Just a little more RMI review

Without doing an entire RMI tutorial,[15] we’ll look at a few more high level RMI topics to make sure we’re all talking the same talk. Specifically, we’ll look at the server side and client side of using RMI.

RMI on the Server side in 4 steps

(An overview of the steps to make a remote model service that runs on the server.)

  1. Create a remote interface. This is where the signature for methods like getCustData() will reside. Both the stub (proxy) and the actual model service (the remote object) will implement this interface.

  2. Create the remote implementation, in other words, the actual model object that will reside on the model server. This includes code that registers the model with a well-known registry service such as JNDI or the RMI registry.

  3. Generate the stub and (possibly) skeleton. RMI provides a compiler called rmic that will create the proxies for you.

  4. Start/run the model service (which will register itself with the registry and wait for calls from far-away clients).

The client side, with and without RMI

Let’s compare the pseudo-code of a client using RMI to the pseudo-code of a client NOT using RMI.

The client without RMI

public void goClient() {

  try {
     // get a new Socket

     // get an OutputStream
     // chain it to an ObjectOutputStream

     // send an opcode & op arguments
     // flush OS

     // get the InputStream
     // chain it to an ObjectInputStream

     // read the return value and/or
     // handle exceptions

     // close stuff

  } // catch and handle remote exceptions
}

The client with ...

Get Head First Servlets and JSP, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.