Designing RMI Applications

Ensure Data Integrity

import java.rmi.*;
import java.rmi.server.*;

public class Account_Impl extends UnicastRemoteObject implements Account {
  private Money _balance;

  public synchronized Money getBalance()
    throws RemoteException {
    return _balance;
  }

  public synchronized void makeDeposit(Money amount)
    throws RemoteException, NegativeAmountException {
    checkForNegativeAmount(amount);
    _balance.add(amount);
    return;
  }

  public synchronized void makeWithdrawal(Money amount)
    throws RemoteException, OverdraftException, NegativeAmountException {
    checkForNegativeAmount(amount);
    checkForOverdraft(amount);
    _balance.subtract(amount);
    return;
  }
}


José M. Vidal .

33 of 49