Methods Summary |
---|
private boolean | becomeOwner()
String clientHost = wrapperAroundGetClientHost();
if (null != _currentClient) {
if (_currentClient.equals(clientHost)) {
return true;
}
} else {
_currentClient = clientHost;
return true;
}
return false;
|
private void | checkAccess()
String clientHost = wrapperAroundGetClientHost();
if ((null != _currentClient) && (_currentClient.equals(clientHost))) {
return;
}
throw new LockedAccountException();
|
private void | checkForNegativeAmount(Money amount)
int cents = amount.getCents();
if (0 > cents) {
throw new NegativeAmountException();
}
|
private void | checkForOverdraft(Money amount)
if (amount.greaterThan(_balance)) {
throw new OverdraftException(false);
}
return;
|
public synchronized Money | getBalance()
checkAccess();
return _balance;
|
public synchronized void | getLock()
if (false == becomeOwner()) {
throw new LockedAccountException();
}
return;
|
public synchronized void | makeDeposit(Money amount)
checkAccess();
checkForNegativeAmount(amount);
_balance.add(amount);
return;
|
public synchronized void | makeWithdrawal(Money amount)
checkAccess();
checkForNegativeAmount(amount);
checkForOverdraft(amount);
_balance.subtract(amount);
return;
|
public synchronized void | releaseLock()
String clientHost = wrapperAroundGetClientHost();
if ((null != _currentClient) && (_currentClient.equals(clientHost))) {
_currentClient = null;
}
|
private java.lang.String | wrapperAroundGetClientHost()
String clientHost = null;
try {
clientHost = getClientHost();
} catch (ServerNotActiveException ignored) {
}
return clientHost;
|