private void signOffBreak(MyWaiter mw) { int numWorkingWaiters = 0; for (MyWaiter w : waiters) { numWorkingWaiters = (w.state != waiterState.onBreak) ? ++numWorkingWaiters : --numWorkingWaiters; } if (waiters.size() <= 1 || numWorkingWaiters < 1) { print("No break allowed"); mw.waiter.msgNoBreak(); mw.state = waiterState.working; } else { print("Break is allowed."); mw.waiter.msgYesBreak(); mw.state = waiterState.onBreak; } // stateChanged(); }
public void msgRequestingBreak(WaiterAgent w) { print("Received msgRequestingBreak"); synchronized (waiters) { for (MyWaiter mw : waiters) { if (mw.waiter == w) { mw.state = waiterState.requestingBreak; } } } stateChanged(); }
public void msgImBack(WaiterAgent w) { print("Received msgImBack"); synchronized (waiters) { for (MyWaiter mw : waiters) { if (mw.waiter == w) { mw.state = waiterState.working; } } } stateChanged(); }