Completing Server-side Files

The RMI module generates implementation classes that are complete except for the business logic. In addition, the generated implementation classes contain code that will register an instance of the class with an RMI registry running at //localhost:1099/. If you want to register your server in another registry you need to modify this code.

Adding Business Logic to an Implementation Class

Look for the method bodies that were generated for the methods declared in the remote interface. Add whatever code is needed to provide the functionality specified in the method signature.

If your business logic is complex, consider implementing some of it in private methods that are not declared in the remote interface, or even in additional classes.

Changing Code that Specifies the Binding Name

The default behavior of a generated implementation class is to create an instance of itself and bind that instance to a registry under the class name. For example, if you begin with an interface named Hello, the RMI module generates an implementation class named HelloImpl, and the default binding behavior is determined by the following code:

HelloImpl obj = new HelloImpl ();
registerToRegistry("HelloImpl", obj, true);

To change the binding name, change the value of the first parameter. For example:

HelloImpl obj = new HelloImpl ();
registerToRegistry("HelloServer", obj, true);

Changing Code that Specifies the RMI Registry

The default behavior of a generated implementation class is to look for an RMI registry on the local machine at port 1099. If it does not find such a registry, it will create one and then bind the server instance.

The following code relies on this default behavior:

HelloImpl obj = new HelloImpl();
registerToRegistry("HelloImpl", obj, true);

Since the first parameter, name, does not specify host and port, these values default to //localhost:1099/ in the rebind call. If you want to register your server with some other registry, do the following:

  1. Start the registry (command line)

  2. Change the registerToRegistry arguments.

Compiling Your Server

The last step in completing server files is to compile all the classes related to the server, including the remote interface, together. Right-click the node for the RMI server class and select Compile from the contextual menu. Doing so also compiles the remote interface and generates the stub and skeleton files.
Legal Notices