Information Technology Reference
In-Depth Information
RMI Code
RemoteJ DDL
public
class
Bank
extends
UnicastRemoteObject
implements
IBank {
private
double balance;
import
java.rmi.*;
import
evaluation.bank.*;
service
BankService {
public
Bank() throws RemoteException { }
protocol
: rmi {
options {
public
static void main(String[] args) {
if
(System.getSecurityManager() == null) {
System.setSecurityManager(
new
RMISecurityManager());
}
try
{
Bank obj =
new
Bank();
Naming.rebind("//localhost/Bank", obj);
}
catch
(Exception e) {
e.printStackTrace();
}
}
public
void
debit(
double
amount)
throws
RemoteException {
balance -= amount;
}
public
void
credit(
double
amount)
throws
RemoteException {
balance += amount;
}
public
void
create()
throws
RemoteException {
balance = 0;
}
public
void
open()
throws
RemoteException {
// open balance file
}
public
void
close()
throws
RemoteException {
// close balance file
}
public
double
getBalance()
throws
RemoteException {
return balance;
}
}
registryName = "RMITestServer";
registryHost = "localhost";
registryPort = 1099;
hosts = "localhost,bookworm,bookpro";
runEmbeddedRegistry = true;
}
pointcut
void
Bank.debit(
double
) {
recovery = nextServer;
}
pointcut
void
Bank.credit(
double
) {
recovery = nextServer;
}
pointcut
void
Bank.create() {
recovery = nextServer;
}
pointcut
void
Bank.open() {
recovery = nextServer;
}
pointcut
void
Bank.close() {
recovery = nextServer;
}
pointcut
double
Bank.getBalance() {
recovery = nextServer;
}
}
}
public
interface
IBank
extends
Remote {
public
void
debit(
double
amount)
throws
RemoteException;
public void
credit(
double
amount)
throws
RemoteException;
public void
create()
throws
RemoteException;
public
void
open()
throws
RemoteException;
public
void
close()
throws
RemoteException;
public
double
getBalance()
throws
RemoteException;
}
Figure 6.6. The Bank class converted to implement the RMI
protocol on the left with the DDL that is required to provide the
same functionality on the right.
that are to be exported must be defined in an interface that extends the
Remote
interface and the class where the methods are defined must implement the inter-
face. All methods in the interface and the class must be declared to throw the
RemoteException
exception.
It should be noted that this example contains no recovery code.
Search WWH ::
Custom Search