Exemplo n.º 1
0
 public void msgRequestingBreak(WaiterAgent w) {
   print("Received msgRequestingBreak");
   synchronized (waiters) {
     for (MyWaiter mw : waiters) {
       if (mw.waiter == w) {
         mw.state = waiterState.requestingBreak;
       }
     }
   }
   stateChanged();
 }
Exemplo n.º 2
0
 public void msgImBack(WaiterAgent w) {
   print("Received msgImBack");
   synchronized (waiters) {
     for (MyWaiter mw : waiters) {
       if (mw.waiter == w) {
         mw.state = waiterState.working;
       }
     }
   }
   stateChanged();
 }
Exemplo n.º 3
0
 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();
 }