Information Technology Reference
In-Depth Information
public class Bank {
private double balance;
public BankServer() {
}
public void debit(double amount) {
balance =amount;
}
public void credit(double amount) {
balance += amount;
}
public void create() {
balance = 0;
}
public void open() {
// open balance file
}
public void close() {
// close balance file
}
public double getBalance() {
return balance;
}
}
Figure 6.5.
Bank class.
proach for the RMI, REST and JMS protocols and then converting them using
the RemoteJ compiler/generator and associated DDL files.
6.3.1
Bank Example
In this section we define a simple bank application and convert it to a distributed
application using the RMI protocol. We then convert it using the RemoteJ com-
piler/generator and compare the different approaches.
Our bank application consists of the single class, Bank , illustrated in Fig-
ure 6.5. The class consists of six methods that we wish to make remote using the
RMI protocol.
To convert the above application into an RMI application, we firstly need to
define an interface containing the remote methods we wish to define as distributed.
We then alter the Bank class to extend the UnicastRemoteObject class and
implement the IBank interface. Our converted class and interface is illustrated
in Figure 6.6 on the left-hand side with the shaded areas illustrating the changes
that needed to be made to the class to implement the RMI protocol. Note that
in order to illustrate the requirements for exporting the remote object to the RMI
registry we have added a main method.
As can be seen from the example, the RMI protocol requires developer's
to adhere to both a coding convention as well as a framework.
The methods
Search WWH ::




Custom Search