This repository has been archived by the owner on Nov 30, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
BankGuardRole
Matthew Pohlmann edited this page Jan 1, 2014
·
1 revision
####Description Role inside of the bank that is responsible for escorting customers to tellers, defending the bank against robbers, and escorting customers out of the bank at closing time.
####Class Signature
public class BankGuardRole extends Role implements BankGuard {}
####Data
Queue<BankCustomerRole> waitingCustomers;
List<BankTellerRole> bankTellers;
####Scheduler
if Ǝ BankCustomerRole cust in waitingCustomers && Ǝ BankTellerRole teller in bankTellers ∋ teller.state == TellerState.UNOCCUPIED then,
escortToTeller(cust, teller);
if Bank.getOpen == false then, // May not need this rule if we just allow customers to finish up
escortCustomersOut();
####Messages
public void msgHereToSeeTeller(BankCustomerRole customer) {
// Add customer to queue
waitingCustomers.add(customer);
stateChanged();
}
public void msgDoneWithCustomer(BankTellerRole teller) {
stateChanged();
}
####Actions
private void escortToTeller(cust, teller) {
waitingCustomers.peek().msgGoToTeller(teller);
waitingCustomers.remove();
}
private void escortCustomersOut(cust, teller) {
for (BankCustomerRole cust : waitingCustomers) {
waitingCustomers.peek().msgLeaveBank(cust);
waitingCustomers.remove();
}
}