FileDocCategorySizeDatePackage
Account3_Impl2.javaAPI DocExample3035Thu Nov 08 00:22:48 GMT 2001com.ora.rmibook.chapter13.bank

Account3_Impl2

public class Account3_Impl2 extends UnicastRemoteObject implements Account3

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


      
          
        _balance = startingBalance;
        _timeLeftUntilLockIsReleased = 0;
        (Account3_Impl2_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 MoneygetBalance(java.lang.String clientIDNumber)

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

        checkAccess(clientIDNumber);
        checkForNegativeAmount(amount);
        _balance = _balance.add(amount);
        return;
    
public 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;