University of Cincinnati logo and link  
Setting Up Remote Method Invocation
 
  UC ingot As a proof of concept for RMI at Fifth Third Bank, I wrote a quick and dirty RMI chat program.  This program had a number of advantages, but unfortunately the proof of concept went nowhere.  Anyway, here are some of the steps we can take to build a chat application with RMI.
    • First, let's think in terms of interfaces.  If you have used interfaces before, you're one step ahead.  If you have not used interfaces, this is a good time to see where interfaces are important.
    • We'll want to define all of our methods in this interface.  So what methods might we want?
      • public void login(String user, String password) to login a user.
      • public void sendMessage(String message, String user) to send a message to a user.
      • We can add more as we desire, such as public void beep(String user) to alert a user to a message.
    • Let's call the interface Chat.
  • A few things we need to know about this interface.
    • It must extend Remote.  Wait a minute, this is an interface, is it not?  Sure enough, interfaces may extend other interfaces.
      • Curiously, you may note that this interface does not have any constants or methods.  That's because it is simply a marker for a class taht can be called remotely.  That's all it really is, just a flag.
    • Each method must declare throws RemoteException.  A RemoteException is thrown if a problem exists in the network communication.
      • In prior versions of the JDK, this was a simple extension of  class IOException.  But it has been enhanced with the getCause() method, which returns a Throwable object representing the original cause of the exception.
      • There are quite a few subclasses of RemoteException as well.  See the JavaDoc for details.
  • The client will use this interface to communicate with the proxy.  Similarly, the server class will implement this interface.  That way, we know that methods we call in the stub will be available in the server.
 Making the Server Class