1 | package com.hammurapi.eventbus.tests.fastfood; |
2 | |
3 | import java.util.Random; |
4 | |
5 | import com.hammurapi.eventbus.local.LocalEventBus; |
6 | |
7 | public class Cashier extends Thread { |
8 | |
9 | private LocalEventBus<Object, ?, ?> bus; |
10 | private final int numberOfOrders; |
11 | private Random random; |
12 | |
13 | public Cashier(int numberOfOrders, LocalEventBus<Object, ?, ?> eventBus) { |
14 | this.bus = eventBus; |
15 | this.numberOfOrders = numberOfOrders; |
16 | this.random = new Random(System.currentTimeMillis()+this.hashCode()); |
17 | } |
18 | |
19 | @Override |
20 | public void run() { |
21 | try { |
22 | for (int i=0; i<numberOfOrders; ++i) { |
23 | Class<? extends MainDish> mainDishType = random.nextBoolean() ? Hamburger.class : Cheeseburger.class; |
24 | Class<? extends SideDish> sideDishType = random.nextBoolean() ? FrenchFries.class : Coleslaw.class; |
25 | bus.post(new Order(mainDishType, sideDishType)); |
26 | Thread.sleep(random.nextInt(100)); |
27 | } |
28 | } catch (Exception e) { |
29 | e.printStackTrace(); |
30 | } |
31 | } |
32 | } |