Last modified: "March 21, 2015 17:48:54 by mevett"

Running an RMI Program

The following instructions are for running the RMI-based implementation of the Producer-Consumer problem in chapter 15 of Silberschatz's textbook.  We'll assume there are two host machines, though things will work just fine if you run two different JVMs on the same machine.  In this case, you can think of each JVM as a "host". One host will run the MessageQueue, the other will run a producer and a consumer. The MessageQueue acts as a server to its clients, the producers and consumers.
 
  1. Compile all Java source files on both hosts.  The resulting .class files must exist on both hosts.
  2. [Only if you have a very old version of Java do you have to do this: On both hosts, prepare the skeleton and stub files. To do this, from DOS prompt:  rmic MessageQueueImpl]
  3. Run the RMI registry on the Queue host.
    1. On a Windows machine from DOS prompt:  start rmiregistry  (this will fork off another DOS window, running the rmiregistry.  The new DOS window will remain empty.)
    2. On a unix box (including a Mac), from the command line prompt: rmiregistry &. It may help to do this from within the same directory (let's refer to it as "DIR") that you will be running the MessageQueueImpl class.
  4. Create a permissions file. Here is a fairly elaborate permission file, Here is a simpler, but more dangerous one.
  5. (More dangerous in the sense that it leaves your machine open to certain net-based attacks during the lifetime of the MessageQueueImpl thread.) For simplicity's sake, keep your permissions file in the same directory as your .class files.
  6. On the Queue host (the remote machine), create the remote object (the message queue).  From a console/terminal prompt (and while in directory DIR): java -Djava.security.policy=permit.txt MessageQueueImpl
  7. On the producer/consumer host (the local machine), create a Factory. This will create a producer and a consumer client. These, in turn, will access the message queue via RMI.  To do this, from a console/terminal prompt: java -Djava.security.policy=permit.txt Factory
  8. At this point, you should see output appear steadily on the Queue host's console window. The Queue will print a message each time an element is consumed or produced, along with the number of elements currently remaining in the queue.