From f8d47e6fa5577dcf2ecf70d7e2f553236815268b Mon Sep 17 00:00:00 2001 From: Gregor Riegler Date: Fri, 31 May 2013 13:55:25 +0200 Subject: [PATCH] [XVSM] Pizzeria notifies on start Group agent that it exists. So the pizzeria can be selected in the group creation GUI. [XVSM] Group Agent gets notified about changes in every pizzeria. --- README.md | 17 ++--- pom.xml | 52 ---------------- .../tuwien/sbc/valesriegler/common/Util.java | 35 ++++++----- .../sbc/valesriegler/group/GroupAgent.java | 10 ++- .../group/gui/DeliveryOverviewModel.java | 3 +- .../group/gui/GroupCreationDetailsPanel.java | 3 +- .../valesriegler/pizzeria/PizzeriaAgent.java | 1 + .../xvsm/AbstractXVSMConnector.java | 15 +++-- .../sbc/valesriegler/xvsm/GroupAgentXVSM.java | 62 +++++++++++++------ .../sbc/valesriegler/xvsm/GroupXVSM.java | 10 +-- .../valesriegler/xvsm/PizzeriaAgentXVSM.java | 8 ++- .../xvsm/PizzeriaRegistration.java | 16 +++++ .../sbc/valesriegler/xvsm/WaiterXVSM.java | 35 ++++++++--- .../sbc/valesriegler/xvsm/cook/Cook.java | 17 +++-- 14 files changed, 148 insertions(+), 136 deletions(-) create mode 100644 src/main/java/at/ac/tuwien/sbc/valesriegler/xvsm/PizzeriaRegistration.java diff --git a/README.md b/README.md index 32a7e85..cbe352f 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ Space Based Computing SS 2013 ================== -### How to start the Group GUI - mvn exec:java -Dexec.mainClass="at.ac.tuwien.sbc.valesriegler.group.GroupAgent" -Dmozartspaces.configurationFile="mozartspaces-client.xml" +### How to start the JMS Group GUI + mvn exec:java -Dexec.mainClass="at.ac.tuwien.sbc.valesriegler.group.GroupAgent" -Dexec.args="XVSM" ### How to start the JMS Pizzeria GUI mvn exec:java -Dexec.mainClass="at.ac.tuwien.sbc.valesriegler.pizzeria.PizzeriaAgent" -Dexec.args="JMS" @@ -12,14 +12,17 @@ Space Based Computing SS 2013 ### How to start a JMS Cook with Id 1 mvn exec:java -Dexec.mainClass="at.ac.tuwien.sbc.valesriegler.jms.cook.Cook" -Dexec.args="1" -### How to start the Space Server - mvn exec:java -Dexec.mainClass="org.mozartspaces.core.Server" +### How to start a Space Server + mvn exec:java -Dexec.mainClass="org.mozartspaces.core.Server" -Dexec.args= +### How to start the Space Group GUI + mvn exec:java -Dexec.mainClass="at.ac.tuwien.sbc.valesriegler.group.GroupAgent" -Dexec.args="XVSM" + ### How to start the Space Pizzeria GUI - mvn exec:java -Dexec.mainClass="at.ac.tuwien.sbc.valesriegler.pizzeria.PizzeriaAgent" -Dexec.args="XVSM" -Dmozartspaces.configurationFile="mozartspaces-client.xml" + mvn exec:java -Dexec.mainClass="at.ac.tuwien.sbc.valesriegler.pizzeria.PizzeriaAgent" -Dexec.args="XVSM " ### How to start a Space Waiter with Id 1 - mvn exec:java -Dexec.mainClass="at.ac.tuwien.sbc.valesriegler.xvsm.waiter.Waiter" -Dexec.args="1" -Dmozartspaces.configurationFile="mozartspaces-client.xml" + mvn exec:java -Dexec.mainClass="at.ac.tuwien.sbc.valesriegler.xvsm.waiter.Waiter" -Dexec.args="1 " ### How to start a Space Cook with Id 1 - mvn exec:java -Dexec.mainClass="at.ac.tuwien.sbc.valesriegler.xvsm.cook.Cook" -Dexec.args="1" -Dmozartspaces.configurationFile="mozartspaces-client.xml" \ No newline at end of file + mvn exec:java -Dexec.mainClass="at.ac.tuwien.sbc.valesriegler.xvsm.cook.Cook" -Dexec.args="1 " \ No newline at end of file diff --git a/pom.xml b/pom.xml index 2ad4a6c..aa59978 100644 --- a/pom.xml +++ b/pom.xml @@ -86,56 +86,4 @@ - - - server - - - - org.codehaus.mojo - exec-maven-plugin - - - install - - java - - - - - org.mozartspaces.core.Server - - 4242 - - runtime - - - - - - - - pizzeria - - - - org.codehaus.mojo - exec-maven-plugin - - java - - -Dmozartspaces.configurationFile=mozartspaces-client.xml - -classpath - - at.ac.tuwien.sbc.valesriegler.pizzeria.PizzeriaAgent - - - - - - - - - - \ No newline at end of file diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/common/Util.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/common/Util.java index 3226328..753bb25 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/common/Util.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/common/Util.java @@ -21,25 +21,26 @@ import javax.swing.border.TitledBorder; public abstract class Util { private static final Logger log = LoggerFactory.getLogger(Util.class); - - public static boolean useJMS = true; - - + public static boolean useJMS = true; public static final String TABLE_ASSIGNED = "tables"; - public static final String GROUPS_CONTAINER = "groups"; - public static final String ASSIGN_TABLE = "assignTable"; - public static final String TAKE_ORDER = "takeOrder"; - public static final String ORDER_TAKEN = "order"; - public static final String DELIVER_PIZZAS = "deliverPizzas"; - public static final String PREPARE_PIZZAS = "preparePizzas"; - public static final String PIZZAS_IN_PROGRESS = "pizzasInProgress"; - public static final String ORDER_COMPLETE = "orderComplete"; - public static final String PAYMENT_REQUEST = "payment"; - public static final String FREE_TABLES = "freeTables"; - public static final String IS_EATING = "isEating"; - public static final String PAYMENT_DONE = "hasPaid"; - public static final String INFO = "info"; + public static final String GROUP_AGENT_TABLE_ASSIGNED = "groupAgentTables"; + public static final String ASSIGN_TABLE = "assignTable"; + public static final String TAKE_ORDER = "takeOrder"; + public static final String ORDER_TAKEN = "order"; + public static final String GROUP_AGENT_ORDER_TAKEN = "groupAgentOrder"; + public static final String DELIVER_PIZZAS = "deliverPizzas"; + public static final String PREPARE_PIZZAS = "preparePizzas"; + public static final String PIZZAS_IN_PROGRESS = "pizzasInProgress"; + public static final String ORDER_COMPLETE = "orderComplete"; + public static final String GROUP_AGENT_ORDER_COMPLETE = "groupAgentOrderComplete"; + public static final String PAYMENT_REQUEST = "payment"; + public static final String GROUP_AGENT_PAYMENT_REQUEST = "groupAgentPayment"; + public static final String FREE_TABLES = "freeTables"; + public static final String PAYMENT_DONE = "hasPaid"; + public static final String GROUP_AGENT_PAYMENT_DONE = "groupAgentHasPaid"; + public static final String PIZZERIA_INFO = "pizzeriaInfo"; + public static final String GROUP_AGENT_INFO = "groupAgentInfo"; private static Random random = new Random(); diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/group/GroupAgent.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/group/GroupAgent.java index bcf2251..31a84a1 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/group/GroupAgent.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/group/GroupAgent.java @@ -10,10 +10,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import javax.swing.*; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; +import java.util.*; /** * The Main class of the Group component. @@ -36,7 +33,7 @@ public class GroupAgent { notified about this somehow and the list has to be adapted as it is the model of the dropdown in the GUI for selecting for which pizzeria the customer groups are created In case of XVSM the identifier string is a port number*/ - private List pizzeriaIdentifiers = Collections.synchronizedList(new ArrayList()); + private Set pizzeriaIdentifiers = Collections.synchronizedSet(new HashSet()); public static GroupAgent groupAgent; @@ -69,6 +66,7 @@ public class GroupAgent { } else { xvsm = new GroupAgentXVSM(); + xvsm.listenForNewPizzerias(); xvsm.listenForTableAssigned(); xvsm.listenForOrdersTaken(); xvsm.listenForDeliveredOrders(); @@ -85,7 +83,7 @@ public class GroupAgent { return groupconn; } - public List getPizzeriaIdentifiers() { + public Set getPizzeriaIdentifiers() { return pizzeriaIdentifiers; } diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/group/gui/DeliveryOverviewModel.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/group/gui/DeliveryOverviewModel.java index b60054a..95431a9 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/group/gui/DeliveryOverviewModel.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/group/gui/DeliveryOverviewModel.java @@ -4,7 +4,6 @@ package at.ac.tuwien.sbc.valesriegler.group.gui; import at.ac.tuwien.sbc.valesriegler.common.TableModel; import at.ac.tuwien.sbc.valesriegler.common.Util; import at.ac.tuwien.sbc.valesriegler.group.DeliveryGroup; -import at.ac.tuwien.sbc.valesriegler.group.Group; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -19,7 +18,7 @@ public class DeliveryOverviewModel extends TableModel { private static final String ADDRESS = "Address"; private static final String ID = "ID"; private static final String PIZZERIA = "Pizzeria"; - private static final String[] COLUMNS = new String[] { ID, ADDRESS, PIZZAS, STATE, PIZZERIA }; + private static final String[] COLUMNS = new String[]{ID, ADDRESS, PIZZAS, STATE, PIZZERIA}; @Override diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/group/gui/GroupCreationDetailsPanel.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/group/gui/GroupCreationDetailsPanel.java index d60a965..374b822 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/group/gui/GroupCreationDetailsPanel.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/group/gui/GroupCreationDetailsPanel.java @@ -5,6 +5,7 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.ArrayList; import java.util.List; +import java.util.Set; import javax.swing.*; @@ -55,7 +56,7 @@ public class GroupCreationDetailsPanel extends JPanel { final JLabel pizzeriaLabel = new JLabel("Pizzeria: "); - final List pizzeriaIdentifiers = GroupAgent.getInstance().getPizzeriaIdentifiers(); + final Set pizzeriaIdentifiers = GroupAgent.getInstance().getPizzeriaIdentifiers(); for (String pizzeriaIdentifier : pizzeriaIdentifiers) { pizzeriaDropdown.addItem(pizzeriaIdentifier); } 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 9568130..58551db 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 @@ -82,6 +82,7 @@ public class PizzeriaAgent { xvsm = new PizzeriaAgentXVSM(port); xvsm.initializeOrderId(); + xvsm.notifyGroupAgent(); xvsm.listenForFreeTables(); xvsm.listenForTakenOrders(); diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/xvsm/AbstractXVSMConnector.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/xvsm/AbstractXVSMConnector.java index 95b68fd..4e0b861 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/xvsm/AbstractXVSMConnector.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/xvsm/AbstractXVSMConnector.java @@ -9,8 +9,6 @@ import org.mozartspaces.capi3.FifoCoordinator; import org.mozartspaces.capi3.LindaCoordinator; import org.mozartspaces.capi3.LindaCoordinator.LindaSelector; import org.mozartspaces.core.*; -import org.mozartspaces.core.config.CommonsXmlConfiguration; -import org.mozartspaces.core.config.Configuration; import org.mozartspaces.notifications.NotificationManager; import org.mozartspaces.notifications.Operation; import org.slf4j.Logger; @@ -31,18 +29,23 @@ public abstract class AbstractXVSMConnector { private static final Logger log = LoggerFactory.getLogger(AbstractXVSMConnector.class); protected ContainerReference tableAssignedContainer; + protected ContainerReference groupAgentTableAssignedContainer; protected ContainerReference assignTableContainer; protected ContainerReference takeOrderContainer; protected ContainerReference orderTakenContainer; + protected ContainerReference groupAgentOrderTakenContainer; protected ContainerReference preparePizzasContainer; protected ContainerReference deliverPizzasContainer; protected ContainerReference paymentRequestContainer; + protected ContainerReference groupAgentPaymentRequestContainer; protected ContainerReference freeTablesContainer; protected ContainerReference pizzaInProgressContainer; protected ContainerReference orderCompleteContainer; - protected ContainerReference isEatingContainer; + protected ContainerReference groupAgentOrderCompleteContainer; protected ContainerReference paymentDoneContainer; - protected ContainerReference infoContainer; + protected ContainerReference groupAgentPaymentDoneContainer; + protected ContainerReference pizzeriaInfoContainer; + protected ContainerReference groupAgentInfoContainer; protected Capi capi; protected NotificationManager notificationMgr; @@ -198,7 +201,7 @@ public abstract class AbstractXVSMConnector { protected TransactionReference getDefaultTransaction() throws MzsCoreException { return capi.createTransaction( - Util.SPACE_TRANSACTION_TIMEOUT, - URI.create(String.format(Util.SERVER_ADDR, port))); + Util.SPACE_TRANSACTION_TIMEOUT, + URI.create(String.format(Util.SERVER_ADDR, port))); } } \ No newline at end of file diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/xvsm/GroupAgentXVSM.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/xvsm/GroupAgentXVSM.java index 2bb5f4c..9087f2f 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/xvsm/GroupAgentXVSM.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/xvsm/GroupAgentXVSM.java @@ -1,30 +1,29 @@ package at.ac.tuwien.sbc.valesriegler.xvsm; -import java.io.Serializable; -import java.util.List; - -import javax.swing.SwingUtilities; - -import org.mozartspaces.core.MzsConstants.RequestTimeout; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import at.ac.tuwien.sbc.valesriegler.common.Util; import at.ac.tuwien.sbc.valesriegler.group.GroupAgent; import at.ac.tuwien.sbc.valesriegler.types.GroupData; import at.ac.tuwien.sbc.valesriegler.types.Table; +import org.mozartspaces.core.MzsConstants.RequestTimeout; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.swing.*; +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; public class GroupAgentXVSM extends AbstractXVSMConnector { private static final Logger log = LoggerFactory.getLogger(GroupAgentXVSM.class); public GroupAgentXVSM() { super(Util.GROUP_AGENT_PORT); -// assignTableContainer = useContainer(Util.ASSIGN_TABLE); - orderCompleteContainer = useContainer(Util.ORDER_COMPLETE) ; - paymentRequestContainer = useContainer(Util.PAYMENT_REQUEST) ; - paymentDoneContainer = useContainer(Util.PAYMENT_DONE); - tableAssignedContainer = useContainer(Util.TABLE_ASSIGNED); - orderTakenContainer = useContainer(Util.ORDER_TAKEN); + groupAgentOrderCompleteContainer = useContainer(Util.GROUP_AGENT_ORDER_COMPLETE); + groupAgentPaymentRequestContainer = useContainer(Util.GROUP_AGENT_PAYMENT_REQUEST) ; + groupAgentPaymentDoneContainer = useContainer(Util.GROUP_AGENT_PAYMENT_DONE); + groupAgentTableAssignedContainer = useContainer(Util.GROUP_AGENT_TABLE_ASSIGNED); + groupAgentOrderTakenContainer = useContainer(Util.GROUP_AGENT_ORDER_TAKEN); + groupAgentInfoContainer = useContainer(Util.GROUP_AGENT_INFO); } public void listenForDeliveredOrders() { @@ -43,7 +42,7 @@ public class GroupAgentXVSM extends AbstractXVSMConnector { }); } }; - createNotification(deliveredOrders, orderCompleteContainer); + createNotification(deliveredOrders, groupAgentOrderCompleteContainer); } @@ -64,7 +63,7 @@ public class GroupAgentXVSM extends AbstractXVSMConnector { }; - createNotification(paymentRequest, paymentRequestContainer); + createNotification(paymentRequest, groupAgentPaymentRequestContainer); } public void listenForPaymentDone() { @@ -83,7 +82,7 @@ public class GroupAgentXVSM extends AbstractXVSMConnector { } }; - createNotification(payment, paymentDoneContainer); + createNotification(payment, groupAgentPaymentDoneContainer); } public void listenForTableAssigned() { @@ -102,7 +101,7 @@ public class GroupAgentXVSM extends AbstractXVSMConnector { }); } }; - createNotification(tableAssignmentListener, tableAssignedContainer); + createNotification(tableAssignmentListener, groupAgentTableAssignedContainer); } @@ -121,11 +120,34 @@ public class GroupAgentXVSM extends AbstractXVSMConnector { }); } }; - createNotification(tableAssignmentListener, orderTakenContainer); + createNotification(tableAssignmentListener, groupAgentOrderTakenContainer); } public void sendNewGroupsToSpace(List groupData, int pizzeriaSpacePort) { sendItemsToContainer(groupData, useContainerOfSpaceWithPort(Util.ASSIGN_TABLE, pizzeriaSpacePort), RequestTimeout.DEFAULT, null); } + public void listenForNewPizzerias() { + SpaceListener newPizzeriaListener = new SpaceListenerImpl(capi, groupAgentInfoContainer, true) { + + @Override + void onEntriesWritten(List entries) throws Exception { + + final List pizzeriaRegistrations = castEntries(entries); + final List pizzeriaIds = new ArrayList<>(); + for (PizzeriaRegistration registration : pizzeriaRegistrations) { + pizzeriaIds.add(String.valueOf(registration.pizzeriaSpacePort)); + } + + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + GroupAgent.getInstance().getPizzeriaIdentifiers().addAll(pizzeriaIds); + } + }); + } + }; + createNotification(newPizzeriaListener, groupAgentInfoContainer); + + } } diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/xvsm/GroupXVSM.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/xvsm/GroupXVSM.java index 6a2b0d8..a2cbdff 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/xvsm/GroupXVSM.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/xvsm/GroupXVSM.java @@ -27,10 +27,11 @@ public class GroupXVSM extends AbstractXVSMConnector { super(port); this.groupId = groupId; - paymentRequestContainer = useContainer(Util.PAYMENT_REQUEST) ; - orderCompleteContainer = useContainer(Util.ORDER_COMPLETE) ; - isEatingContainer = useContainer(Util.IS_EATING) ; - freeTablesContainer = useContainer(Util.FREE_TABLES) ; + paymentRequestContainer = useContainerOfSpaceWithPort(Util.PAYMENT_REQUEST, port) ; + groupAgentPaymentRequestContainer = useContainerOfSpaceWithPort(Util.GROUP_AGENT_PAYMENT_REQUEST, Util.GROUP_AGENT_PORT); + orderCompleteContainer = useContainerOfSpaceWithPort(Util.ORDER_COMPLETE, port) ; +// isEatingContainer = useContainer(Util.IS_EATING) ; +// freeTablesContainer = useContainer(Util.FREE_TABLES) ; } public void waitForMyOrder() { @@ -68,6 +69,7 @@ public class GroupXVSM extends AbstractXVSMConnector { } sendItemsToContainer(Arrays.asList(groupData), paymentRequestContainer, RequestTimeout.DEFAULT, null); + sendItemsToContainer(Arrays.asList(groupData), groupAgentPaymentRequestContainer, RequestTimeout.DEFAULT, null); log.info("I sent my payment request to the space! GroupId: {}", groupId); } diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/xvsm/PizzeriaAgentXVSM.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/xvsm/PizzeriaAgentXVSM.java index b5824ab..8addaa5 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/xvsm/PizzeriaAgentXVSM.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/xvsm/PizzeriaAgentXVSM.java @@ -34,7 +34,7 @@ public class PizzeriaAgentXVSM extends AbstractXVSMConnector { paymentDoneContainer = useContainer(Util.PAYMENT_DONE) ; orderTakenContainer = useContainer(Util.ORDER_TAKEN); assignTableContainer = useContainer(Util.ASSIGN_TABLE); - infoContainer = useContainer(Util.INFO); + pizzeriaInfoContainer = useContainer(Util.PIZZERIA_INFO); } public void listenForOccupiedTables() { @@ -261,6 +261,10 @@ public void listenForTakenOrders() { public void initializeOrderId() { - sendItemsToContainer(Arrays.asList(new OrderId(0)), infoContainer, RequestTimeout.DEFAULT, null); + sendItemsToContainer(Arrays.asList(new OrderId(0)), pizzeriaInfoContainer, RequestTimeout.DEFAULT, null); + } + + public void notifyGroupAgent() { + sendItemsToContainer(Arrays.asList(new PizzeriaRegistration(port)), useContainerOfSpaceWithPort(Util.GROUP_AGENT_INFO, Util.GROUP_AGENT_PORT), RequestTimeout.DEFAULT, null); } } diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/xvsm/PizzeriaRegistration.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/xvsm/PizzeriaRegistration.java new file mode 100644 index 0000000..5e97112 --- /dev/null +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/xvsm/PizzeriaRegistration.java @@ -0,0 +1,16 @@ +package at.ac.tuwien.sbc.valesriegler.xvsm; + + +import java.io.Serializable; + +/** + * {@link PizzeriaRegistration} objects are written to the space to indicate the existance of a new pizzeria at the + * port specified by {@link PizzeriaRegistration#pizzeriaSpacePort} + */ +public class PizzeriaRegistration implements Serializable { + public final int pizzeriaSpacePort; + + public PizzeriaRegistration(int pizzeriaSpacePort) { + this.pizzeriaSpacePort = pizzeriaSpacePort; + } +} diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/xvsm/WaiterXVSM.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/xvsm/WaiterXVSM.java index 9e50245..815383e 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/xvsm/WaiterXVSM.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/xvsm/WaiterXVSM.java @@ -27,13 +27,18 @@ public class WaiterXVSM extends AbstractXVSMConnector { assignTableContainer = useContainer(Util.ASSIGN_TABLE); takeOrderContainer = useContainer(Util.TAKE_ORDER); orderTakenContainer = useContainer(Util.ORDER_TAKEN); + groupAgentOrderTakenContainer = useContainerOfSpaceWithPort(Util.GROUP_AGENT_ORDER_TAKEN, Util.GROUP_AGENT_PORT); preparePizzasContainer = useContainer(Util.PREPARE_PIZZAS); orderCompleteContainer = useContainer(Util.ORDER_COMPLETE); + groupAgentOrderCompleteContainer = useContainerOfSpaceWithPort(Util.GROUP_AGENT_ORDER_COMPLETE, Util.GROUP_AGENT_PORT); deliverPizzasContainer = useContainer(Util.DELIVER_PIZZAS); paymentRequestContainer = useContainer(Util.PAYMENT_REQUEST); + groupAgentPaymentRequestContainer = useContainerOfSpaceWithPort(Util.GROUP_AGENT_PAYMENT_REQUEST, Util.GROUP_AGENT_PORT); paymentDoneContainer = useContainer(Util.PAYMENT_DONE); + groupAgentPaymentDoneContainer = useContainerOfSpaceWithPort(Util.GROUP_AGENT_PAYMENT_DONE, Util.GROUP_AGENT_PORT); tableAssignedContainer = useContainer(Util.TABLE_ASSIGNED); - infoContainer = useContainer(Util.INFO); + groupAgentTableAssignedContainer = useContainerOfSpaceWithPort(Util.GROUP_AGENT_TABLE_ASSIGNED, Util.GROUP_AGENT_PORT); + pizzeriaInfoContainer = useContainer(Util.PIZZERIA_INFO); } public void listenForFreeTable() { @@ -140,7 +145,9 @@ public class WaiterXVSM extends AbstractXVSMConnector { groupData.setPayingWaiter(waiterId); - sendItemsToContainer(Arrays.asList(groupData), paymentDoneContainer, RequestTimeout.ZERO, tx); + final List groupsPayed = Arrays.asList(groupData); + sendItemsToContainer(groupsPayed, paymentDoneContainer, RequestTimeout.ZERO, tx); + sendItemsToContainer(groupsPayed, groupAgentPaymentDoneContainer, RequestTimeout.ZERO, null); capi.commitTransaction(tx); } catch (Exception e) { @@ -182,7 +189,7 @@ public class WaiterXVSM extends AbstractXVSMConnector { /* get the id of the last order of the pizzeria and set the order accordingly and update the space */ - final OrderId orderId = takeMatchingEntity(new OrderId(null), infoContainer, tx, RequestTimeout.INFINITE, "The Order id object could not be taken from the space!"); + final OrderId orderId = takeMatchingEntity(new OrderId(null), pizzeriaInfoContainer, tx, RequestTimeout.INFINITE, "The Order id object could not be taken from the space!"); final int id = orderId.getId(); final int nextId = id+1; order.setId(nextId); @@ -190,13 +197,16 @@ public class WaiterXVSM extends AbstractXVSMConnector { for (PizzaOrder orderedPizza : orderedPizzas) { orderedPizza.setOrderId(nextId); } - sendItemsToContainer(Arrays.asList(new OrderId(nextId)), infoContainer, RequestTimeout.DEFAULT, tx); + sendItemsToContainer(Arrays.asList(new OrderId(nextId)), pizzeriaInfoContainer, RequestTimeout.DEFAULT, tx); // send the order as a whole to the space - sendItemsToContainer(Arrays.asList(groupData), + final List groupsWhoHaveOrdered = Arrays.asList(groupData); + sendItemsToContainer(groupsWhoHaveOrdered, orderTakenContainer, RequestTimeout.ZERO, tx); sendItemsToContainer(order.getOrderedPizzas(), preparePizzasContainer, RequestTimeout.ZERO, tx); + sendItemsToContainer(groupsWhoHaveOrdered, + groupAgentOrderTakenContainer, RequestTimeout.ZERO, null); capi.commitTransaction(tx); log.info("Waiter has taken order from group {}", @@ -261,9 +271,13 @@ public class WaiterXVSM extends AbstractXVSMConnector { completeOrder.setId(orderId); completeOrder.setGroupId(groupId); group.setOrder(completeOrder); - sendItemsToContainer(Arrays.asList(group), - orderCompleteContainer, RequestTimeout.DEFAULT, - tx); + final List groupsWithCompleteOrder = Arrays.asList(group); + sendItemsToContainer(groupsWithCompleteOrder, + orderCompleteContainer, RequestTimeout.DEFAULT, + tx); + sendItemsToContainer(groupsWithCompleteOrder, + groupAgentOrderCompleteContainer, RequestTimeout.DEFAULT, + null); capi.commitTransaction(tx); } else { log.info("Not yet all pizzas prepared! Order with id " @@ -295,10 +309,13 @@ public class WaiterXVSM extends AbstractXVSMConnector { lockedGroup.setTable(lockedFreeTable); lockedGroup.setTableWaiter(waiterId); - sendItemsToContainer(Arrays.asList(lockedFreeTable), + final List freeTables = Arrays.asList(lockedFreeTable); + sendItemsToContainer(freeTables, tableAssignedContainer, RequestTimeout.ZERO, tx); sendItemsToContainer(Arrays.asList(lockedGroup), takeOrderContainer, RequestTimeout.ZERO, tx); + sendItemsToContainer(freeTables, + groupAgentTableAssignedContainer, RequestTimeout.ZERO, null); try { capi.commitTransaction(tx); diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/xvsm/cook/Cook.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/xvsm/cook/Cook.java index 2f15e90..ba647ef 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/xvsm/cook/Cook.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/xvsm/cook/Cook.java @@ -1,19 +1,19 @@ package at.ac.tuwien.sbc.valesriegler.xvsm.cook; + import at.ac.tuwien.sbc.valesriegler.common.Tuple; import at.ac.tuwien.sbc.valesriegler.common.Util; +import at.ac.tuwien.sbc.valesriegler.xvsm.CookXVSM; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import at.ac.tuwien.sbc.valesriegler.xvsm.CookXVSM; - public class Cook { private static final String USAGE = "Cook needs exactly two integer parameters: COOKID, PIZZERIA-SPACE-PORT"; private static final Logger log = LoggerFactory.getLogger(Cook.class); private final int pizzeriaPort; private final int id; - private CookXVSM xvsm; + private CookXVSM xvsm; public static void main(String[] args) { final Tuple cookIdAndSpacePort = Util.parseIdAndSpacePort(args, USAGE); @@ -22,13 +22,10 @@ public class Cook { cook.start(); } - private void start() { - xvsm = new CookXVSM(id, pizzeriaPort); - - xvsm.listenForPizzas(); - - - } + private void start() { + xvsm = new CookXVSM(id, pizzeriaPort); + xvsm.listenForPizzas(); + } public Cook(int id, int pizzeriaPort) { this.id = id; -- 2.43.0