FileDocCategorySizeDatePackage
Account_Impl.javaAPI DocExample3067Thu Nov 08 00:22:52 GMT 2001com.ora.rmibook.chapter15.bank

Account_Impl

public class Account_Impl extends UnicastRemoteObject implements Account

Fields Summary
private static final int
TIMER_DURATION
private Money
_balance
private String
_currentClient
private int
_timeLeftUntilLockIsReleased
Constructors Summary
public Account_Impl(Money startingBalance)


      
          
        _balance = startingBalance;
        _timeLeftUntilLockIsReleased = 0;
        (Account_Impl_LockThread.getSingleton()).addAccount(this);
        //	register with the lock-expiration thread
    
Methods Summary
private voidcheckAccess(java.lang.String clientIDNumber)

        if (null == _currentClient) {
            _currentClient = clientIDNumber;
        } else {
            if (!_currentClient.equals(clientIDNumber)) {
                throw new LockedAccountException();
            }
        }
        resetCounter();
        return;
    
private voidcheckForNegativeAmount(Money amount)

        int cents = amount.getCents();

        if (0 > cents) {
            throw new NegativeAmountException();
        }
    
private voidcheckForOverdraft(Money amount)

        if (amount.greaterThan(_balance)) {
            throw new OverdraftException(false);
        }
        return;
    
protected synchronized voiddecrementLockTimer(int amountToDecrement)

        _timeLeftUntilLockIsReleased -= amountToDecrement;
        if (_timeLeftUntilLockIsReleased < 0) {
            _currentClient = null;
        }
    
public synchronized MoneygetBalance(java.lang.String clientIDNumber)

        checkAccess(clientIDNumber);
        return _balance;
    
public synchronized voidmakeDeposit(java.lang.String clientIDNumber, Money amount)

        checkAccess(clientIDNumber);
        checkForNegativeAmount(amount);
        _balance = _balance.add(amount);
        return;
    
public synchronized voidmakeWithdrawal(java.lang.String clientIDNumber, Money amount)

        checkAccess(clientIDNumber);
        checkForNegativeAmount(amount);
        checkForOverdraft(amount);
        _balance = _balance.subtract(amount);
        return;
    
private voidresetCounter()

        _timeLeftUntilLockIsReleased = TIMER_DURATION;
    
private java.lang.StringwrapperAroundGetClientHost()

        String clientHost = null;

        try {
            clientHost = getClientHost();
        } catch (ServerNotActiveException ignored) {
        }
        return clientHost;