From 6b3cc5b26e8e5361559cbd343f29fdfa5ad95130 Mon Sep 17 00:00:00 2001 From: Jan Vales Date: Sun, 5 May 2013 21:39:38 +0200 Subject: [PATCH] implemented Workflow to "ordered", where the cook has pizzas to cook and another queue waiting for completed orders. --- queues | 6 ++++++ .../sbc/valesriegler/DEBUG_CreateTable.java | 2 +- .../{pizzeria/gui => }/DEP_Order.java | 2 +- .../{pizzeria/gui => }/DEP_Table.java | 2 +- .../tuwien/sbc/valesriegler/group/Group.java | 18 ++++++++++++++---- .../group/actions/OrderResponse.java | 19 +++++++++++++++++++ .../group/jms/JMSGroupConnector.java | 8 ++++++++ .../valesriegler/pizzeria/PizzeriaAgent.java | 2 +- .../pizzeria/gui/PizzeriaFrame.java | 2 ++ .../gui/tablemodels/OrdersOverviewModel.java | 2 +- .../gui/tablemodels/PizzasOfOrderModel.java | 2 +- .../tablemodels/TableModelOfSingleOrder.java | 2 +- .../gui/tablemodels/TablesOverviewModel.java | 4 ++-- .../gui/tablemodels/WaitersOfOrderModel.java | 2 +- .../sbc/valesriegler/types/GroupState.java | 2 +- .../jms/messageListeners/WantToOrder.java | 16 +++++++++------- .../sbc/valesriegler/xvsm/XVSMConnector.java | 2 +- .../sbc/valesriegler/xvsm/waiter/Waiter.java | 2 +- 18 files changed, 71 insertions(+), 24 deletions(-) rename src/main/java/at/ac/tuwien/sbc/valesriegler/{pizzeria/gui => }/DEP_Order.java (97%) rename src/main/java/at/ac/tuwien/sbc/valesriegler/{pizzeria/gui => }/DEP_Table.java (91%) create mode 100644 src/main/java/at/ac/tuwien/sbc/valesriegler/group/actions/OrderResponse.java diff --git a/queues b/queues index d556238..3f463b9 100644 --- a/queues +++ b/queues @@ -18,6 +18,12 @@ Liste aller Messagequeues: WantToOrder Gruppen, die eine Bestellungen, die von Waitern bearbeitet werden sollen. + PendingOrders + Bestellungen, die in der Küche in auftrag gegeben wurden, aber noch nicht fertig/ausgeliefert sind. + + OrderedPizzas + Pizzen, die von Köchen gekocht werden sollen. + ---------------------- Wartende Gruppen diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/DEBUG_CreateTable.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/DEBUG_CreateTable.java index 4663c7d..6e0feae 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/DEBUG_CreateTable.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/DEBUG_CreateTable.java @@ -39,7 +39,7 @@ public class DEBUG_CreateTable { tableprod.setDeliveryMode(DeliveryMode.NON_PERSISTENT); // Create Tables - for (int i = 0; i < 1; i++) { + for (int i = 0; i < 3; i++) { tableprod.send(session.createObjectMessage(new Table(i))); } diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/DEP_Order.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/DEP_Order.java similarity index 97% rename from src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/DEP_Order.java rename to src/main/java/at/ac/tuwien/sbc/valesriegler/DEP_Order.java index a4e9433..c91789f 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/DEP_Order.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/DEP_Order.java @@ -1,4 +1,4 @@ -package at.ac.tuwien.sbc.valesriegler.pizzeria.gui; +package at.ac.tuwien.sbc.valesriegler; import java.util.List; diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/DEP_Table.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/DEP_Table.java similarity index 91% rename from src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/DEP_Table.java rename to src/main/java/at/ac/tuwien/sbc/valesriegler/DEP_Table.java index 3ae422d..4de9c66 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/DEP_Table.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/DEP_Table.java @@ -1,4 +1,4 @@ -package at.ac.tuwien.sbc.valesriegler.pizzeria.gui; +package at.ac.tuwien.sbc.valesriegler; import java.io.Serializable; 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 e7be93c..2642063 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 @@ -40,7 +40,10 @@ public class Group implements Runnable { break; case SITTING: GroupAgent.getInstance().getGroupcomm().send(new OrderRequest(groupData)); + order(); break; + case ORDER_PENDING: + break; // do nothing. case ORDERED: break; // do nothing. case EATING:// just wait some more and request bill. @@ -83,15 +86,22 @@ public class Group implements Runnable { } // ask the group to send their order. - public void askForOrder(int waiter) { + public void order() { + groupData.setState(GroupState.ORDER_PENDING); + new Thread(this).start(); + log.debug("order(): " + this); + } + + // Waiter telling group he/she forwarded the order. + public void orderReceived(int waiter) { groupData.setState(GroupState.ORDERED); groupData.setOrderWaiter(waiter); new Thread(this).start(); - log.debug("askForOrder(): " + this); + log.debug("orderReceived(): " + this); } - // pizzas are here! nom pizzas! - public void bringOrderedPizzas(Order order, int waiter) { + // pizzas are here! nom nom nom + public void deliverPizzas(Order order, int waiter) { groupData.setState(GroupState.EATING); groupData.setOrder(order); groupData.setPizzaWaiter(waiter); 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 new file mode 100644 index 0000000..137c6f5 --- /dev/null +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/group/actions/OrderResponse.java @@ -0,0 +1,19 @@ +package at.ac.tuwien.sbc.valesriegler.group.actions; + +import java.io.Serializable; + +import at.ac.tuwien.sbc.valesriegler.types.GroupData; + +public class OrderResponse extends AbstractAction implements Serializable { + private final int waiterId; + + public OrderResponse(GroupData groupdata, int waiterId) { + super(groupdata); + this.waiterId = waiterId; + } + + public int getWaiterId() { + return waiterId; + } + +} 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 afb2bb2..58784ce 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 @@ -19,6 +19,7 @@ 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.TableRequest; import at.ac.tuwien.sbc.valesriegler.group.actions.TableResponse; @@ -60,7 +61,14 @@ public class JMSGroupConnector extends AbstractGroupConnector implements Message Group g = GroupAgent.getInstance().getGroupModel().getGroupByID(tablerresponse.getGroupdata().getId()); g.assignTable(tablerresponse.getTable(), tablerresponse.getWaiterId()); return; + } else if (obj instanceof OrderResponse) { + OrderResponse orderresponse = (OrderResponse) obj; + log.debug("Received: " + orderresponse); + Group g = GroupAgent.getInstance().getGroupModel().getGroupByID(orderresponse.getGroupdata().getId()); + g.orderReceived(orderresponse.getWaiterId()); + return; } + } log.warn("Unknown messagetype received!"); 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 4335e50..9350462 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,7 +8,7 @@ import org.mozartspaces.core.MzsCoreException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import at.ac.tuwien.sbc.valesriegler.pizzeria.gui.DEP_Table; +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; 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 828532a..f9a7e63 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,6 +21,8 @@ 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; 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 fafde45..b16b2c3 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 @@ -3,8 +3,8 @@ 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.pizzeria.gui.DEP_Order; public class OrdersOverviewModel extends TableModel { private static final String ID = "Order ID"; 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 1244fc7..3166e15 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.pizzeria.gui.DEP_Order; import at.ac.tuwien.sbc.valesriegler.types.PizzaOrder; public class PizzasOfOrderModel extends TableModel { 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 471b296..4b016b4 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,7 +1,7 @@ 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.pizzeria.gui.DEP_Order; public abstract class TableModelOfSingleOrder extends TableModel { protected DEP_Order currentOrder; 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 2b810ea..498eece 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,9 +3,9 @@ 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.pizzeria.gui.DEP_Table; -import at.ac.tuwien.sbc.valesriegler.pizzeria.gui.DEP_Table.TableStatus; public class TablesOverviewModel extends TableModel { private static final String TABLE_ID = "ID"; 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 7badbe2..1a2dda9 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,6 +1,6 @@ package at.ac.tuwien.sbc.valesriegler.pizzeria.gui.tablemodels; -import at.ac.tuwien.sbc.valesriegler.pizzeria.gui.DEP_Order; +import at.ac.tuwien.sbc.valesriegler.DEP_Order; public class WaitersOfOrderModel extends TableModelOfSingleOrder { private static final String TABLE_ASSIGNMENT = "Table Assignment"; 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 c0fa2bf..6a48dc7 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 @@ -3,5 +3,5 @@ package at.ac.tuwien.sbc.valesriegler.types; import java.io.Serializable; public enum GroupState implements Serializable { - NEW, WAITING, SITTING, ORDERED, EATING, PAY, GONE + NEW, WAITING, SITTING, ORDER_PENDING, ORDERED, EATING, PAY, GONE } 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 41fd83d..4eb3351 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 @@ -14,7 +14,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import at.ac.tuwien.sbc.valesriegler.group.actions.OrderRequest; -import at.ac.tuwien.sbc.valesriegler.group.actions.TableRequest; +import at.ac.tuwien.sbc.valesriegler.group.actions.OrderResponse; import at.ac.tuwien.sbc.valesriegler.types.Order; import at.ac.tuwien.sbc.valesriegler.types.PizzaOrder; import at.ac.tuwien.sbc.valesriegler.waiter.Waiter; @@ -35,7 +35,7 @@ public class WantToOrder implements MessageListener { ObjectMessage objMsg = (ObjectMessage) msg; Object obj = objMsg.getObject(); - if (obj instanceof TableRequest) { + if (obj instanceof OrderRequest) { OrderRequest orderrequest = (OrderRequest) obj; log.debug("Received: " + orderrequest); @@ -53,16 +53,19 @@ public class WantToOrder implements MessageListener { // Create the queue for the cooks. Order o = orderrequest.getGroupdata().getOrder(); for (PizzaOrder po : o.getOrderedPizzas()) { - ObjectMessage message = session.createObjectMessage(po); - prodOP.send(message); + prodOP.send(session.createObjectMessage(po)); } // Also put the order in the Pending order queue for the waiter to // check. MessageProducer prodPending = session.createProducer(session.createQueue("PendingOrders")); prodPending.setDeliveryMode(DeliveryMode.NON_PERSISTENT); - ObjectMessage message = session.createObjectMessage(o); - prodPending.send(message); + prodPending.send(session.createObjectMessage(o)); + + MessageProducer informGroup = session.createProducer(session.createQueue("GroupConnector")); + informGroup.setDeliveryMode(DeliveryMode.NON_PERSISTENT); + OrderResponse or = new OrderResponse(orderrequest.getGroupdata(), waiter.getId()); + informGroup.send(session.createObjectMessage(or)); session.close(); connection.close(); @@ -78,5 +81,4 @@ public class WantToOrder implements MessageListener { log.error("EXCEPTION!", e); } } - } 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 43b24c5..6dc2933 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 @@ -16,8 +16,8 @@ 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.pizzeria.gui.DEP_Table; /** * Responsible for XVSM Communication 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 b9fa1ce..182d635 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,7 +7,7 @@ import org.mozartspaces.core.MzsCoreException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import at.ac.tuwien.sbc.valesriegler.pizzeria.gui.DEP_Table; +import at.ac.tuwien.sbc.valesriegler.DEP_Table; import at.ac.tuwien.sbc.valesriegler.xvsm.XVSMConnector; /** -- 2.43.0