From 2fb6657d953205f5d3cd7b3e174729c6b531a949 Mon Sep 17 00:00:00 2001 From: Jan Vales Date: Mon, 6 May 2013 02:04:09 +0200 Subject: [PATCH] added some not really helpful class descriptions + removed types that got duplicated. TODO remaining: fix pizzeriagui! --- ...teTable.java => DEBUG_JMSCreateTable.java} | 14 ++- .../sbc/valesriegler/DEP_GroupDataMin.java | 30 ------ .../ac/tuwien/sbc/valesriegler/DEP_Order.java | 97 ------------------- .../ac/tuwien/sbc/valesriegler/DEP_Table.java | 39 -------- .../actions => common}/AbstractAction.java | 9 +- .../valesriegler/cook/actions/PizzaInfo.java | 8 +- .../messageListeners/CookRequestedPizza.java | 6 ++ .../group/AbstractGroupConnector.java | 2 +- .../tuwien/sbc/valesriegler/group/Group.java | 7 +- .../group/actions/OrderRequest.java | 7 ++ .../group/actions/OrderResponse.java | 7 ++ .../group/actions/PayRequest.java | 7 ++ .../group/actions/PayResponse.java | 7 ++ .../valesriegler/group/actions/TableFree.java | 7 ++ .../group/actions/TableRequest.java | 7 ++ .../group/actions/TableResponse.java | 7 ++ .../group/gui/GroupOverviewModel.java | 8 ++ .../group/jms/JMSGroupConnector.java | 6 +- .../pizzeria/AbstractPizzeriaConnector.java | 18 ++++ .../valesriegler/pizzeria/PizzeriaAgent.java | 10 +- .../pizzeria/actions/TableNew.java | 31 ++++++ .../pizzeria/gui/PizzeriaFrame.java | 58 +++++------ .../gui/tablemodels/GroupsOverviewModel.java | 23 ++--- .../gui/tablemodels/OrdersOverviewModel.java | 38 ++++---- .../gui/tablemodels/PizzasOfOrderModel.java | 8 +- .../tablemodels/TableModelOfSingleOrder.java | 14 +-- .../gui/tablemodels/TablesOverviewModel.java | 63 ++++++------ .../gui/tablemodels/WaitersOfOrderModel.java | 32 +++--- .../pizzeria/jms/JMSPizzeriaConnector.java | 92 ++++++++++++++++++ .../sbc/valesriegler/types/GroupState.java | 6 ++ .../tuwien/sbc/valesriegler/types/Order.java | 7 ++ .../sbc/valesriegler/types/OrderStatus.java | 6 ++ .../tuwien/sbc/valesriegler/types/Pizza.java | 6 ++ .../sbc/valesriegler/types/PizzaOrder.java | 6 ++ .../valesriegler/types/PizzaOrderStatus.java | 6 ++ .../sbc/valesriegler/types/PizzaType.java | 10 +- .../tuwien/sbc/valesriegler/types/Table.java | 28 ++++++ .../sbc/valesriegler/waiter/Waiter.java | 9 +- .../jms/messageListeners/WantToOrder.java | 6 ++ .../jms/messageListeners/WantToPay.java | 6 ++ .../messageListeners/WantToSitAtTable.java | 7 ++ .../sbc/valesriegler/xvsm/XVSMConnector.java | 23 +++-- .../sbc/valesriegler/xvsm/waiter/Waiter.java | 28 +++--- 43 files changed, 484 insertions(+), 332 deletions(-) rename src/main/java/at/ac/tuwien/sbc/valesriegler/{DEBUG_CreateTable.java => DEBUG_JMSCreateTable.java} (90%) delete mode 100644 src/main/java/at/ac/tuwien/sbc/valesriegler/DEP_GroupDataMin.java delete mode 100644 src/main/java/at/ac/tuwien/sbc/valesriegler/DEP_Order.java delete mode 100644 src/main/java/at/ac/tuwien/sbc/valesriegler/DEP_Table.java rename src/main/java/at/ac/tuwien/sbc/valesriegler/{group/actions => common}/AbstractAction.java (59%) create mode 100644 src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/AbstractPizzeriaConnector.java create mode 100644 src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/actions/TableNew.java create mode 100644 src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/jms/JMSPizzeriaConnector.java diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/DEBUG_CreateTable.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/DEBUG_JMSCreateTable.java similarity index 90% rename from src/main/java/at/ac/tuwien/sbc/valesriegler/DEBUG_CreateTable.java rename to src/main/java/at/ac/tuwien/sbc/valesriegler/DEBUG_JMSCreateTable.java index bfb941b..7adb57e 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/DEBUG_CreateTable.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/DEBUG_JMSCreateTable.java @@ -12,16 +12,22 @@ import org.slf4j.LoggerFactory; import at.ac.tuwien.sbc.valesriegler.types.PizzaType; import at.ac.tuwien.sbc.valesriegler.types.Table; -public class DEBUG_CreateTable { - private static final Logger log = LoggerFactory.getLogger(DEBUG_CreateTable.class); +/** + * a helper to generate Tables. + * + * @author jan + * + */ +public class DEBUG_JMSCreateTable { + private static final Logger log = LoggerFactory.getLogger(DEBUG_JMSCreateTable.class); private static int nextID = 0; final private int id; public static void main(String[] args) throws Exception { - new DEBUG_CreateTable(++nextID); + new DEBUG_JMSCreateTable(++nextID); } - public DEBUG_CreateTable(int id) { + public DEBUG_JMSCreateTable(int id) { this.id = id; log.info("I AM A DEBUG_CreateTable WITH ID {}", this.id); produce(PizzaType.CARDINALE); diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/DEP_GroupDataMin.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/DEP_GroupDataMin.java deleted file mode 100644 index c4e3f6b..0000000 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/DEP_GroupDataMin.java +++ /dev/null @@ -1,30 +0,0 @@ -package at.ac.tuwien.sbc.valesriegler; - -import java.io.Serializable; - -/** - * A group bean which only has an id and a size. - * - * @author Gregor Riegler - */ -@Deprecated -public class DEP_GroupDataMin implements Serializable { - private int id; - private int size; - - public int getId() { - return id; - } - - public void setId(int id) { - this.id = id; - } - - public int getSize() { - return size; - } - - public void setSize(int size) { - this.size = size; - } -} diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/DEP_Order.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/DEP_Order.java deleted file mode 100644 index c91789f..0000000 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/DEP_Order.java +++ /dev/null @@ -1,97 +0,0 @@ -package at.ac.tuwien.sbc.valesriegler; - -import java.util.List; - -import at.ac.tuwien.sbc.valesriegler.types.PizzaOrder; - -@Deprecated -public class DEP_Order { - private int id; - private int tableId; - private int groupId; - private OrderStatus status; - - enum OrderStatus { - ORDERED, PAID, DELIVERED - } - - private int waiterIdOfTableAssignment; - private int waiterIdOfOrder; - private int waiterIdOfServing; - private int waiterIdOfPayment; - - private List pizzaOrders; - - public int getId() { - return id; - } - - public void setId(int id) { - this.id = id; - } - - public int getTableId() { - return tableId; - } - - public void setTableId(int tableId) { - this.tableId = tableId; - } - - public int getGroupId() { - return groupId; - } - - public void setGroupId(int groupId) { - this.groupId = groupId; - } - - public OrderStatus getStatus() { - return status; - } - - public void setStatus(OrderStatus status) { - this.status = status; - } - - public int getWaiterIdOfTableAssignment() { - return waiterIdOfTableAssignment; - } - - public void setWaiterIdOfTableAssignment(int waiterIdOfTableAssignment) { - this.waiterIdOfTableAssignment = waiterIdOfTableAssignment; - } - - public int getWaiterIdOfOrder() { - return waiterIdOfOrder; - } - - public void setWaiterIdOfOrder(int waiterIdOfOrder) { - this.waiterIdOfOrder = waiterIdOfOrder; - } - - public int getWaiterIdOfServing() { - return waiterIdOfServing; - } - - public void setWaiterIdOfServing(int waiterIdOfServing) { - this.waiterIdOfServing = waiterIdOfServing; - } - - public int getWaiterIdOfPayment() { - return waiterIdOfPayment; - } - - public void setWaiterIdOfPayment(int waiterIdOfPayment) { - this.waiterIdOfPayment = waiterIdOfPayment; - } - - public List getPizzaOrders() { - return pizzaOrders; - } - - public void setPizzaOrders(List pizzaOrders) { - this.pizzaOrders = pizzaOrders; - } - -} diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/DEP_Table.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/DEP_Table.java deleted file mode 100644 index 4de9c66..0000000 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/DEP_Table.java +++ /dev/null @@ -1,39 +0,0 @@ -package at.ac.tuwien.sbc.valesriegler; - -import java.io.Serializable; - -@Deprecated -public class DEP_Table implements Serializable { - - private int id; - private TableStatus status; - private int groupId; - - public int getId() { - return id; - } - - public void setId(int id) { - this.id = id; - } - - public TableStatus getStatus() { - return status; - } - - public void setStatus(TableStatus status) { - this.status = status; - } - - public int getGroupId() { - return groupId; - } - - public void setGroupId(int groupId) { - this.groupId = groupId; - } - - public enum TableStatus { - FREE, OCCUPIED; - } -} diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/group/actions/AbstractAction.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/common/AbstractAction.java similarity index 59% rename from src/main/java/at/ac/tuwien/sbc/valesriegler/group/actions/AbstractAction.java rename to src/main/java/at/ac/tuwien/sbc/valesriegler/common/AbstractAction.java index 65744f8..87a6656 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/group/actions/AbstractAction.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/common/AbstractAction.java @@ -1,9 +1,16 @@ -package at.ac.tuwien.sbc.valesriegler.group.actions; +package at.ac.tuwien.sbc.valesriegler.common; import java.io.Serializable; import at.ac.tuwien.sbc.valesriegler.types.GroupData; +/** + * Abstract action that can be performed in the DS. In almost all cases the + * groupdata is relevant, it may be null in the few corner cases. + * + * @author jan + * + */ public abstract class AbstractAction implements Serializable { private final GroupData groupdata; diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/cook/actions/PizzaInfo.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/cook/actions/PizzaInfo.java index d8a5284..7ac85df 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/cook/actions/PizzaInfo.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/cook/actions/PizzaInfo.java @@ -2,9 +2,15 @@ package at.ac.tuwien.sbc.valesriegler.cook.actions; import java.io.Serializable; -import at.ac.tuwien.sbc.valesriegler.group.actions.AbstractAction; +import at.ac.tuwien.sbc.valesriegler.common.AbstractAction; import at.ac.tuwien.sbc.valesriegler.types.PizzaOrderStatus; +/** + * Inform Pizzaria of a Pizza-Event. + * + * @author jan + * + */ public class PizzaInfo extends AbstractAction implements Serializable { private final int pizzaId; private final PizzaOrderStatus status; diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/cook/jms/messageListeners/CookRequestedPizza.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/cook/jms/messageListeners/CookRequestedPizza.java index a6babf1..340486c 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/cook/jms/messageListeners/CookRequestedPizza.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/cook/jms/messageListeners/CookRequestedPizza.java @@ -19,6 +19,12 @@ import at.ac.tuwien.sbc.valesriegler.types.Pizza; import at.ac.tuwien.sbc.valesriegler.types.PizzaOrder; import at.ac.tuwien.sbc.valesriegler.types.PizzaOrderStatus; +/** + * Cook the requested pizza. + * + * @author jan + * + */ public class CookRequestedPizza implements MessageListener { private static final Logger log = LoggerFactory.getLogger(CookRequestedPizza.class); private final JMSCook cook; diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/group/AbstractGroupConnector.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/group/AbstractGroupConnector.java index 28c859c..a4b6f56 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/group/AbstractGroupConnector.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/group/AbstractGroupConnector.java @@ -1,6 +1,6 @@ package at.ac.tuwien.sbc.valesriegler.group; -import at.ac.tuwien.sbc.valesriegler.group.actions.AbstractAction; +import at.ac.tuwien.sbc.valesriegler.common.AbstractAction; /** * Abstract class to handle lower-level communication with other processes. diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/group/Group.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/group/Group.java index 94adccc..5b52d46 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/group/Group.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/group/Group.java @@ -12,7 +12,12 @@ import at.ac.tuwien.sbc.valesriegler.types.GroupState; import at.ac.tuwien.sbc.valesriegler.types.Order; import at.ac.tuwien.sbc.valesriegler.types.Table; -// class doing all the Group related work as required. +/** + * class denoting a Group's will. + * + * @author jan + * + */ public class Group implements Runnable { private static final Logger log = LoggerFactory.getLogger(Group.class); private static int idNext = -1; // TODO: set to 0 after debugging! diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/group/actions/OrderRequest.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/group/actions/OrderRequest.java index 532c604..e067674 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/group/actions/OrderRequest.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/group/actions/OrderRequest.java @@ -2,8 +2,15 @@ package at.ac.tuwien.sbc.valesriegler.group.actions; import java.io.Serializable; +import at.ac.tuwien.sbc.valesriegler.common.AbstractAction; import at.ac.tuwien.sbc.valesriegler.types.GroupData; +/** + * Indicate the interest to order pizzas + * + * @author jan + * + */ public class OrderRequest extends AbstractAction implements Serializable { public OrderRequest(GroupData groupdata) { super(groupdata); diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/group/actions/OrderResponse.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/group/actions/OrderResponse.java index 0a828af..27d4619 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/group/actions/OrderResponse.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/group/actions/OrderResponse.java @@ -2,8 +2,15 @@ package at.ac.tuwien.sbc.valesriegler.group.actions; import java.io.Serializable; +import at.ac.tuwien.sbc.valesriegler.common.AbstractAction; import at.ac.tuwien.sbc.valesriegler.types.GroupData; +/** + * response to the group's interest in pizza. + * + * @author jan + * + */ public class OrderResponse extends AbstractAction implements Serializable { private final int waiterId; diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/group/actions/PayRequest.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/group/actions/PayRequest.java index 978db73..0c0cd72 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/group/actions/PayRequest.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/group/actions/PayRequest.java @@ -2,8 +2,15 @@ package at.ac.tuwien.sbc.valesriegler.group.actions; import java.io.Serializable; +import at.ac.tuwien.sbc.valesriegler.common.AbstractAction; import at.ac.tuwien.sbc.valesriegler.types.GroupData; +/** + * indicate a groups interest to pay and leave. + * + * @author jan + * + */ public class PayRequest extends AbstractAction implements Serializable { public PayRequest(GroupData groupdata) { super(groupdata); diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/group/actions/PayResponse.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/group/actions/PayResponse.java index 40e4534..1129f1f 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/group/actions/PayResponse.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/group/actions/PayResponse.java @@ -2,8 +2,15 @@ package at.ac.tuwien.sbc.valesriegler.group.actions; import java.io.Serializable; +import at.ac.tuwien.sbc.valesriegler.common.AbstractAction; import at.ac.tuwien.sbc.valesriegler.types.GroupData; +/** + * response of paying. + * + * @author jan + * + */ public class PayResponse extends AbstractAction implements Serializable { private final int waiterId; diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/group/actions/TableFree.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/group/actions/TableFree.java index 3e3944e..d751c1b 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/group/actions/TableFree.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/group/actions/TableFree.java @@ -2,8 +2,15 @@ package at.ac.tuwien.sbc.valesriegler.group.actions; import java.io.Serializable; +import at.ac.tuwien.sbc.valesriegler.common.AbstractAction; import at.ac.tuwien.sbc.valesriegler.types.GroupData; +/** + * Leave table. + * + * @author jan + * + */ public class TableFree extends AbstractAction implements Serializable { public TableFree(GroupData groupdata) { super(groupdata); diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/group/actions/TableRequest.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/group/actions/TableRequest.java index 03195c6..f31d99e 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/group/actions/TableRequest.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/group/actions/TableRequest.java @@ -2,8 +2,15 @@ package at.ac.tuwien.sbc.valesriegler.group.actions; import java.io.Serializable; +import at.ac.tuwien.sbc.valesriegler.common.AbstractAction; import at.ac.tuwien.sbc.valesriegler.types.GroupData; +/** + * indicate interest to get a table to sitdown. + * + * @author jan + * + */ public class TableRequest extends AbstractAction implements Serializable { public TableRequest(GroupData groupdata) { super(groupdata); diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/group/actions/TableResponse.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/group/actions/TableResponse.java index c665274..24eaa24 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/group/actions/TableResponse.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/group/actions/TableResponse.java @@ -2,9 +2,16 @@ package at.ac.tuwien.sbc.valesriegler.group.actions; import java.io.Serializable; +import at.ac.tuwien.sbc.valesriegler.common.AbstractAction; import at.ac.tuwien.sbc.valesriegler.types.GroupData; import at.ac.tuwien.sbc.valesriegler.types.Table; +/** + * Response to the wish of getting a table to sitdown. + * + * @author jan + * + */ public class TableResponse extends AbstractAction implements Serializable { private final Table table; private final int waiterId; diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/group/gui/GroupOverviewModel.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/group/gui/GroupOverviewModel.java index 4d7e7a8..cb59622 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/group/gui/GroupOverviewModel.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/group/gui/GroupOverviewModel.java @@ -12,6 +12,14 @@ import at.ac.tuwien.sbc.valesriegler.group.Group; import at.ac.tuwien.sbc.valesriegler.types.PizzaOrder; import at.ac.tuwien.sbc.valesriegler.types.PizzaType; +/** + * Might not the nicest way to store global data, but this is an elemental + * Object, storing ALL the Group's data. Might consider splitting those two + * usecases apart. + * + * @author jan + * + */ public class GroupOverviewModel extends TableModel { private static final Logger log = LoggerFactory.getLogger(GroupOverviewModel.class); diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/group/jms/JMSGroupConnector.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/group/jms/JMSGroupConnector.java index 17f359e..42a3505 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/group/jms/JMSGroupConnector.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/group/jms/JMSGroupConnector.java @@ -14,10 +14,10 @@ import org.apache.activemq.ActiveMQConnectionFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import at.ac.tuwien.sbc.valesriegler.common.AbstractAction; import at.ac.tuwien.sbc.valesriegler.group.AbstractGroupConnector; import at.ac.tuwien.sbc.valesriegler.group.Group; import at.ac.tuwien.sbc.valesriegler.group.GroupAgent; -import at.ac.tuwien.sbc.valesriegler.group.actions.AbstractAction; import at.ac.tuwien.sbc.valesriegler.group.actions.OrderRequest; import at.ac.tuwien.sbc.valesriegler.group.actions.OrderResponse; import at.ac.tuwien.sbc.valesriegler.group.actions.PayRequest; @@ -43,8 +43,8 @@ public class JMSGroupConnector extends AbstractGroupConnector implements Message connection = new ActiveMQConnectionFactory("tcp://localhost:61616").createConnection(); connection.start(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); - MessageConsumer consWantToSit = session.createConsumer(session.createQueue("GroupConnector")); - consWantToSit.setMessageListener(this); + MessageConsumer consumer = session.createConsumer(session.createQueue("GroupConnector")); + consumer.setMessageListener(this); } catch (JMSException e) { log.error("EXCEPTION!", e); } diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/AbstractPizzeriaConnector.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/AbstractPizzeriaConnector.java new file mode 100644 index 0000000..5e87d6d --- /dev/null +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/AbstractPizzeriaConnector.java @@ -0,0 +1,18 @@ +package at.ac.tuwien.sbc.valesriegler.pizzeria; + +import at.ac.tuwien.sbc.valesriegler.common.AbstractAction; + +/** + * Abstract class to handle lower-level communication with other processes. + * + * @author jan + * + */ +public abstract class AbstractPizzeriaConnector { + public void init() { + } + + public void send(AbstractAction request) { + } + +} diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/PizzeriaAgent.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/PizzeriaAgent.java index 9350462..316125e 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/PizzeriaAgent.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/PizzeriaAgent.java @@ -8,13 +8,13 @@ import org.mozartspaces.core.MzsCoreException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import at.ac.tuwien.sbc.valesriegler.DEP_Table; import at.ac.tuwien.sbc.valesriegler.pizzeria.gui.PizzeriaFrame; import at.ac.tuwien.sbc.valesriegler.pizzeria.gui.tablemodels.GroupsOverviewModel; import at.ac.tuwien.sbc.valesriegler.pizzeria.gui.tablemodels.OrdersOverviewModel; import at.ac.tuwien.sbc.valesriegler.pizzeria.gui.tablemodels.PizzasOfOrderModel; import at.ac.tuwien.sbc.valesriegler.pizzeria.gui.tablemodels.TablesOverviewModel; import at.ac.tuwien.sbc.valesriegler.pizzeria.gui.tablemodels.WaitersOfOrderModel; +import at.ac.tuwien.sbc.valesriegler.types.Table; import at.ac.tuwien.sbc.valesriegler.xvsm.XVSMConnector; /** @@ -23,7 +23,7 @@ import at.ac.tuwien.sbc.valesriegler.xvsm.XVSMConnector; * Start the communication and the Pizzeria GUI * * @author Gregor Riegler - * + * @author jan */ public class PizzeriaAgent { private static final Logger log = LoggerFactory.getLogger(PizzeriaAgent.class); @@ -38,7 +38,7 @@ public class PizzeriaAgent { private XVSMConnector xvsm; - public static void main(String[] args) { + public static void main(String[] args) {// TODO: remove hardcoding of JMS. // if (args.length != 1) { // throw new IllegalArgumentException(USAGE); // } else { @@ -91,7 +91,7 @@ public class PizzeriaAgent { frame.setOnTablesCreatedHandler(new TablesCreatedHandler() { @Override - public void freeTablesCreated(List tables) { + public void freeTablesCreated(List tables) { // xvsm.sendFreeTablesToSpace(tables); } @@ -111,6 +111,6 @@ public class PizzeriaAgent { } public interface TablesCreatedHandler { - public void freeTablesCreated(List tables); + public void freeTablesCreated(List
tables); } } diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/actions/TableNew.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/actions/TableNew.java new file mode 100644 index 0000000..c2002f1 --- /dev/null +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/actions/TableNew.java @@ -0,0 +1,31 @@ +package at.ac.tuwien.sbc.valesriegler.pizzeria.actions; + +import java.io.Serializable; + +import at.ac.tuwien.sbc.valesriegler.common.AbstractAction; +import at.ac.tuwien.sbc.valesriegler.types.Table; + +/** + * Indicate the creation of a new table. + * + * @author jan + * + */ +public class TableNew extends AbstractAction implements Serializable { + private final Table table; + + public TableNew(Table table) { + super(null); + this.table = table; + } + + public Table getTable() { + return table; + } + + @Override + public String toString() { + return "TableNew [table=" + table + "]"; + } + +} diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/PizzeriaFrame.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/PizzeriaFrame.java index f9a7e63..4d772ae 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/PizzeriaFrame.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/PizzeriaFrame.java @@ -21,8 +21,6 @@ import javax.swing.event.ListSelectionListener; import javax.swing.event.TableModelEvent; import javax.swing.event.TableModelListener; -import at.ac.tuwien.sbc.valesriegler.DEP_Order; -import at.ac.tuwien.sbc.valesriegler.DEP_Table; import at.ac.tuwien.sbc.valesriegler.common.TableModel; import at.ac.tuwien.sbc.valesriegler.pizzeria.PizzeriaAgent; import at.ac.tuwien.sbc.valesriegler.pizzeria.PizzeriaAgent.TablesCreatedHandler; @@ -31,9 +29,8 @@ import at.ac.tuwien.sbc.valesriegler.pizzeria.gui.tablemodels.OrdersOverviewMode import at.ac.tuwien.sbc.valesriegler.pizzeria.gui.tablemodels.PizzasOfOrderModel; import at.ac.tuwien.sbc.valesriegler.pizzeria.gui.tablemodels.TablesOverviewModel; import at.ac.tuwien.sbc.valesriegler.pizzeria.gui.tablemodels.WaitersOfOrderModel; -import at.ac.tuwien.sbc.valesriegler.types.PizzaOrder; -import at.ac.tuwien.sbc.valesriegler.types.PizzaOrderStatus; -import at.ac.tuwien.sbc.valesriegler.types.PizzaType; +import at.ac.tuwien.sbc.valesriegler.types.Order; +import at.ac.tuwien.sbc.valesriegler.types.Table; /** * Base Frame of the Pizzeria GUI @@ -112,12 +109,12 @@ public class PizzeriaFrame extends JFrame { } private void initModels() { - List orders = getOrdersTestData(); + List orders = getOrdersTestData(); ordersModel.setItems(orders); // When the tables get created in the first place, the handler is informed int numberOfTables = getNumberOfTables(); - List freeTablesCreated = tablesModel.createFreeTables(numberOfTables); + List
freeTablesCreated = tablesModel.createFreeTables(numberOfTables); onTablesCreatedHandler.freeTablesCreated(freeTablesCreated); } @@ -142,7 +139,7 @@ public class PizzeriaFrame extends JFrame { ListSelectionModel lsm = (ListSelectionModel) e.getSource(); int minIndex = lsm.getMinSelectionIndex(); - DEP_Order currentOrder = ordersModel.getOrderOfRow(minIndex); + Order currentOrder = ordersModel.getOrderOfRow(minIndex); waitersPanel.setBorder(new TitledBorder(String.format(WAITER_IDS_CAPTION, currentOrder.getId()))); pizzasPanel.setBorder(new TitledBorder(String.format(PIZZAS_CAPTION, currentOrder.getId()))); waitersModel.setCurrentOrder(currentOrder); @@ -215,31 +212,26 @@ public class PizzeriaFrame extends JFrame { /** * not necessary in production */ - private List getOrdersTestData() { - List orders = new ArrayList<>(); - DEP_Order order1 = new DEP_Order(); - DEP_Order order2 = new DEP_Order(); - DEP_Order order3 = new DEP_Order(); - DEP_Order order4 = new DEP_Order(); - - order1.setId(1); - order2.setId(2); - order3.setId(3); - order4.setId(4); - - order1.setWaiterIdOfOrder(4); - order2.setWaiterIdOfServing(2); - - List pizzas = new ArrayList<>(); - PizzaOrder pizzaOrder1 = new PizzaOrder(PizzaType.CARDINALE); - pizzaOrder1.setStatus(PizzaOrderStatus.DONE); - pizzas.add(pizzaOrder1); - order1.setPizzaOrders(pizzas); - - orders.add(order1); - orders.add(order2); - orders.add(order3); - orders.add(order4); + private List getOrdersTestData() { // TODO: useful way to get data. + List orders = new ArrayList<>(); + // Order order1 = new Order(); + // Order order2 = new Order(); + // Order order3 = new Order(); + // Order order4 = new Order(); + // + // order1.setWaiterIdOfOrder(4); + // order2.setWaiterIdOfServing(2); + // + // List pizzas = new ArrayList<>(); + // PizzaOrder pizzaOrder1 = new PizzaOrder(PizzaType.CARDINALE); + // pizzaOrder1.setStatus(PizzaOrderStatus.DONE); + // pizzas.add(pizzaOrder1); + // order1.setPizzaOrders(pizzas); + + // orders.add(order1); + // orders.add(order2); + // orders.add(order3); + // orders.add(order4); return orders; } diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/tablemodels/GroupsOverviewModel.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/tablemodels/GroupsOverviewModel.java index 498e820..f7baa36 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/tablemodels/GroupsOverviewModel.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/tablemodels/GroupsOverviewModel.java @@ -1,15 +1,13 @@ package at.ac.tuwien.sbc.valesriegler.pizzeria.gui.tablemodels; -import at.ac.tuwien.sbc.valesriegler.DEP_GroupDataMin; import at.ac.tuwien.sbc.valesriegler.common.TableModel; +import at.ac.tuwien.sbc.valesriegler.types.GroupData; -public class GroupsOverviewModel extends TableModel { +public class GroupsOverviewModel extends TableModel { private static final String ID = "ID"; private static final String SIZE = "Size"; - - private static final String[] COLUMNS = new String[] { - ID, SIZE - }; + + private static final String[] COLUMNS = new String[] { ID, SIZE }; @Override protected String[] getColumns() { @@ -18,12 +16,15 @@ public class GroupsOverviewModel extends TableModel { @Override public Object getValueAt(int rowIndex, int columnIndex) { - DEP_GroupDataMin group = items.get(rowIndex); + GroupData group = items.get(rowIndex); String wantedColumn = COLUMNS[columnIndex]; - switch(wantedColumn) { - case ID : return group.getId(); - case SIZE : return group.getSize(); - default : throw new RuntimeException(UNHANDLEDCOLUMN); + switch (wantedColumn) { + case ID: + return group.getId(); + case SIZE: + return group.getSize(); + default: + throw new RuntimeException(UNHANDLEDCOLUMN); } } diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/tablemodels/OrdersOverviewModel.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/tablemodels/OrdersOverviewModel.java index b16b2c3..1df4968 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/tablemodels/OrdersOverviewModel.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/tablemodels/OrdersOverviewModel.java @@ -1,35 +1,35 @@ package at.ac.tuwien.sbc.valesriegler.pizzeria.gui.tablemodels; -import java.util.ArrayList; -import java.util.List; - -import at.ac.tuwien.sbc.valesriegler.DEP_Order; import at.ac.tuwien.sbc.valesriegler.common.TableModel; +import at.ac.tuwien.sbc.valesriegler.types.Order; -public class OrdersOverviewModel extends TableModel { +public class OrdersOverviewModel extends TableModel { private static final String ID = "Order ID"; private static final String TABLE_ID = "Table ID"; private static final String GROUP_ID = "Group ID"; private static final String STATUS = "Status"; - - private static final String[] COLUMNS = new String[] { - ID, TABLE_ID, GROUP_ID, STATUS - }; - + + private static final String[] COLUMNS = new String[] { ID, TABLE_ID, GROUP_ID, STATUS }; + @Override public Object getValueAt(int rowIndex, int columnIndex) { - DEP_Order order = items.get(rowIndex); + Order order = items.get(rowIndex); String wantedColumn = COLUMNS[columnIndex]; - switch(wantedColumn) { - case ID : return order.getId(); - case TABLE_ID : return order.getTableId(); - case GROUP_ID : return order.getGroupId(); - case STATUS : return order.getStatus(); - default : throw new RuntimeException(UNHANDLEDCOLUMN); + switch (wantedColumn) { + case ID: + return order.getId(); + case TABLE_ID: // FIXME: tableid! + return new Integer(0); + case GROUP_ID: + return order.getGroupId(); + case STATUS: + return order.getStatus(); + default: + throw new RuntimeException(UNHANDLEDCOLUMN); } } - - public DEP_Order getOrderOfRow(int rowIndex) { + + public Order getOrderOfRow(int rowIndex) { return items.get(rowIndex); } diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/tablemodels/PizzasOfOrderModel.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/tablemodels/PizzasOfOrderModel.java index 3166e15..d62877f 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/tablemodels/PizzasOfOrderModel.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/tablemodels/PizzasOfOrderModel.java @@ -2,8 +2,8 @@ package at.ac.tuwien.sbc.valesriegler.pizzeria.gui.tablemodels; import java.util.List; -import at.ac.tuwien.sbc.valesriegler.DEP_Order; import at.ac.tuwien.sbc.valesriegler.common.TableModel; +import at.ac.tuwien.sbc.valesriegler.types.Order; import at.ac.tuwien.sbc.valesriegler.types.PizzaOrder; public class PizzasOfOrderModel extends TableModel { @@ -13,9 +13,9 @@ public class PizzasOfOrderModel extends TableModel { private static final String[] COLUMNS = new String[] { TYPE, STATUS, COOK }; - private DEP_Order currentOrder; + private Order currentOrder; - public void setCurrentOrder(DEP_Order currentOrder) { + public void setCurrentOrder(Order currentOrder) { this.currentOrder = currentOrder; fireTableDataChanged(); @@ -26,7 +26,7 @@ public class PizzasOfOrderModel extends TableModel { if (rowIndex > 0) return null; - List pizzaOrders = currentOrder.getPizzaOrders(); + List pizzaOrders = currentOrder.getOrderedPizzas(); if (pizzaOrders == null) return null; diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/tablemodels/TableModelOfSingleOrder.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/tablemodels/TableModelOfSingleOrder.java index 4b016b4..9f436c1 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/tablemodels/TableModelOfSingleOrder.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/tablemodels/TableModelOfSingleOrder.java @@ -1,17 +1,17 @@ package at.ac.tuwien.sbc.valesriegler.pizzeria.gui.tablemodels; -import at.ac.tuwien.sbc.valesriegler.DEP_Order; import at.ac.tuwien.sbc.valesriegler.common.TableModel; +import at.ac.tuwien.sbc.valesriegler.types.Order; -public abstract class TableModelOfSingleOrder extends TableModel { - protected DEP_Order currentOrder; - - public void setCurrentOrder(DEP_Order currentOrder) { +public abstract class TableModelOfSingleOrder extends TableModel { + protected Order currentOrder; + + public void setCurrentOrder(Order currentOrder) { this.currentOrder = currentOrder; - + fireTableDataChanged(); } - + @Override public int getRowCount() { return currentOrder == null ? 0 : 1; diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/tablemodels/TablesOverviewModel.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/tablemodels/TablesOverviewModel.java index 498eece..5ba4982 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/tablemodels/TablesOverviewModel.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/tablemodels/TablesOverviewModel.java @@ -3,17 +3,14 @@ package at.ac.tuwien.sbc.valesriegler.pizzeria.gui.tablemodels; import java.util.ArrayList; import java.util.List; -import at.ac.tuwien.sbc.valesriegler.DEP_Table; -import at.ac.tuwien.sbc.valesriegler.DEP_Table.TableStatus; import at.ac.tuwien.sbc.valesriegler.common.TableModel; +import at.ac.tuwien.sbc.valesriegler.types.Table; -public class TablesOverviewModel extends TableModel { +public class TablesOverviewModel extends TableModel
{ private static final String TABLE_ID = "ID"; - private static final String STATUS = "Status"; + private static final String STATUS = "Is free"; private static final String GROUP_ID = "Group ID"; - private static final String[] COLUMNS = new String[] { - TABLE_ID, STATUS, GROUP_ID - }; + private static final String[] COLUMNS = new String[] { TABLE_ID, STATUS, GROUP_ID }; private int idCounter = 1; @Override @@ -23,53 +20,53 @@ public class TablesOverviewModel extends TableModel { @Override public Object getValueAt(int rowIndex, int columnIndex) { - DEP_Table table = items.get(rowIndex); + Table table = items.get(rowIndex); String wantedColumn = COLUMNS[columnIndex]; - switch(wantedColumn) { - case TABLE_ID : return table.getId(); - case STATUS : return table.getStatus(); - case GROUP_ID : return table.getGroupId(); - default : throw new RuntimeException(UNHANDLEDCOLUMN); + switch (wantedColumn) { + case TABLE_ID: + return table.getId(); + case STATUS: + return table.isFree(); + case GROUP_ID: + return table.getGroupId(); + default: + throw new RuntimeException(UNHANDLEDCOLUMN); } } public int getNumberOfFreeTables() { return getIdsOfFreeTables().size(); } - + public List getIdsOfFreeTables() { List ids = new ArrayList<>(); - - synchronized(items) { - for(DEP_Table table : items) { - if(table.getStatus() == TableStatus.FREE) { + + synchronized (items) { + for (Table table : items) { + if (table.isFree()) { ids.add(table.getId()); } } } - + return ids; } - - public List createFreeTables(int numberOfTables) { - synchronized(items) { - List tables = new ArrayList(); - for(int i=0; i createFreeTables(int numberOfTables) { + synchronized (items) { + List
tables = new ArrayList
(); + for (int i = 0; i < numberOfTables; i++) { + Table table = createFreeTable(); tables.add(table); } addItems(tables); - + return tables; } } - - private DEP_Table createFreeTable() { - DEP_Table table = new DEP_Table(); - table.setId(idCounter); - idCounter = idCounter + 1; - table.setStatus(TableStatus.FREE); - return table; + + private Table createFreeTable() { + return new Table(); } } diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/tablemodels/WaitersOfOrderModel.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/tablemodels/WaitersOfOrderModel.java index 1a2dda9..f8d16c5 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/tablemodels/WaitersOfOrderModel.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/tablemodels/WaitersOfOrderModel.java @@ -1,27 +1,35 @@ package at.ac.tuwien.sbc.valesriegler.pizzeria.gui.tablemodels; -import at.ac.tuwien.sbc.valesriegler.DEP_Order; public class WaitersOfOrderModel extends TableModelOfSingleOrder { private static final String TABLE_ASSIGNMENT = "Table Assignment"; private static final String ORDER = "Order"; private static final String SERVING = "Serving"; private static final String PAYMENT = "Payment"; - private static final String[] COLUMNS = new String[] { - TABLE_ASSIGNMENT, ORDER, SERVING, PAYMENT - }; + private static final String[] COLUMNS = new String[] { TABLE_ASSIGNMENT, ORDER, SERVING, PAYMENT }; @Override public Object getValueAt(int rowIndex, int columnIndex) { - if(rowIndex > 0) return null; - + if (rowIndex > 0) + return null; + String wantedColumn = COLUMNS[columnIndex]; - switch(wantedColumn) { - case TABLE_ASSIGNMENT : return currentOrder.getWaiterIdOfTableAssignment(); - case ORDER : return currentOrder.getWaiterIdOfOrder(); - case SERVING : return currentOrder.getWaiterIdOfServing(); - case PAYMENT : return currentOrder.getWaiterIdOfPayment(); - default : throw new RuntimeException(UNHANDLEDCOLUMN); + switch (wantedColumn) { + // case TABLE_ASSIGNMENT : return + // currentOrder.getWaiterIdOfTableAssignment(); + // case ORDER : return currentOrder.getWaiterIdOfOrder(); + // case SERVING : return currentOrder.getWaiterIdOfServing(); + // case PAYMENT : return currentOrder.getWaiterIdOfPayment(); + case TABLE_ASSIGNMENT: + return new Integer(-2); + case ORDER: + return new Integer(-2); + case SERVING: + return new Integer(-2); + case PAYMENT: + return new Integer(-2); + default: + throw new RuntimeException(UNHANDLEDCOLUMN); } } diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/jms/JMSPizzeriaConnector.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/jms/JMSPizzeriaConnector.java new file mode 100644 index 0000000..132c5a2 --- /dev/null +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/jms/JMSPizzeriaConnector.java @@ -0,0 +1,92 @@ +package at.ac.tuwien.sbc.valesriegler.pizzeria.jms; + +import javax.jms.Connection; +import javax.jms.DeliveryMode; +import javax.jms.JMSException; +import javax.jms.Message; +import javax.jms.MessageConsumer; +import javax.jms.MessageListener; +import javax.jms.MessageProducer; +import javax.jms.ObjectMessage; +import javax.jms.Session; + +import org.apache.activemq.ActiveMQConnectionFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import at.ac.tuwien.sbc.valesriegler.common.AbstractAction; +import at.ac.tuwien.sbc.valesriegler.group.Group; +import at.ac.tuwien.sbc.valesriegler.group.GroupAgent; +import at.ac.tuwien.sbc.valesriegler.group.actions.OrderResponse; +import at.ac.tuwien.sbc.valesriegler.group.actions.TableResponse; +import at.ac.tuwien.sbc.valesriegler.pizzeria.AbstractPizzeriaConnector; +import at.ac.tuwien.sbc.valesriegler.pizzeria.actions.TableNew; + +/** + * This class handles the communication with other processes using JMS. + * + * @author jan + * + */ +public class JMSPizzeriaConnector extends AbstractPizzeriaConnector implements MessageListener { + private static final Logger log = LoggerFactory.getLogger(JMSPizzeriaConnector.class); + + private Connection connection; + + @Override + public void init() { + try { + connection = new ActiveMQConnectionFactory("tcp://localhost:61616").createConnection(); + connection.start(); + Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); + MessageConsumer consumer = session.createConsumer(session.createQueue("PizzariaConnector")); + consumer.setMessageListener(this); + } catch (JMSException e) { + log.error("EXCEPTION!", e); + } + } + + @Override + public void onMessage(Message msg) { + try { + msg.acknowledge(); + if (msg instanceof ObjectMessage) { + ObjectMessage objMsg = (ObjectMessage) msg; + Object obj = objMsg.getObject(); + + if (obj instanceof TableResponse) { + TableResponse tablerresponse = (TableResponse) obj; + log.debug("Received: " + tablerresponse); + Group g = GroupAgent.getInstance().getGroupModel().getGroupByID(tablerresponse.getGroupdata().getId()); + g.assignTable(tablerresponse.getTable(), tablerresponse.getWaiterId()); + return; + } else if (obj instanceof OrderResponse) { + + } + } + + log.warn("Unknown messagetype received!"); + } catch (JMSException e) { + log.error("EXCEPTION!", e); + } + } + + @Override + public void send(AbstractAction request) { + try { + if (request instanceof TableNew) { + + Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); + MessageProducer wantToSitAtTable = session.createProducer(session.createQueue("TablesFree")); + wantToSitAtTable.setDeliveryMode(DeliveryMode.NON_PERSISTENT); + wantToSitAtTable.send(session.createObjectMessage(((TableNew) request).getTable())); + + session.close(); + return; + } + } catch (JMSException e) { + log.error("EXCEPTION!", e); + } + } + +} diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/types/GroupState.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/types/GroupState.java index 6a48dc7..52d7013 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/types/GroupState.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/types/GroupState.java @@ -2,6 +2,12 @@ package at.ac.tuwien.sbc.valesriegler.types; import java.io.Serializable; +/** + * Enum denoting all the possible states a Group can be in. + * + * @author jan + * + */ public enum GroupState implements Serializable { NEW, WAITING, SITTING, ORDER_PENDING, ORDERED, EATING, PAY, GONE } diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/types/Order.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/types/Order.java index 3685bb6..47e8d41 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/types/Order.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/types/Order.java @@ -5,6 +5,13 @@ import java.util.List; import at.ac.tuwien.sbc.valesriegler.group.Group; +/** + * Object denotes a Group's interest in pizzas and the state of the pizzas + * themselves. + * + * @author jan + * + */ public class Order implements Serializable { private static int idNext = 0; private final int id; diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/types/OrderStatus.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/types/OrderStatus.java index 2a6256e..c895214 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/types/OrderStatus.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/types/OrderStatus.java @@ -2,6 +2,12 @@ package at.ac.tuwien.sbc.valesriegler.types; import java.io.Serializable; +/** + * Enum denoting all the possible states an Order can have. + * + * @author jan + * + */ public enum OrderStatus implements Serializable { NEW, ORDERED, DELIVERED, PAID } diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/types/Pizza.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/types/Pizza.java index feb448d..b442696 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/types/Pizza.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/types/Pizza.java @@ -5,6 +5,12 @@ import java.io.Serializable; import at.ac.tuwien.sbc.valesriegler.cook.JMSCook; import at.ac.tuwien.sbc.valesriegler.waiter.Waiter; +/** + * this is a PIZZA! omnomnomnom + * + * @author jan + * + */ public class Pizza implements Serializable { final private int id; final private PizzaType type; diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/types/PizzaOrder.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/types/PizzaOrder.java index e5a102c..9e8a3c7 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/types/PizzaOrder.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/types/PizzaOrder.java @@ -2,6 +2,12 @@ package at.ac.tuwien.sbc.valesriegler.types; import java.io.Serializable; +/** + * Class denoting one Pizza in the future and its state. + * + * @author jan + * + */ public class PizzaOrder implements Serializable { private static int nextID = 0; final private int id; diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/types/PizzaOrderStatus.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/types/PizzaOrderStatus.java index 2c8d513..5e9c2e6 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/types/PizzaOrderStatus.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/types/PizzaOrderStatus.java @@ -2,6 +2,12 @@ package at.ac.tuwien.sbc.valesriegler.types; import java.io.Serializable; +/** + * Enum denoting all the possible states a PizzaOrder can be in. + * + * @author jan + * + */ public enum PizzaOrderStatus implements Serializable { NEW, ORDERED, IN_PREPARATION, DONE } diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/types/PizzaType.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/types/PizzaType.java index 453ffee..7873349 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/types/PizzaType.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/types/PizzaType.java @@ -2,9 +2,15 @@ package at.ac.tuwien.sbc.valesriegler.types; import java.io.Serializable; +/** + * enum denoting all the kinds of pizzas we have. Thats pretty few :( + * + * @author jan + * + */ public enum PizzaType implements Serializable { - MARGHERITA(5, 3), SALAMI(5.5, 7), CARDINALE(6,5); - + MARGHERITA(5, 3), SALAMI(5.5, 7), CARDINALE(6, 5); + public final double price; public final double duration; diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/types/Table.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/types/Table.java index 0b48bcc..44c09a3 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/types/Table.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/types/Table.java @@ -2,17 +2,45 @@ package at.ac.tuwien.sbc.valesriegler.types; import java.io.Serializable; +/** + * A table is a thing, where people can put things at. Possibly a laptop, to + * have free hands to hold a pizzabox on the knees. + * + * @author jan + * + */ public class Table implements Serializable { + private static int idNext = 0; private final int id; + private int groupId = -1; + public Table(int id) { this.id = id; } + public Table() { + id = ++idNext; + } + public int getId() { return id; } + public int getGroupId() { + return groupId; + } + + public void setGroupId(int groupId) { + this.groupId = groupId; + } + + public boolean isFree() { + if (groupId == -1) + return true; + return false; + } + @Override public String toString() { return "Table [id=" + id + "]"; diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/waiter/Waiter.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/waiter/Waiter.java index 95b961e..50cd859 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/waiter/Waiter.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/waiter/Waiter.java @@ -14,8 +14,13 @@ import at.ac.tuwien.sbc.valesriegler.waiter.jms.messageListeners.WantToOrder; import at.ac.tuwien.sbc.valesriegler.waiter.jms.messageListeners.WantToPay; import at.ac.tuwien.sbc.valesriegler.waiter.jms.messageListeners.WantToSitAtTable; -//TODO: needs a WaiterAgent and abstraction to support mzs + jms! -// Currently this is jms only! +/** + * A waiter is a person who does all the stuff and gets lousy tips in return. + * TODO: might want to split this class into multiple, to allow for abstraction. + * + * @author jan + * + */ public class Waiter implements Serializable { private static final Logger log = LoggerFactory.getLogger(Waiter.class); private static int nextID = 0; diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/waiter/jms/messageListeners/WantToOrder.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/waiter/jms/messageListeners/WantToOrder.java index 4eb3351..a2d1f14 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/waiter/jms/messageListeners/WantToOrder.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/waiter/jms/messageListeners/WantToOrder.java @@ -19,6 +19,12 @@ import at.ac.tuwien.sbc.valesriegler.types.Order; import at.ac.tuwien.sbc.valesriegler.types.PizzaOrder; import at.ac.tuwien.sbc.valesriegler.waiter.Waiter; +/** + * Listener listening on the WantToOrder MQ, handling all incomming messages. + * + * @author jan + * + */ public class WantToOrder implements MessageListener { private static final Logger log = LoggerFactory.getLogger(WantToOrder.class); private final Waiter waiter; diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/waiter/jms/messageListeners/WantToPay.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/waiter/jms/messageListeners/WantToPay.java index e263b0a..80f5b3e 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/waiter/jms/messageListeners/WantToPay.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/waiter/jms/messageListeners/WantToPay.java @@ -17,6 +17,12 @@ import at.ac.tuwien.sbc.valesriegler.group.actions.PayRequest; import at.ac.tuwien.sbc.valesriegler.group.actions.PayResponse; import at.ac.tuwien.sbc.valesriegler.waiter.Waiter; +/** + * Listener listening on the WantToPay MQ, handling all incomming messages. + * + * @author jan + * + */ public class WantToPay implements MessageListener { private static final Logger log = LoggerFactory.getLogger(WantToPay.class); private final Waiter waiter; diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/waiter/jms/messageListeners/WantToSitAtTable.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/waiter/jms/messageListeners/WantToSitAtTable.java index 9b1487e..ca4f4e5 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/waiter/jms/messageListeners/WantToSitAtTable.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/waiter/jms/messageListeners/WantToSitAtTable.java @@ -19,6 +19,13 @@ import at.ac.tuwien.sbc.valesriegler.group.actions.TableResponse; import at.ac.tuwien.sbc.valesriegler.types.Table; import at.ac.tuwien.sbc.valesriegler.waiter.Waiter; +/** + * Listener listening on the WantToSitAtTable MQ, handling all incomming + * messages. + * + * @author jan + * + */ public class WantToSitAtTable implements MessageListener { private static final Logger log = LoggerFactory.getLogger(WantToSitAtTable.class); private final Waiter waiter; diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/xvsm/XVSMConnector.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/xvsm/XVSMConnector.java index 6dc2933..241ef2c 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/xvsm/XVSMConnector.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/xvsm/XVSMConnector.java @@ -1,6 +1,5 @@ package at.ac.tuwien.sbc.valesriegler.xvsm; -import java.io.Serializable; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -16,44 +15,44 @@ import org.mozartspaces.core.MzsCoreException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import at.ac.tuwien.sbc.valesriegler.DEP_Table; import at.ac.tuwien.sbc.valesriegler.common.SpaceUtil; +import at.ac.tuwien.sbc.valesriegler.types.Table; /** * Responsible for XVSM Communication * * @author Gregor Riegler - * + * */ public class XVSMConnector { private static final Logger log = LoggerFactory.getLogger(XVSMConnector.class); - + private ContainerReference tablesContainer; private Capi capi; - public void initSpaceCommunication() throws MzsCoreException { MzsCore core = DefaultMzsCore.newInstanceWithoutSpace(); capi = new Capi(core); - tablesContainer = SpaceUtil.getOrCreateNamedContainer(SpaceUtil.SERVER_ADDR, SpaceUtil.TABLES_CONTAINER, capi, Arrays.asList((Coordinator) new AnyCoordinator())); + tablesContainer = SpaceUtil.getOrCreateNamedContainer(SpaceUtil.SERVER_ADDR, SpaceUtil.TABLES_CONTAINER, capi, + Arrays.asList((Coordinator) new AnyCoordinator())); } - - public void sendFreeTablesToSpace(List tables) { + + public void sendFreeTablesToSpace(List
tables) { try { List entries = new ArrayList<>(); - for (DEP_Table table : tables) { + for (Table table : tables) { entries.add(new Entry(table)); } capi.write(entries, tablesContainer); - + log.info("Wrote Free tables to Space!"); } catch (MzsCoreException e) { e.printStackTrace(); } } - public List readTables() { - ArrayList tables = new ArrayList<>(); + public List
readTables() { + ArrayList
tables = new ArrayList<>(); try { tables = capi.take(tablesContainer); } catch (MzsCoreException e) { diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/xvsm/waiter/Waiter.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/xvsm/waiter/Waiter.java index 182d635..4a6cc49 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/xvsm/waiter/Waiter.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/xvsm/waiter/Waiter.java @@ -7,27 +7,27 @@ import org.mozartspaces.core.MzsCoreException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import at.ac.tuwien.sbc.valesriegler.DEP_Table; +import at.ac.tuwien.sbc.valesriegler.types.Table; import at.ac.tuwien.sbc.valesriegler.xvsm.XVSMConnector; /** * This is a waiter using XVSM * * @author Gregor Riegler - * + * */ public class Waiter implements Serializable { private static final String USAGE = "Waiter needs exactly one parameter: ID of type Integer"; private static final Logger log = LoggerFactory.getLogger(Waiter.class); - + private int id; private XVSMConnector xvsm; public static void main(String[] args) { - if(args.length != 1) { + if (args.length != 1) { throw new IllegalArgumentException(USAGE); } - + int parsedId = 0; try { parsedId = Integer.parseInt(args[0]); @@ -35,20 +35,20 @@ public class Waiter implements Serializable { log.error(USAGE); return; } - + Waiter waiter = new Waiter(parsedId); waiter.start(); } private void start() { initSpaceCommunication(); - - List tables = xvsm.readTables(); - + + List
tables = xvsm.readTables(); + log.info("Number of free tables received: {}", tables.size()); - + } - + private void initSpaceCommunication() { try { xvsm = new XVSMConnector(); @@ -58,10 +58,9 @@ public class Waiter implements Serializable { log.error("The Waiter has no Space connection! Have you started the Space Server?"); System.exit(1); } - + log.info("Space Connection established!"); - - + } public Waiter(int id) { @@ -70,4 +69,3 @@ public class Waiter implements Serializable { } } - -- 2.43.0