@Override public void run() { try { while (this.loggedIn()) { DataPacket packet = new DataPacket(Function.CREATE_RANDOM_ORDER); packet.cashier = this; packet = this.communicateWithServer(packet); if (packet == null) continue; this.addOrder(packet.order); int sleepAmount = (Utils.generateRandomNumber(4) + 3) * 1000; try { Thread.sleep(sleepAmount); } catch (InterruptedException e) { } // poll the order manager for any undelivered orders floating about DataPacket undeliveredOrderPacket = new DataPacket(Function.GET_UNDELIVERED_ORDER); DataPacket undeliveredOrderReturnPacket = this.communicateWithServer(undeliveredOrderPacket); if (undeliveredOrderReturnPacket.order != null) this.deliverOrder(undeliveredOrderReturnPacket.order); } } catch (Exception e) { System.out.println("Cashier.run: Error exception " + e.getMessage()); } }
@Override public void logOut() { // let the server know the cashier's logged in DataPacket packet = new DataPacket(Function.EMPLOYEE_LOG_OUT); packet.cashier = this; packet = this.communicateWithServer(packet); super.logOut(); }