]> git.somenet.org - pub/jan/sbc.git/blob - src/main/java/at/ac/tuwien/sbc/valesriegler/xvsm/waiter/Waiter.java
Waiter listens for free tables and for new guests. When a table gets free he tries...
[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.XVSMConnector;
20
21 /**
22  * This is a waiter using XVSM
23  * 
24  * @author Gregor Riegler <gregor DOT riegler AT gmail DOT com>
25  * 
26  */
27 public class Waiter implements Serializable {
28         private static final String USAGE = "Waiter needs exactly one parameter: ID of type Integer";
29         private static final Logger log = LoggerFactory.getLogger(Waiter.class);
30
31         private int id;
32         private XVSMConnector xvsm;
33
34         public static void main(String[] args) {
35                 if (args.length != 1) {
36                         throw new IllegalArgumentException(USAGE);
37                 }
38
39                 int parsedId = 0;
40                 try {
41                         parsedId = Integer.parseInt(args[0]);
42                 } catch (NumberFormatException e) {
43                         log.error(USAGE);
44                         return;
45                 }
46
47                 Waiter waiter = new Waiter(parsedId);
48                 waiter.start();
49         }
50
51         private void start() {
52                 xvsm = new XVSMConnector();
53                 xvsm.initSpaceCommunication();
54                 
55                 xvsm.useFreeTablesContainer();
56                 xvsm.useAssignTableContainer();
57                 xvsm.useTablesContainer();
58                 xvsm.useTakeOrderContainer();
59                 
60                 // when new guests arrive the waiter should try to assign a table to them
61                 xvsm.listenForNewGuests();
62                 
63                 // when tables get free the waiter should have a look if there are waiting guests and assign the new table to them
64                 xvsm.listenForFreeTable();
65
66         }
67
68
69         public Waiter(int id) {
70                 this.id = id;
71                 log.info("I AM A WAITER WITH ID {}", id);
72         }
73
74 }