The Files You Need for RMI Programs
The RMI module has an RMI wizard and several RMI templates. You can use
either tool to generate Java source files (.java files) for the different
parts of RMI programs. The kind of RMI program you are writing determines
the files you need to generate.
Remote Interface Files
This is a Java interface that extends java.rmi.Remote. The remote interface
defines the interface of an RMI server. It is compiled to create the stub
and skeleton files that allow client and server to communicate. On the
server side, you need a remote interface in the package with your implementation
class. On the client side, you need to know the method signatures
declared in the remote interface, because your client will be invoking
these methods.
The RMI module lets use an existing remote interface or write your own:
-
If you are writing a client program that will use RMI technology to access
an RMI server that someone else has already developed and deployed, you
will begin with a copy of the remote interface that declares the server-side
methods your client program can invoke.
-
If you are developing an RMI server or a complete RMI application, you
will probably begin by writing your own remote interface.
The RMI templates include a template named RemoteInterface that generates
a remote interface that you complete in the IDE's editing window. The RMI
wizard provides more support for writing a remote interface; it has buttons
that add interface elements in correct syntax.
Client-side Files
The files you need for a client-side program are:
-
A client class. You can generate a client class with the template named
"RMI_Client." After generating a client class, complete its main()
method by adding logic that looks up a reference to the RMI server from
an RMI registry and uses the reference to invoke server methods.
-
RMI technology makes it possible for the client program to obtain stub
files at run time, after it performs the registry lookup.
If you are writing a client program to access an existing RMI server, you
will need a copy of the remote interface, which contains method signatures
for the server-side methods your program can invoke.
Server-side Files
The files you need for a server-side program are:
-
An implementation class. This is called the implementation class because
it contains implementations of the methods declared in the remote interface.
These comprise the business logic that can be executed by clients.
The RMI module generates implementation classes that include their
own "startup" code. This means that they create instances of themselves,
export themselves and register themselves with an RMI registry. You can
generate an implementation class with either the RMI templates or the RMI
wizard.
After generating an implementation class, you need to write the business
logic. If your business logic is complex, you can supplement the public
methods declared in the remote interface with private methods that are
invoked by the declared remote methods.
-
The skeleton classes. These are generated when you compile the remote interface.
If you are using the RMI templates to generate you server-side files, you
should generate and complete a remote interface (or obtain a copy of an
existing interface) before generating the other server-side files. If you
are using the RMI Wizard, the wizard can help you write a remote interface.
Legal Notices