]> git.somenet.org - pub/jan/sbc.git/blob - src/main/java/at/ac/tuwien/sbc/valesriegler/xvsm/waiter/Waiter.java
implemented Workflow to "ordered", where the cook has pizzas to cook and another...
[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.List;
5
6 import org.mozartspaces.core.MzsCoreException;
7 import org.slf4j.Logger;
8 import org.slf4j.LoggerFactory;
9
10 import at.ac.tuwien.sbc.valesriegler.DEP_Table;
11 import at.ac.tuwien.sbc.valesriegler.xvsm.XVSMConnector;
12
13 /**
14  * This is a waiter using XVSM
15  * 
16  * @author Gregor Riegler <gregor DOT riegler AT gmail DOT com>
17  *
18  */
19 public class Waiter implements Serializable {
20         private static final String USAGE = "Waiter needs exactly one parameter: ID of type Integer";
21         private static final Logger log = LoggerFactory.getLogger(Waiter.class);
22         
23         private int id;
24         private XVSMConnector xvsm;
25
26         public static void main(String[] args) {
27                 if(args.length != 1) {
28                         throw new IllegalArgumentException(USAGE);
29                 }
30                 
31                 int parsedId = 0;
32                 try {
33                         parsedId = Integer.parseInt(args[0]);
34                 } catch (NumberFormatException e) {
35                         log.error(USAGE);
36                         return;
37                 }
38                 
39                 Waiter waiter = new Waiter(parsedId);
40                 waiter.start();
41         }
42
43         private void start() {
44                 initSpaceCommunication();
45                 
46                 List<DEP_Table> tables = xvsm.readTables();
47                 
48                 log.info("Number of free tables received: {}", tables.size());
49                 
50         }
51         
52         private void initSpaceCommunication() {
53                 try {
54                         xvsm = new XVSMConnector();
55                         xvsm.initSpaceCommunication();
56                 } catch (MzsCoreException e) {
57                         log.error(e.getMessage());
58                         log.error("The Waiter has no Space connection! Have you started the Space Server?");
59                         System.exit(1);
60                 }
61                 
62                 log.info("Space Connection established!");
63                 
64                 
65         }
66
67         public Waiter(int id) {
68                 this.id = id;
69                 log.info("I AM A WAITER WITH ID {}", id);
70         }
71
72 }
73