FileDocCategorySizeDatePackage
Account3_Impl.javaAPI DocExample3453Thu Nov 08 00:22:34 GMT 2001com.ora.rmibook.chapter12.bank

Account3_Impl

public class Account3_Impl extends UnicastRemoteObject implements Account3

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


      
          
        _balance = startingBalance;
        _timeLeftUntilLockIsReleased = 0;
        new Thread(new CountDownTimer()).start();
    
Methods Summary
private voidcheckAccess()

        String clientHost = wrapperAroundGetClientHost();

        if (null == _currentClient) {
            _currentClient = clientHost;
        } else {
            if (!_currentClient.equals(clientHost)) {
                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;
    
public synchronized MoneygetBalance()

        checkAccess();
        return _balance;
    
public synchronized voidmakeDeposit(Money amount)

        checkAccess();
        checkForNegativeAmount(amount);
        _balance.add(amount);
        return;
    
public synchronized voidmakeWithdrawal(Money amount)

        checkAccess();
        checkForNegativeAmount(amount);
        checkForOverdraft(amount);
        _balance.subtract(amount);
        return;
    
private voidreleaseLock()

        if (null != _currentClient) {
            _currentClient = null;
        }
    
private voidresetCounter()

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

        String clientHost = null;

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