Chapter 5

Creating and Running a Registry Service

 

 

Universal TeacherRegistry Service

There are two ways to start a registry:

Use the RMI registry application (rmiregistry)
Use java.rmi.registry package to write your own registry service.

This chapter shows you how to write and start your own registry service. The source code needed for this example is stored in the examples\Register directory. The "Register" directory contains the following files:

  • RegisterInterface.java
  • RegisterServerImpl.java
  • RegisterClient.java
  • Compile.bat
  • Rmicompile.bat
  • RunServer.bat
  • RunClient.bat

The design of the server is very simple. The server stores the names of the users in a file. A user can register and view the names of already registered users.


Remote Interface

Just as in the last example, you must create an interface that extends the Remote interface.

Listing 5.1 RegisterInterface.java

import java.rmi.*;
import java.io.*;

//server interface
public interface RegisterInterface extends Remote {
	
   //method used to register a user. 
   //This method gets the name of the user as parameter.
   public String register(String name)
	throws RemoteException,IOException;
	
   //method used to show the list of users
   public String getList()
         throws RemoteException,IOException;
}

The interface declares two methods: The first method register() stores the names of users in a file named "regfile.txt" and the getList() method returns a list of already registered users.

 

 

 

RMI BOOK MAIN PAGE                Top

  
Copyright © 2001 www.universalteacher.com