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 RMI

public void goClient() {

  try {

     // lookup the remote object (stub)

     // call the remote object's method

  } // catch and handle remote exceptions
}


[15] If you aren’t really familiar with RMI, drive to your local bookstore, pick up (but don’t buy) a copy of Head First Java, and just read the sections on RMI. Then put the book back on the shelf, face forward, in front of the competing book of your choice. Make sure that the cover is dusted and don’t spill coffee on it.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset