From d392f8fde8e0b396cfa4698aec2ac21efca54021 Mon Sep 17 00:00:00 2001 From: Jan Vales Date: Sun, 12 May 2013 23:27:56 +0200 Subject: [PATCH] unified command line argument parsing a little. --- .../sbc/valesriegler/cook/CookAgent.java | 5 +++ .../sbc/valesriegler/group/GroupAgent.java | 44 ++++++++++++------- .../valesriegler/pizzeria/PizzeriaAgent.java | 20 ++++----- .../sbc/valesriegler/waiter/WaiterAgent.java | 5 +++ 4 files changed, 46 insertions(+), 28 deletions(-) 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 0e5356e..ec58592 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 @@ -29,8 +29,13 @@ public class CookAgent { return; } + log.info("Middleware: " + mw + " ID:" + parsedId); if ("JMS".equalsIgnoreCase(mw)) { new JMSCook(parsedId); + } else if ("XVSM".equalsIgnoreCase(mw)) { + // TODO: XVSM Cook? + } else { + throw new IllegalArgumentException(USAGE); } } 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 48896ee..cad536b 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 @@ -5,7 +5,6 @@ import java.util.List; import javax.swing.SwingUtilities; -import org.mozartspaces.core.MzsConstants.RequestTimeout; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -25,28 +24,41 @@ import at.ac.tuwien.sbc.valesriegler.xvsm.GroupAgentXVSM; * */ public class GroupAgent { - + private static final String USAGE = "This application needs exactly 1 parameter: <\"XVSM\"|\"JMS\">"; + private static final Logger log = LoggerFactory.getLogger(GroupAgent.class); private GroupOverviewModel groupModel; private AbstractGroupConnector groupconn; private GroupAgentXVSM xvsm; - + public static GroupAgent groupAgent; public static void main(String[] args) { - // TODO: use jms and xvsm manager here. - groupAgent = new GroupAgent(new JMSGroupConnector()); - + if (args.length != 1) { + throw new IllegalArgumentException(USAGE); + } + + String mw = args[0]; + log.info("Middleware: " + mw); + + if ("JMS".equalsIgnoreCase(mw)) { + groupAgent = new GroupAgent(new JMSGroupConnector()); + } else if ("XVSM".equalsIgnoreCase(mw)) { + // TODO: XVSM Connector? + groupAgent = new GroupAgent(new JMSGroupConnector()); + } else { + throw new IllegalArgumentException(USAGE); + } + SwingUtilities.invokeLater(new GroupGUI()); } - public GroupAgent(JMSGroupConnector groupconn) { + public GroupAgent(AbstractGroupConnector groupconn) { groupModel = new GroupOverviewModel(); - if(Util.useJMS) { + if (Util.useJMS) { this.groupconn = groupconn; groupconn.init(); - } - else { + } else { xvsm = new GroupAgentXVSM(); xvsm.listenForTableAssigned(); @@ -70,19 +82,19 @@ public class GroupAgent { } public void onGroupsCreated(List newGroups) { - if(!Util.useJMS) { + if (!Util.useJMS) { List groupData = new ArrayList<>(); - + for (Group group : newGroups) { groupData.add(group.getGroupData()); } xvsm.sendNewGroupsToSpace(groupData); - + log.info("New Groups were sent to the space"); - - // start the space group in a new thread + + // start the space group in a new thread for (GroupData group : groupData) { - new Thread(new SpaceGroup(group.getId())).start(); + new Thread(new SpaceGroup(group.getId())).start(); } } 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 9115ac6..fea4978 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 @@ -28,10 +28,9 @@ import at.ac.tuwien.sbc.valesriegler.xvsm.PizzeriaAgentXVSM; * @author jan */ public class PizzeriaAgent { + private static final String USAGE = "This application needs exactly 1 parameter: <\"XVSM\"|\"JMS\">"; private static final Logger log = LoggerFactory.getLogger(PizzeriaAgent.class); - private static final String USAGE = "Usage: java PizzeriaAgent XVSM|JMS"; - private static PizzeriaAgent pizzeriaAgent; private OrdersOverviewModel ordersModel; @@ -43,15 +42,14 @@ public class PizzeriaAgent { private PizzeriaAgentXVSM xvsm; private JMSPizzeriaConnector jmspc; - public static void main(String[] args) {// TODO: remove hardcoding of JMS. - // if (args.length != 1) { - // throw new IllegalArgumentException(USAGE); - // } else { - // String mom = "XVSM";// args[0]; - String mom = Util.useJMS ? "JMS" : "XVSM"; - log.info(mom); + public static void main(String[] args) { + if (args.length != 1) { + throw new IllegalArgumentException(USAGE); + } + String mw = args[0]; + log.info("Middleware: " + mw); pizzeriaAgent = new PizzeriaAgent(); - switch (mom) { + switch (mw) { case "XVSM": pizzeriaAgent.createModels(); pizzeriaAgent.initXVSM(); @@ -65,8 +63,6 @@ public class PizzeriaAgent { default: throw new IllegalArgumentException(USAGE); } - - // } } private void initJMS() { 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 6540656..591d133 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 @@ -30,8 +30,13 @@ public class WaiterAgent { return; } + log.info("Middleware: " + mw + " ID:" + parsedId); if ("JMS".equalsIgnoreCase(mw)) { new JMSWaiter(parsedId); + } else if ("XVSM".equalsIgnoreCase(mw)) { + // TODO: XVSM Waiter? + } else { + throw new IllegalArgumentException(USAGE); } } } -- 2.43.0