001 package com.hammurapi.eventbus.tests.fastfood;
002
003 import java.util.Random;
004
005 import com.hammurapi.eventbus.local.LocalEventBus;
006
007 public class Cashier extends Thread {
008
009 private LocalEventBus<Object, ?, ?> bus;
010 private final int numberOfOrders;
011 private Random random;
012
013 public Cashier(int numberOfOrders, LocalEventBus<Object, ?, ?> eventBus) {
014 this.bus = eventBus;
015 this.numberOfOrders = numberOfOrders;
016 this.random = new Random(System.currentTimeMillis()+this.hashCode());
017 }
018
019 @Override
020 public void run() {
021 try {
022 for (int i=0; i<numberOfOrders; ++i) {
023 Class<? extends MainDish> mainDishType = random.nextBoolean() ? Hamburger.class : Cheeseburger.class;
024 Class<? extends SideDish> sideDishType = random.nextBoolean() ? FrenchFries.class : Coleslaw.class;
025 bus.post(new Order(mainDishType, sideDishType));
026 Thread.sleep(random.nextInt(100));
027 }
028 } catch (Exception e) {
029 e.printStackTrace();
030 }
031 }
032 }