]> git.somenet.org - pub/jan/sbc.git/blob - src/main/java/at/ac/tuwien/sbc/valesriegler/xvsm/waiter/Waiter.java
Space cook listens for pizza requests
[pub/jan/sbc.git] / src / main / java / at / ac / tuwien / sbc / valesriegler / xvsm / waiter / Waiter.java
1 package at.ac.tuwien.sbc.valesriegler.xvsm.waiter;
2
3 import java.io.Serializable;
4 import java.util.ArrayList;
5 import java.util.List;
6
7 import javax.swing.SwingUtilities;
8
9 import org.mozartspaces.core.Entry;
10 import org.mozartspaces.notifications.Notification;
11 import org.mozartspaces.notifications.NotificationListener;
12 import org.mozartspaces.notifications.Operation;
13 import org.slf4j.Logger;
14 import org.slf4j.LoggerFactory;
15
16 import at.ac.tuwien.sbc.valesriegler.pizzeria.PizzeriaAgent;
17 import at.ac.tuwien.sbc.valesriegler.types.GroupData;
18 import at.ac.tuwien.sbc.valesriegler.types.Table;
19 import at.ac.tuwien.sbc.valesriegler.xvsm.WaiterXVSM;
20 import at.ac.tuwien.sbc.valesriegler.xvsm.XVSMConnector;
21
22 /**
23  * This is a waiter using XVSM
24  * 
25  * @author Gregor Riegler <gregor DOT riegler AT gmail DOT com>
26  * 
27  */
28 public class Waiter implements Serializable {
29         private static final String USAGE = "Waiter needs exactly one parameter: ID of type Integer";
30         private static final Logger log = LoggerFactory.getLogger(Waiter.class);
31
32         private int id;
33         private WaiterXVSM xvsm;
34
35         public static void main(String[] args) {
36                 if (args.length != 1) {
37                         throw new IllegalArgumentException(USAGE);
38                 }
39
40                 int parsedId = 0;
41                 try {
42                         parsedId = Integer.parseInt(args[0]);
43                 } catch (NumberFormatException e) {
44                         log.error(USAGE);
45                         return;
46                 }
47
48                 Waiter waiter = new Waiter(parsedId);
49                 waiter.start();
50         }
51
52         private void start() {
53                 xvsm = new WaiterXVSM(id);
54                 
55                 xvsm.listenForOrders();
56                 
57                 // when new guests arrive the waiter should try to assign a table to them
58                 xvsm.listenForNewGuests();
59                 
60                 // when tables get free the waiter should have a look if there are waiting guests and assign the new table to them
61                 xvsm.listenForFreeTable();
62                 
63                 
64
65         }
66
67
68         public Waiter(int id) {
69                 this.id = id;
70                 log.info("I AM A WAITER WITH ID {}", id);
71         }
72
73 }