1 package at.ac.tuwien.sbc.valesriegler.common;
4 import java.util.Collections;
5 import java.util.HashMap;
8 import java.util.Random;
10 import org.mozartspaces.capi3.Coordinator;
11 import org.mozartspaces.core.Capi;
12 import org.mozartspaces.core.ContainerReference;
13 import org.mozartspaces.core.MzsConstants.Container;
14 import org.mozartspaces.core.MzsConstants.RequestTimeout;
15 import org.mozartspaces.core.MzsCoreException;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
19 public abstract class Util {
20 private static final Logger log = LoggerFactory.getLogger(Util.class);
22 // TODO: solve the switch between mom by command-line arguments
23 public static boolean useJMS = true;
25 public static final String TABLE_ASSIGNED = "tables";
26 public static final String GROUPS_CONTAINER = "groups";
27 public static final String ASSIGN_TABLE = "assignTable";
28 public static final String TAKE_ORDER = "takeOrder";
29 public static final String ORDER_TAKEN = "order";
30 public static final String DELIVER_PIZZAS = "deliverPizzas";
31 public static final String PREPARE_PIZZAS = "preparePizzas";
32 public static final String PIZZAS_IN_PROGRESS = "pizzasInProgress";
33 public static final String ORDER_COMPLETE = "orderComplete";
34 public static final String PAYMENT_REQUEST = "payment";
35 public static final String FREE_TABLES = "freeTables";
36 public static final String IS_EATING = "isEating";
37 public static final String PAYMENT_DONE = "hasPaid";
38 public static final String INFO = "info";
40 private static Random random = new Random();
42 public static final long SPACE_TRANSACTION_TIMEOUT = 1500;
44 public static final String SERVER_ADDR = "xvsm://localhost:9876";
46 public static final String JMS_CONNECTSTRING = "tcp://localhost:61616?jms.prefetchPolicy.all=1";
48 public static String getId(int id) {
49 return (id != 0 && id != -1) ? String.valueOf(id) : "";
52 public static int getIntSafe(Integer nr) {
53 return nr == null ? 0 : nr;
56 public static <T extends HasId> Map<Integer, T> intoMapById(List<T> hasIds) {
58 return Collections.emptyMap();
61 Map<Integer, T> myMap = new HashMap<>();
62 for (T hasId : hasIds) {
63 myMap.put(hasId.getId(), hasId);
68 public static int getRandom(int min, int max) {
69 return random.nextInt(max - min + 1) + min;
72 public static int parseId(String[] args, String usage) {
73 if (args.length != 1) {
74 throw new IllegalArgumentException(usage);
79 parsedId = Integer.parseInt(args[0]);
80 } catch (NumberFormatException e) {
81 throw new IllegalArgumentException(usage);