Since the server process and the RMI registry will continue to run indefi nitely after
the client process has fi nished, they will need to be closed down by entering Ctrl-C
in each of their windows.
Now that the basic process has been covered, the next section will examine a
more realistic application of RMI.
Using RMI Meaningfully
In a realistic RMI application, multiple methods and probably multiple objects will
be employed. With such real-world applications, there are two possible strategies
that may be adopted, as described below.
Use a single instance of the implementation class to hold instance(s) of a class
whose methods are to be called remotely. Pass instance(s) of the latter class as
argument(s) of the constructor for the implementation class.
Use the implementation class directly for storing required data and methods,
creating instances of this class, rather than using separate class(es).
Some authors use the fi rst strategy, while others use the second. Each approach has
its merits and both will be illustrated below by implementing the same application, so
that the reader may compare the two techniques and choose his/her own preference.
This application will make bank account objects available to connecting clients,
which may then manipulate these remote objects by invoking their methods. For
simplicity's sake, just four account objects will be created and the practical consid-
erations relating to security of such accounts will be ignored completely!
Each of the above two methods will be implemented in turn…
Instance variables and associated methods for an individual account will be encap-
sulated within an application class called Account . If this class does not already
exist, then it must be created, adding a further step to the four steps specifi ed in
Sect. 5.2 . This step will be inserted as step 3 in the description below.
1. Create the interface.
Our interface will be called Bank1 and will provide access to details of all accounts
via method getBankAccounts . This method returns an ArrayList of Account objects
that will be declared within the implementation class. The code is shown below:
public interface Bank1 extends Remote
public ArrayList<Account> getBankAccounts()