From 952f21b80d0320582221a72b3ed2fb651475ecf4 Mon Sep 17 00:00:00 2001 From: Someone Date: Fri, 7 Jun 2013 03:45:49 +0200 Subject: [PATCH] added required server-URL parameter and Driver --- .../tuwien/sbc/valesriegler/common/Util.java | 222 +++++++++--------- .../sbc/valesriegler/cook/CookAgent.java | 8 +- .../sbc/valesriegler/cook/jms/JMSCook.java | 12 +- .../jms/messageListeners/OrdersToCook.java | 3 +- .../sbc/valesriegler/driver/DriverAgent.java | 42 ++++ .../valesriegler/driver/jms/JMSDriver.java | 52 ++++ .../group/jms/JMSGroupConnector.java | 6 +- .../valesriegler/pizzeria/PizzeriaAgent.java | 136 +++++------ .../pizzeria/jms/JMSPizzeriaConnector.java | 9 +- .../sbc/valesriegler/waiter/WaiterAgent.java | 8 +- .../valesriegler/waiter/jms/JMSWaiter.java | 17 +- .../jms/messageListeners/CookedOrders.java | 3 +- .../jms/messageListeners/WantToOrder.java | 3 +- .../jms/messageListeners/WantToPay.java | 3 +- .../messageListeners/WantToSitAtTable.java | 3 +- 15 files changed, 321 insertions(+), 206 deletions(-) create mode 100644 src/main/java/at/ac/tuwien/sbc/valesriegler/driver/DriverAgent.java create mode 100644 src/main/java/at/ac/tuwien/sbc/valesriegler/driver/jms/JMSDriver.java 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 5a5f6f7..bbf57c0 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 @@ -1,42 +1,53 @@ package at.ac.tuwien.sbc.valesriegler.common; -import at.ac.tuwien.sbc.valesriegler.types.PizzaOrder; -import at.ac.tuwien.sbc.valesriegler.types.PizzaType; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.Insets; +import java.net.URI; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Random; +import java.util.Set; + +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTable; +import javax.swing.ScrollPaneConstants; +import javax.swing.border.TitledBorder; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import javax.swing.*; -import javax.swing.border.TitledBorder; -import java.awt.*; -import java.net.URI; -import java.util.*; -import java.util.List; +import at.ac.tuwien.sbc.valesriegler.types.PizzaOrder; +import at.ac.tuwien.sbc.valesriegler.types.PizzaType; 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 ASSIGN_TABLE = "assignTable"; - public static final String TAKE_ORDER = "takeOrder"; - public static final String ORDER_TAKEN = "order"; - public static final String DELIVERY_ORDER_TAKEN = "deliverOrderTaken"; - public static final String DELIVER_PIZZAS = "deliverPizzas"; - public static final String DELIVER_DELIVERY_PIZZAS = "deliverDeliveryPizzas"; - public static final String DELIVER_DELIVERY_ORDER = "deliverDeliveryOrderContainer"; - public static final String PREPARE_PIZZAS = "preparePizzas"; - public static final String PREPARE_DELIVERY_PIZZAS = "prepareDeliveryPizzas"; - 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 PAYMENT_DONE = "hasPaid"; - public static final String PIZZERIA_INFO = "pizzeriaInfo"; - public static final String PHONE_CALLS = "phoneCalls"; - public static final String GROUP_AGENT_INFO = "groupAgentInfo"; - public static final String PIZZERIA_GROUP = "pizzeriaGroupContainer"; - public static final String PIZZERIA_TABLE = "pizzeriaTableContainer"; - public static final String PIZZERIA_DELIVERY = "pizzeriaDeliveryContainer"; + 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 DELIVERY_ORDER_TAKEN = "deliverOrderTaken"; + public static final String DELIVER_PIZZAS = "deliverPizzas"; + public static final String DELIVER_DELIVERY_PIZZAS = "deliverDeliveryPizzas"; + public static final String DELIVER_DELIVERY_ORDER = "deliverDeliveryOrderContainer"; + public static final String PREPARE_PIZZAS = "preparePizzas"; + public static final String PREPARE_DELIVERY_PIZZAS = "prepareDeliveryPizzas"; + 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 PAYMENT_DONE = "hasPaid"; + public static final String PIZZERIA_INFO = "pizzeriaInfo"; + public static final String PHONE_CALLS = "phoneCalls"; + public static final String GROUP_AGENT_INFO = "groupAgentInfo"; + public static final String PIZZERIA_GROUP = "pizzeriaGroupContainer"; + public static final String PIZZERIA_TABLE = "pizzeriaTableContainer"; + public static final String PIZZERIA_DELIVERY = "pizzeriaDeliveryContainer"; private static Random random = new Random(); @@ -46,7 +57,7 @@ public abstract class Util { public static final int GROUP_AGENT_PORT = 9876; public static final int DELIVERY_CUSTOMERS_PORT = 9877; - public static final String JMS_CONNECTSTRING = "tcp://localhost:61616?jms.prefetchPolicy.all=1"; + // public static final String JMS_CONNECTSTRING = "tcp://localhost:61616?jms.prefetchPolicy.all=1"; public static String getId(int id) { return (id != 0 && id != -1) ? String.valueOf(id) : ""; @@ -56,9 +67,9 @@ public abstract class Util { return nr == null ? 0 : nr; } - public static URI createURI(int port) { - return URI.create(String.format(SERVER_ADDR, port)); - } + public static URI createURI(int port) { + return URI.create(String.format(SERVER_ADDR, port)); + } public static Map intoMapById(List hasIds) { if (hasIds == null) { @@ -76,77 +87,76 @@ public abstract class Util { return random.nextInt(max - min + 1) + min; } - public static Tuple parseIdAndSpacePort(String[] args, String usage) { - if (args.length != 2) { - throw new IllegalArgumentException(usage); - } - - int parsedId = 0; - int port = 0; - try { - parsedId = Integer.parseInt(args[0]); - port = Integer.parseInt(args[1]); - } catch (NumberFormatException e) { - throw new IllegalArgumentException(usage); - } - - return new Tuple(parsedId, port); - } - - public static JTable createTableInTitledPanel(JPanel wrapperPanel, TableModel model, String title) { - JTable table = new JTable(model); - wrapperPanel.setLayout(new GridBagLayout()); - GridBagConstraints c = new GridBagConstraints(); - c.gridx = 0; - c.weightx = 1; - c.weighty = 1; - c.insets = new Insets(10, 10, 10, 10); - c.fill = GridBagConstraints.BOTH; - JScrollPane scrollPane = new JScrollPane(table); - - wrapperPanel.setBorder(new TitledBorder(title)); - scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED); - wrapperPanel.add(scrollPane, c); - table.setAutoCreateRowSorter(true); - return table; - } - - /** - * - * @return A display string for PizzaTypes. - *

- * e.g. Cardinale, Cardinale, Margherita is displayed as - * "2xCARDINALE,1xMARGHERITA" - */ - public static String pizzaDisplay(List list) { - HashMap pizzaCount = new HashMap(); - for (PizzaOrder pizzaOrder : list) { - PizzaType pizzaType = pizzaOrder.getPizzaType(); - if (pizzaCount.containsKey(pizzaType)) { - pizzaCount.put(pizzaType, pizzaCount.get(pizzaType) + 1); - } else - pizzaCount.put(pizzaType, 1); - } - Set pizzaTypes = pizzaCount.keySet(); - StringBuilder sb = new StringBuilder(); - - boolean multiplePizzas = false; - for (PizzaType pizzaType : pizzaTypes) { - if (multiplePizzas) - sb.append(", "); - else - multiplePizzas = true; - - sb.append(pizzaCount.get(pizzaType) + "x"); - sb.append(pizzaType.toString()); - } - - return sb.toString(); - } - - public static void handleSpaceErrorAndTerminate(Exception e) { - log.error(e.getMessage()); - e.printStackTrace(); - System.exit(1); - } + public static Tuple parseIdAndSpacePort(String[] args, String usage) { + if (args.length != 2) { + throw new IllegalArgumentException(usage); + } + + int parsedId = 0; + int port = 0; + try { + parsedId = Integer.parseInt(args[0]); + port = Integer.parseInt(args[1]); + } catch (NumberFormatException e) { + throw new IllegalArgumentException(usage); + } + + return new Tuple(parsedId, port); + } + + public static JTable createTableInTitledPanel(JPanel wrapperPanel, TableModel model, String title) { + JTable table = new JTable(model); + wrapperPanel.setLayout(new GridBagLayout()); + GridBagConstraints c = new GridBagConstraints(); + c.gridx = 0; + c.weightx = 1; + c.weighty = 1; + c.insets = new Insets(10, 10, 10, 10); + c.fill = GridBagConstraints.BOTH; + JScrollPane scrollPane = new JScrollPane(table); + + wrapperPanel.setBorder(new TitledBorder(title)); + scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED); + wrapperPanel.add(scrollPane, c); + table.setAutoCreateRowSorter(true); + return table; + } + + /** + * + * @return A display string for PizzaTypes. + *

+ * e.g. Cardinale, Cardinale, Margherita is displayed as "2xCARDINALE,1xMARGHERITA" + */ + public static String pizzaDisplay(List list) { + HashMap pizzaCount = new HashMap(); + for (PizzaOrder pizzaOrder : list) { + PizzaType pizzaType = pizzaOrder.getPizzaType(); + if (pizzaCount.containsKey(pizzaType)) { + pizzaCount.put(pizzaType, pizzaCount.get(pizzaType) + 1); + } else + pizzaCount.put(pizzaType, 1); + } + Set pizzaTypes = pizzaCount.keySet(); + StringBuilder sb = new StringBuilder(); + + boolean multiplePizzas = false; + for (PizzaType pizzaType : pizzaTypes) { + if (multiplePizzas) + sb.append(", "); + else + multiplePizzas = true; + + sb.append(pizzaCount.get(pizzaType) + "x"); + sb.append(pizzaType.toString()); + } + + return sb.toString(); + } + + public static void handleSpaceErrorAndTerminate(Exception e) { + log.error(e.getMessage()); + e.printStackTrace(); + System.exit(1); + } } diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/cook/CookAgent.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/cook/CookAgent.java index ec58592..985fafb 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/cook/CookAgent.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/cook/CookAgent.java @@ -12,18 +12,18 @@ import at.ac.tuwien.sbc.valesriegler.cook.jms.JMSCook; * */ public class CookAgent { - private static final String USAGE = "This application needs exactly 2 parameters: <\"XVSM\"|\"JMS\"> "; + private static final String USAGE = "This application needs exactly 2 parameters: <\"XVSM\"|\"JMS\"> "; private static final Logger log = LoggerFactory.getLogger(CookAgent.class); public static void main(String[] args) throws Exception { - if (args.length != 2) { + if (args.length != 3) { throw new IllegalArgumentException(USAGE); } String mw = args[0]; int parsedId = 0; try { - parsedId = Integer.parseInt(args[1]); + parsedId = Integer.parseInt(args[2]); } catch (NumberFormatException e) { log.error(USAGE); return; @@ -31,7 +31,7 @@ public class CookAgent { log.info("Middleware: " + mw + " ID:" + parsedId); if ("JMS".equalsIgnoreCase(mw)) { - new JMSCook(parsedId); + new JMSCook(args[1], parsedId); } else if ("XVSM".equalsIgnoreCase(mw)) { // TODO: XVSM Cook? } else { diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/cook/jms/JMSCook.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/cook/jms/JMSCook.java index 103bd0f..c2378da 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/cook/jms/JMSCook.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/cook/jms/JMSCook.java @@ -10,7 +10,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import at.ac.tuwien.sbc.valesriegler.common.HasId; -import at.ac.tuwien.sbc.valesriegler.common.Util; import at.ac.tuwien.sbc.valesriegler.cook.jms.messageListeners.OrdersToCook; /** @@ -21,16 +20,17 @@ import at.ac.tuwien.sbc.valesriegler.cook.jms.messageListeners.OrdersToCook; */ public class JMSCook implements HasId { private static final Logger log = LoggerFactory.getLogger(JMSCook.class); - + private final String CONNECTSTRING; final private int id; - public JMSCook(int id) { + public JMSCook(String jmsURL, int id) { + CONNECTSTRING = jmsURL; this.id = id; log.info("I AM A JMSCook WITH ID {}", this.id); try { // Connecting to the Broker and to the output queue - ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(Util.JMS_CONNECTSTRING); + ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(CONNECTSTRING); Connection connection = connectionFactory.createConnection(); connection.start(); @@ -42,6 +42,10 @@ public class JMSCook implements HasId { } } + public String getCONNECTSTRING() { + return CONNECTSTRING; + } + @Override public int getId() { return id; diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/cook/jms/messageListeners/OrdersToCook.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/cook/jms/messageListeners/OrdersToCook.java index 0bdb17e..5c61c7b 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/cook/jms/messageListeners/OrdersToCook.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/cook/jms/messageListeners/OrdersToCook.java @@ -13,7 +13,6 @@ import org.apache.activemq.ActiveMQConnectionFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import at.ac.tuwien.sbc.valesriegler.common.Util; import at.ac.tuwien.sbc.valesriegler.cook.actions.OrderInfo; import at.ac.tuwien.sbc.valesriegler.cook.jms.JMSCook; import at.ac.tuwien.sbc.valesriegler.group.actions.OrderRequest; @@ -52,7 +51,7 @@ public class OrdersToCook implements MessageListener { pizzaorder.setStatus(PizzaOrderStatus.IN_PREPARATION); } - ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(Util.JMS_CONNECTSTRING); + ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(cook.getCONNECTSTRING()); Connection connection = connectionFactory.createConnection(); connection.start(); diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/driver/DriverAgent.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/driver/DriverAgent.java new file mode 100644 index 0000000..303dff5 --- /dev/null +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/driver/DriverAgent.java @@ -0,0 +1,42 @@ +package at.ac.tuwien.sbc.valesriegler.driver; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import at.ac.tuwien.sbc.valesriegler.cook.jms.JMSCook; + +/** + * DriverAgent parses the arguments and runs the JMS/XVSMDriver with the given ID. + * + * @author jan + * + */ +public class DriverAgent { + private static final String USAGE = "This application needs exactly 2 parameters: <\"XVSM\"|\"JMS\"> "; + private static final Logger log = LoggerFactory.getLogger(DriverAgent.class); + + public static void main(String[] args) throws Exception { + if (args.length != 3) { + throw new IllegalArgumentException(USAGE); + } + + String mw = args[0]; + int parsedId = 0; + try { + parsedId = Integer.parseInt(args[2]); + } catch (NumberFormatException e) { + log.error(USAGE); + return; + } + + log.info("Middleware: " + mw + " ID:" + parsedId); + if ("JMS".equalsIgnoreCase(mw)) { + new JMSCook(args[1], parsedId); + } else if ("XVSM".equalsIgnoreCase(mw)) { + // TODO: XVSM Driver? + } else { + throw new IllegalArgumentException(USAGE); + } + } + +} diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/driver/jms/JMSDriver.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/driver/jms/JMSDriver.java new file mode 100644 index 0000000..2aac4e7 --- /dev/null +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/driver/jms/JMSDriver.java @@ -0,0 +1,52 @@ +package at.ac.tuwien.sbc.valesriegler.driver.jms; + +import javax.jms.Connection; +import javax.jms.JMSException; + +import org.apache.activemq.ActiveMQConnectionFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import at.ac.tuwien.sbc.valesriegler.common.HasId; + +/** + * JMSDriver registers all the Listeners. + * + * @author jan + * + */ +public class JMSDriver implements HasId { + private static final Logger log = LoggerFactory.getLogger(JMSDriver.class); + private final String CONNECTSTRING; + public String getCONNECTSTRING() { + return CONNECTSTRING; + } + + final private int id; + + public JMSDriver(String jmsURL, int id) { + CONNECTSTRING = jmsURL; + this.id = id; + log.info("I AM A JMSCook WITH ID {}", this.id); + + try { + // Connecting to the Broker and to the output queue + ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(CONNECTSTRING); + Connection connection = connectionFactory.createConnection(); + connection.start(); + + // Session sessWantToSit = connection.createSession(false, + // Session.CLIENT_ACKNOWLEDGE); + // MessageConsumer consWantToSit = + // sessWantToSit.createConsumer(sessWantToSit.createQueue("OrdersToCook")); + // consWantToSit.setMessageListener(new OrdersToCook(this)); + } catch (JMSException e) { + log.error("EXCEPTION!", e); + } + } + + @Override + public int getId() { + return id; + } +} 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 831eeb5..fd7965f 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 @@ -15,7 +15,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import at.ac.tuwien.sbc.valesriegler.common.AbstractAction; -import at.ac.tuwien.sbc.valesriegler.common.Util; import at.ac.tuwien.sbc.valesriegler.group.AbstractGroupConnector; import at.ac.tuwien.sbc.valesriegler.group.Group; import at.ac.tuwien.sbc.valesriegler.group.GroupAgent; @@ -36,13 +35,14 @@ import at.ac.tuwien.sbc.valesriegler.waiter.actions.DeliverOrder; */ public class JMSGroupConnector extends AbstractGroupConnector implements MessageListener { private static final Logger log = LoggerFactory.getLogger(JMSGroupConnector.class); - + // FIXME: how to communicate?! + public static final String JMS_CONNECTSTRING = "tcp://localhost:61616?jms.prefetchPolicy.all=1"; private Connection connection; @Override public void init() { try { - connection = new ActiveMQConnectionFactory(Util.JMS_CONNECTSTRING).createConnection(); + connection = new ActiveMQConnectionFactory(JMS_CONNECTSTRING).createConnection(); connection.start(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageConsumer consumer = session.createConsumer(session.createQueue("GroupConnector")); 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 06435c5..4f9687c 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 @@ -1,17 +1,25 @@ package at.ac.tuwien.sbc.valesriegler.pizzeria; +import java.util.List; + +import javax.swing.SwingUtilities; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import at.ac.tuwien.sbc.valesriegler.common.Util; import at.ac.tuwien.sbc.valesriegler.pizzeria.actions.TableNew; import at.ac.tuwien.sbc.valesriegler.pizzeria.gui.PizzeriaFrame; -import at.ac.tuwien.sbc.valesriegler.pizzeria.gui.tablemodels.*; +import at.ac.tuwien.sbc.valesriegler.pizzeria.gui.tablemodels.DeliveryDetailsModel; +import at.ac.tuwien.sbc.valesriegler.pizzeria.gui.tablemodels.DeliveryOrdersModel; +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.pizzeria.jms.JMSPizzeriaConnector; import at.ac.tuwien.sbc.valesriegler.types.Table; import at.ac.tuwien.sbc.valesriegler.xvsm.PizzeriaAgentXVSM; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.swing.*; -import java.util.List; /** * The Main class of the Pizzeria compoment. @@ -22,7 +30,7 @@ import java.util.List; * @author jan */ public class PizzeriaAgent { - private static final String USAGE = "This application needs 2 parameters: <\"XVSM\"|\"JMS\"> "; + private static final String USAGE = "This application needs 2 parameters: <\"XVSM\"|\"JMS\"> "; private static final Logger log = LoggerFactory.getLogger(PizzeriaAgent.class); private static PizzeriaAgent pizzeriaAgent; @@ -32,11 +40,11 @@ public class PizzeriaAgent { private TablesOverviewModel tablesModel; private WaitersOfOrderModel waitersModel; private PizzasOfOrderModel pizzasOfOrderModel; - private DeliveryDetailsModel deliveryDetailsModel; - private PizzasOfOrderModel pizzasOfDeliveryModel; - private DeliveryOrdersModel deliveryOrdersModel; + private DeliveryDetailsModel deliveryDetailsModel; + private PizzasOfOrderModel pizzasOfDeliveryModel; + private DeliveryOrdersModel deliveryOrdersModel; - private PizzeriaAgentXVSM xvsm; + private PizzeriaAgentXVSM xvsm; private JMSPizzeriaConnector jmspc; public static void main(String[] args) { @@ -47,53 +55,49 @@ public class PizzeriaAgent { log.info("Middleware: " + mw); pizzeriaAgent = new PizzeriaAgent(); switch (mw) { - case "XVSM": - pizzeriaAgent.createModels(); - pizzeriaAgent.initXVSM(args[1]); - pizzeriaAgent.initGUI(); - Util.useJMS = false; - break; - case "JMS": - pizzeriaAgent.createModels(); - pizzeriaAgent.initJMS(); - pizzeriaAgent.initGUI(); - Util.useJMS = true; - break; - default: - throw new IllegalArgumentException(USAGE); + case "XVSM" : + pizzeriaAgent.createModels(); + pizzeriaAgent.initXVSM(args[1]); + pizzeriaAgent.initGUI(); + Util.useJMS = false; + break; + case "JMS" : + pizzeriaAgent.createModels(); + pizzeriaAgent.jmspc = new JMSPizzeriaConnector(args[1]); + pizzeriaAgent.jmspc.init(); + pizzeriaAgent.initGUI(); + Util.useJMS = true; + break; + default : + throw new IllegalArgumentException(USAGE); } } - private void initJMS() { - jmspc = new JMSPizzeriaConnector(); - jmspc.init(); - } - private void initXVSM(String arg) { - int port = 0; - try { - port = Integer.parseInt(arg); - } catch (NumberFormatException e) { - log.error("The XVSM-Space-Identifier needs to be an integer port!"); - System.exit(1); - } - - xvsm = new PizzeriaAgentXVSM(port); - xvsm.initializeOrderId(); - xvsm.notifyGroupAgent(); - -// xvsm.listenForFreeTables(); -// xvsm.listenForTakenOrders(); - xvsm.listenForTakenDeliveryOrders(); -// xvsm.listenForWaitingGroups(); - xvsm.listenForPizzasInPreparation(); -// xvsm.listenForDeliveredOrders(); - xvsm.listenForPreparedPizzas(); - xvsm.listenForTables(); - xvsm.listenForGroups(); -// xvsm.listenForPayment(); -// xvsm.listenForOccupiedTables(); - } + int port = 0; + try { + port = Integer.parseInt(arg); + } catch (NumberFormatException e) { + log.error("The XVSM-Space-Identifier needs to be an integer port!"); + System.exit(1); + } + + xvsm = new PizzeriaAgentXVSM(port); + xvsm.initializeOrderId(); + xvsm.notifyGroupAgent(); + + // xvsm.listenForFreeTables(); + // xvsm.listenForTakenOrders(); + xvsm.listenForTakenDeliveryOrders(); + // xvsm.listenForWaitingGroups(); + xvsm.listenForPizzasInPreparation(); + // xvsm.listenForDeliveredOrders(); + xvsm.listenForPreparedPizzas(); + xvsm.listenForTables(); + xvsm.listenForGroups(); + // xvsm.listenForPayment(); + // xvsm.listenForOccupiedTables(); + } private void initGUI() { PizzeriaGUI gui = new PizzeriaGUI(); @@ -129,9 +133,9 @@ public class PizzeriaAgent { tablesModel = new TablesOverviewModel(); waitersModel = new WaitersOfOrderModel(); pizzasOfOrderModel = new PizzasOfOrderModel(); - deliveryOrdersModel = new DeliveryOrdersModel(); - deliveryDetailsModel = new DeliveryDetailsModel(); - pizzasOfDeliveryModel = new PizzasOfOrderModel(); + deliveryOrdersModel = new DeliveryOrdersModel(); + deliveryDetailsModel = new DeliveryDetailsModel(); + pizzasOfDeliveryModel = new PizzasOfOrderModel(); } public static PizzeriaAgent getInstance() { @@ -142,17 +146,17 @@ public class PizzeriaAgent { return ordersModel; } - public DeliveryOrdersModel getDeliveryOrdersModel() { - return deliveryOrdersModel; - } + public DeliveryOrdersModel getDeliveryOrdersModel() { + return deliveryOrdersModel; + } - public DeliveryDetailsModel getDeliveryDetailsModel() { - return deliveryDetailsModel; - } + public DeliveryDetailsModel getDeliveryDetailsModel() { + return deliveryDetailsModel; + } - public PizzasOfOrderModel getPizzasOfDeliveryModel() { - return pizzasOfDeliveryModel; - } + public PizzasOfOrderModel getPizzasOfDeliveryModel() { + return pizzasOfDeliveryModel; + } public GroupsOverviewModel getGroupModel() { return groupModel; 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 index 8b71caf..e2d71d9 100644 --- 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 @@ -17,7 +17,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import at.ac.tuwien.sbc.valesriegler.common.AbstractAction; -import at.ac.tuwien.sbc.valesriegler.common.Util; import at.ac.tuwien.sbc.valesriegler.cook.actions.OrderInfo; import at.ac.tuwien.sbc.valesriegler.group.actions.OrderResponse; import at.ac.tuwien.sbc.valesriegler.group.actions.PayResponse; @@ -39,13 +38,17 @@ import at.ac.tuwien.sbc.valesriegler.waiter.actions.DeliverOrder; */ public class JMSPizzeriaConnector extends AbstractPizzeriaConnector implements MessageListener { private static final Logger log = LoggerFactory.getLogger(JMSPizzeriaConnector.class); - + private final String CONNECTSTRING; private Connection connection; + public JMSPizzeriaConnector(String jmsURL) { + CONNECTSTRING = jmsURL; + } + @Override public void init() { try { - connection = new ActiveMQConnectionFactory(Util.JMS_CONNECTSTRING).createConnection(); + connection = new ActiveMQConnectionFactory(CONNECTSTRING).createConnection(); connection.start(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageConsumer consumer = session.createConsumer(session.createQueue("PizzeriaConnector")); diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/waiter/WaiterAgent.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/waiter/WaiterAgent.java index 591d133..0e59f52 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/waiter/WaiterAgent.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/waiter/WaiterAgent.java @@ -13,18 +13,18 @@ import at.ac.tuwien.sbc.valesriegler.waiter.jms.JMSWaiter; * */ public class WaiterAgent { - private static final String USAGE = "This application needs exactly 2 parameters: <\"XVSM\"|\"JMS\"> "; + private static final String USAGE = "This application needs exactly 2 parameters: <\"XVSM\"|\"JMS\"> "; private static final Logger log = LoggerFactory.getLogger(WaiterAgent.class); public static void main(String[] args) { - if (args.length != 2) { + if (args.length != 3) { throw new IllegalArgumentException(USAGE); } String mw = args[0]; int parsedId = 0; try { - parsedId = Integer.parseInt(args[1]); + parsedId = Integer.parseInt(args[2]); } catch (NumberFormatException e) { log.error(USAGE); return; @@ -32,7 +32,7 @@ public class WaiterAgent { log.info("Middleware: " + mw + " ID:" + parsedId); if ("JMS".equalsIgnoreCase(mw)) { - new JMSWaiter(parsedId); + new JMSWaiter(args[1], parsedId); } else if ("XVSM".equalsIgnoreCase(mw)) { // TODO: XVSM Waiter? } else { diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/waiter/jms/JMSWaiter.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/waiter/jms/JMSWaiter.java index d483127..ea22a61 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/waiter/jms/JMSWaiter.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/waiter/jms/JMSWaiter.java @@ -1,7 +1,5 @@ package at.ac.tuwien.sbc.valesriegler.waiter.jms; -import java.io.Serializable; - import javax.jms.Connection; import javax.jms.MessageConsumer; import javax.jms.Session; @@ -10,7 +8,7 @@ import org.apache.activemq.ActiveMQConnectionFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import at.ac.tuwien.sbc.valesriegler.common.Util; +import at.ac.tuwien.sbc.valesriegler.common.HasId; import at.ac.tuwien.sbc.valesriegler.waiter.jms.messageListeners.CookedOrders; import at.ac.tuwien.sbc.valesriegler.waiter.jms.messageListeners.WantToOrder; import at.ac.tuwien.sbc.valesriegler.waiter.jms.messageListeners.WantToPay; @@ -23,17 +21,23 @@ import at.ac.tuwien.sbc.valesriegler.waiter.jms.messageListeners.WantToSitAtTabl * @author jan * */ -public class JMSWaiter implements Serializable { +public class JMSWaiter implements HasId { private static final Logger log = LoggerFactory.getLogger(JMSWaiter.class); + private final String CONNECTSTRING; + public String getCONNECTSTRING() { + return CONNECTSTRING; + } + final private int id; - public JMSWaiter(int id) { + public JMSWaiter(String jmsURL, int id) { + CONNECTSTRING = jmsURL; this.id = id; log.info("I AM A WAITER WITH ID {}", id); try { // Connecting to the Broker and to the output queue - ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(Util.JMS_CONNECTSTRING); + ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(CONNECTSTRING); Connection connection = connectionFactory.createConnection(); connection.start(); @@ -63,6 +67,7 @@ public class JMSWaiter implements Serializable { return "Waiter [id=" + id + "]"; } + @Override public int getId() { return id; } diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/waiter/jms/messageListeners/CookedOrders.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/waiter/jms/messageListeners/CookedOrders.java index 443962e..d7cb5f5 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/waiter/jms/messageListeners/CookedOrders.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/waiter/jms/messageListeners/CookedOrders.java @@ -13,7 +13,6 @@ import org.apache.activemq.ActiveMQConnectionFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import at.ac.tuwien.sbc.valesriegler.common.Util; import at.ac.tuwien.sbc.valesriegler.cook.actions.OrderInfo; import at.ac.tuwien.sbc.valesriegler.types.OrderStatus; import at.ac.tuwien.sbc.valesriegler.waiter.actions.DeliverOrder; @@ -49,7 +48,7 @@ public class CookedOrders implements MessageListener { // generate random delay Thread.sleep((long) (Math.random() * 10000)); - ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(Util.JMS_CONNECTSTRING); + ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(waiter.getCONNECTSTRING()); Connection connection = connectionFactory.createConnection(); connection.start(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); 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 916a610..77f4711 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 @@ -13,7 +13,6 @@ import org.apache.activemq.ActiveMQConnectionFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import at.ac.tuwien.sbc.valesriegler.common.Util; import at.ac.tuwien.sbc.valesriegler.group.actions.OrderRequest; import at.ac.tuwien.sbc.valesriegler.group.actions.OrderResponse; import at.ac.tuwien.sbc.valesriegler.waiter.jms.JMSWaiter; @@ -48,7 +47,7 @@ public class WantToOrder implements MessageListener { // generate random delay Thread.sleep((long) (Math.random() * 10000)); - ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(Util.JMS_CONNECTSTRING); + ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(waiter.getCONNECTSTRING()); Connection connection = connectionFactory.createConnection(); connection.start(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); 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 3952be7..6776695 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 @@ -13,7 +13,6 @@ import org.apache.activemq.ActiveMQConnectionFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import at.ac.tuwien.sbc.valesriegler.common.Util; 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.jms.JMSWaiter; @@ -48,7 +47,7 @@ public class WantToPay implements MessageListener { // generate random delay Thread.sleep((long) (Math.random() * 10000)); - ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(Util.JMS_CONNECTSTRING); + ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(waiter.getCONNECTSTRING()); Connection connection = connectionFactory.createConnection(); connection.start(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); 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 6dce8d8..a62e151 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 @@ -14,7 +14,6 @@ import org.apache.activemq.ActiveMQConnectionFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import at.ac.tuwien.sbc.valesriegler.common.Util; import at.ac.tuwien.sbc.valesriegler.group.actions.TableRequest; import at.ac.tuwien.sbc.valesriegler.group.actions.TableResponse; import at.ac.tuwien.sbc.valesriegler.types.Table; @@ -50,7 +49,7 @@ public class WantToSitAtTable implements MessageListener { // generate random delay Thread.sleep((long) (Math.random() * 10000)); - ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(Util.JMS_CONNECTSTRING); + ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(waiter.getCONNECTSTRING()); Connection connection = connectionFactory.createConnection(); connection.start(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); -- 2.43.0