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.
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.
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);
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, start the registry (command line) and change the registerToRegistry
arguments.
See also | |
---|---|
Generating a Server-side File
Compiling a Server File |