From d5533ed5f648124a9e6203297c1d86aa706671ba Mon Sep 17 00:00:00 2001 From: Gregor Riegler Date: Wed, 1 May 2013 23:27:19 +0200 Subject: [PATCH] First running MozartSpaces communication: PizzeriaGUI writes free tables to space after creation and a waiter can read it. --- README.md | 16 ++- pom.xml | 83 +++++++++++++++- run Group.launch | 4 +- run Pizzeria.launch | 9 +- run Space Server.launch | 15 +++ run Waiter 1.launch | 21 ++++ .../sbc/valesriegler/common/PizzaType.java | 4 +- .../sbc/valesriegler/common/SpaceUtil.java | 28 ++++++ .../sbc/valesriegler/common/TableModel.java | 3 +- .../tuwien/sbc/valesriegler/group/Group.java | 3 +- .../sbc/valesriegler/group/GroupState.java | 4 +- .../sbc/valesriegler/group/MinimalGroup.java | 4 +- .../valesriegler/pizzeria/PizzeriaAgent.java | 98 +++++++++++++++++-- .../pizzeria/gui/PizzeriaFrame.java | 32 ++++-- .../sbc/valesriegler/pizzeria/gui/Table.java | 4 +- .../gui/tablemodels/OrdersOverviewModel.java | 4 - .../gui/tablemodels/TablesOverviewModel.java | 40 ++++---- .../sbc/valesriegler/xvsm/XVSMConnector.java | 67 +++++++++++++ .../sbc/valesriegler/xvsm/waiter/Waiter.java | 73 ++++++++++++++ src/main/resources/dummy | 1 - src/main/resources/log4j.properties | 3 +- src/main/resources/logback.xml | 67 +++++++++++++ src/main/resources/mozartspaces-client.xml | 12 +++ 23 files changed, 543 insertions(+), 52 deletions(-) create mode 100644 run Space Server.launch create mode 100644 run Waiter 1.launch create mode 100644 src/main/java/at/ac/tuwien/sbc/valesriegler/common/SpaceUtil.java create mode 100644 src/main/java/at/ac/tuwien/sbc/valesriegler/xvsm/XVSMConnector.java create mode 100644 src/main/java/at/ac/tuwien/sbc/valesriegler/xvsm/waiter/Waiter.java delete mode 100644 src/main/resources/dummy create mode 100644 src/main/resources/logback.xml create mode 100644 src/main/resources/mozartspaces-client.xml diff --git a/README.md b/README.md index 2f71a22..5f077b4 100644 --- a/README.md +++ b/README.md @@ -3,12 +3,20 @@ Space Based Computing SS 2013 ### How to start the Group GUI mvn exec:java -Dexec.mainClass="at.ac.tuwien.sbc.valesriegler.group.GroupAgent" -### How to start the Pizzeria GUI - mvn exec:java -Dexec.mainClass="at.ac.tuwien.sbc.valesriegler.pizzeria.PizzeriaAgent" +### How to start the JMS Pizzeria GUI + mvn exec:java -Dexec.mainClass="at.ac.tuwien.sbc.valesriegler.pizzeria.PizzeriaAgent" -Dexec.args="JMS" -### How to start a Waiter with Id 1 +### How to start a JMS Waiter with Id 1 mvn exec:java -Dexec.mainClass="at.ac.tuwien.sbc.valesriegler.jms.waiter.Waiter" -Dexec.args="1" -### How to start a Cook with Id 1 +### 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 the Space Pizzeria GUI + mvn exec:java -Dexec.mainClass="at.ac.tuwien.sbc.valesriegler.pizzeria.PizzeriaAgent" -Dexec.args="XVSM" -Dmozartspaces.configurationFile="mozartspaces-client.xml" + +### 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" \ No newline at end of file diff --git a/pom.xml b/pom.xml index 63c6872..fe96bd4 100644 --- a/pom.xml +++ b/pom.xml @@ -24,16 +24,34 @@ org.apache.activemq activemq-all 5.8.0 + + + ch.qos.logback + logback-classic + + + + org.mozartspaces + mozartspaces-runtime + 2.2-SNAPSHOT + + + ch.qos.logback + logback-classic + + + + - + @@ -55,6 +73,67 @@ + + + + + mozartspaces + http://www.mozartspaces.org/maven-snapshots + + + + + + 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/run Group.launch b/run Group.launch index fadfd2a..eed0477 100644 --- a/run Group.launch +++ b/run Group.launch @@ -5,7 +5,9 @@ - + + + diff --git a/run Pizzeria.launch b/run Pizzeria.launch index a31fc91..5f9ef6f 100644 --- a/run Pizzeria.launch +++ b/run Pizzeria.launch @@ -5,11 +5,14 @@ - + + + - - + + + diff --git a/run Space Server.launch b/run Space Server.launch new file mode 100644 index 0000000..c07f048 --- /dev/null +++ b/run Space Server.launch @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/run Waiter 1.launch b/run Waiter 1.launch new file mode 100644 index 0000000..66424de --- /dev/null +++ b/run Waiter 1.launch @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/common/PizzaType.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/common/PizzaType.java index ee61c7b..9e44555 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/common/PizzaType.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/common/PizzaType.java @@ -1,6 +1,8 @@ package at.ac.tuwien.sbc.valesriegler.common; -public enum PizzaType { +import java.io.Serializable; + +public enum PizzaType implements Serializable { MARGHERITA(5, 3), SALAMI(5.5, 7), CARDINALE(6,5); public final double price; diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/common/SpaceUtil.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/common/SpaceUtil.java new file mode 100644 index 0000000..81f7bf3 --- /dev/null +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/common/SpaceUtil.java @@ -0,0 +1,28 @@ +package at.ac.tuwien.sbc.valesriegler.common; + +import java.net.URI; +import java.util.List; + +import org.mozartspaces.capi3.Coordinator; +import org.mozartspaces.core.Capi; +import org.mozartspaces.core.ContainerReference; +import org.mozartspaces.core.MzsConstants.Container; +import org.mozartspaces.core.MzsConstants.RequestTimeout; +import org.mozartspaces.core.MzsCoreException; + +public abstract class SpaceUtil { + public static final String TABLES_CONTAINER = "tables"; + public static final String SERVER_ADDR = "xvsm://localhost:9876"; + public static ContainerReference getOrCreateNamedContainer(final String spaceUri, final String containerName, final Capi capi, final List coordinators) + throws MzsCoreException { + + ContainerReference container; + try { + container = capi.lookupContainer(containerName, URI.create(spaceUri), RequestTimeout.DEFAULT, null); + } catch (MzsCoreException e) { + container = capi.createContainer(containerName, URI.create(spaceUri), Container.UNBOUNDED, coordinators, null, null); + } + return container; + } + +} diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/common/TableModel.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/common/TableModel.java index 729a9dd..f03350a 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/common/TableModel.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/common/TableModel.java @@ -1,6 +1,7 @@ package at.ac.tuwien.sbc.valesriegler.common; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import javax.swing.table.AbstractTableModel; @@ -14,7 +15,7 @@ import javax.swing.table.AbstractTableModel; public abstract class TableModel extends AbstractTableModel { protected static final String UNHANDLEDCOLUMN = "Unhandled column"; - protected final List items = new ArrayList(); + protected final List items = Collections.synchronizedList(new ArrayList()); public void addItems(List newItems) { items.addAll(newItems); 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 f95187a..f7f87fb 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 @@ -1,11 +1,12 @@ package at.ac.tuwien.sbc.valesriegler.group; +import java.io.Serializable; import java.util.ArrayList; import java.util.List; import at.ac.tuwien.sbc.valesriegler.common.PizzaType; -public class Group { +public class Group implements Serializable { private MinimalGroup minimalGroup = new MinimalGroup(); private List pizzas = new ArrayList(); diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/group/GroupState.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/group/GroupState.java index c2f499b..1b9e817 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/group/GroupState.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/group/GroupState.java @@ -1,5 +1,7 @@ package at.ac.tuwien.sbc.valesriegler.group; -public enum GroupState { +import java.io.Serializable; + +public enum GroupState implements Serializable { WAITING, SITTING, ORDERED, EATING, PAY, GONE } diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/group/MinimalGroup.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/group/MinimalGroup.java index 1e4a317..dd97a4b 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/group/MinimalGroup.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/group/MinimalGroup.java @@ -1,11 +1,13 @@ package at.ac.tuwien.sbc.valesriegler.group; +import java.io.Serializable; + /** * A group bean which only has an id and a size. * * @author Gregor Riegler */ -public class MinimalGroup { +public class MinimalGroup implements Serializable { private int id; private int size; 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 a221c69..a45bf22 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,8 +1,31 @@ package at.ac.tuwien.sbc.valesriegler.pizzeria; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + import javax.swing.SwingUtilities; +import org.mozartspaces.capi3.AnyCoordinator; +import org.mozartspaces.capi3.Coordinator; +import org.mozartspaces.core.Capi; +import org.mozartspaces.core.ContainerReference; +import org.mozartspaces.core.DefaultMzsCore; +import org.mozartspaces.core.Entry; +import org.mozartspaces.core.MzsCore; +import org.mozartspaces.core.MzsCoreException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import at.ac.tuwien.sbc.valesriegler.common.SpaceUtil; import at.ac.tuwien.sbc.valesriegler.pizzeria.gui.PizzeriaFrame; +import at.ac.tuwien.sbc.valesriegler.pizzeria.gui.Table; +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.xvsm.XVSMConnector; /** * The Main class of the Pizzeria compoment. *

@@ -12,21 +35,82 @@ import at.ac.tuwien.sbc.valesriegler.pizzeria.gui.PizzeriaFrame; * */ public class PizzeriaAgent { + private static final Logger log = LoggerFactory.getLogger(PizzeriaAgent.class); + + private static final String USAGE = "Usage: java PizzeriaAgent XVSM|JMS"; + + private OrdersOverviewModel ordersModel; + private GroupsOverviewModel groupModel; + private TablesOverviewModel tablesModel; + private WaitersOfOrderModel waitersModel; + private PizzasOfOrderModel pizzasModel; + + private XVSMConnector xvsm; public static void main(String[] args) { - // TODO initiate communication - - SwingUtilities.invokeLater(new PizzeriaGUI()); - + if(args.length != 1) { + throw new IllegalArgumentException(USAGE); + } else { + String mom = args[0]; + log.info(mom); + PizzeriaAgent pizzeriaAgent = new PizzeriaAgent(); + switch(mom) { + case "XVSM" : pizzeriaAgent.createModels(); pizzeriaAgent.initXVSM(); pizzeriaAgent.initGUI(); break; + case "JMS" : pizzeriaAgent.createModels(); pizzeriaAgent.initJMS(); pizzeriaAgent.initGUI(); break; + default : throw new IllegalArgumentException(USAGE); + } + + } + } + + private void initJMS() { + // do what you have to do + } + + private void initXVSM() { + try { + xvsm = new XVSMConnector(); + xvsm.initSpaceCommunication(); + + } catch (MzsCoreException e) { + log.error(e.getMessage()); + log.error("The Pizzeria has no Space connection! Have you started the Space Server?"); + System.exit(1); + } + } + + private void initGUI() { + PizzeriaGUI gui = new PizzeriaGUI(); + SwingUtilities.invokeLater(gui); } - static class PizzeriaGUI implements Runnable { + class PizzeriaGUI implements Runnable { @Override public void run() { - PizzeriaFrame frame = new PizzeriaFrame(); + PizzeriaFrame frame = new PizzeriaFrame(ordersModel, groupModel, tablesModel, waitersModel, pizzasModel); + frame.setOnTablesCreatedHandler(new TablesCreatedHandler() { + + @Override + public void freeTablesCreated(List tables) { + xvsm.sendFreeTablesToSpace(tables); + } + + }); + frame.start(); frame.pack(); frame.setVisible(true); } } - + + private void createModels() { + ordersModel = new OrdersOverviewModel(); + groupModel = new GroupsOverviewModel(); + tablesModel = new TablesOverviewModel(); + waitersModel = new WaitersOfOrderModel(); + pizzasModel = new PizzasOfOrderModel(); + } + + public interface TablesCreatedHandler { + public void freeTablesCreated(List
tables); + } } 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 75f46aa..4783393 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 @@ -22,6 +22,8 @@ import javax.swing.event.TableModelListener; import at.ac.tuwien.sbc.valesriegler.common.PizzaType; 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; import at.ac.tuwien.sbc.valesriegler.pizzeria.gui.PizzaOrder.PizzaOrderStatus; import at.ac.tuwien.sbc.valesriegler.pizzeria.gui.tablemodels.GroupsOverviewModel; import at.ac.tuwien.sbc.valesriegler.pizzeria.gui.tablemodels.OrdersOverviewModel; @@ -48,10 +50,20 @@ public class PizzeriaFrame extends JFrame { private TablesOverviewModel tablesModel; private WaitersOfOrderModel waitersModel; private PizzasOfOrderModel pizzasModel; + + private TablesCreatedHandler onTablesCreatedHandler; - public PizzeriaFrame() { + public PizzeriaFrame(OrdersOverviewModel ordersModel, GroupsOverviewModel groupModel, TablesOverviewModel tablesModel, WaitersOfOrderModel waitersModel, PizzasOfOrderModel pizzasModel) { super("Pizzeria"); + + this.ordersModel = ordersModel; + this.groupModel = groupModel; + this.tablesModel = tablesModel; + this.waitersModel = waitersModel; + this.pizzasModel = pizzasModel; + } + public void start() { initModels(); JPanel wrapper = new JPanel(); @@ -99,12 +111,13 @@ public class PizzeriaFrame extends JFrame { private void initModels() { 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); + onTablesCreatedHandler.freeTablesCreated(freeTablesCreated); - ordersModel = new OrdersOverviewModel(orders); - groupModel = new GroupsOverviewModel(); - tablesModel = new TablesOverviewModel(getNumberOfTables()); - waitersModel = new WaitersOfOrderModel(); - pizzasModel = new PizzasOfOrderModel(); } private void initOrdersDetails(JPanel wrapper, JTable ordersTable) { @@ -204,6 +217,9 @@ public class PizzeriaFrame extends JFrame { return table; } + /** + * not necessary in production + */ private List getOrdersTestData() { List orders = new ArrayList<>(); Order order1 = new Order(); @@ -238,4 +254,8 @@ public class PizzeriaFrame extends JFrame { return String.format(FREE_TABLES, tablesModel.getNumberOfFreeTables()); } + public void setOnTablesCreatedHandler(PizzeriaAgent.TablesCreatedHandler tablesCreatedHandler) { + this.onTablesCreatedHandler = tablesCreatedHandler; + } + } diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/Table.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/Table.java index 5ee0531..90fdf42 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/Table.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/Table.java @@ -1,6 +1,8 @@ package at.ac.tuwien.sbc.valesriegler.pizzeria.gui; -public class Table { +import java.io.Serializable; + +public class Table implements Serializable { private int id; private TableStatus status; 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 abdbfae..5d4f47c 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 @@ -16,10 +16,6 @@ public class OrdersOverviewModel extends TableModel { ID, TABLE_ID, GROUP_ID, STATUS }; - public OrdersOverviewModel(List defaultOrders) { - setItems(defaultOrders); - } - @Override public Object getValueAt(int rowIndex, int columnIndex) { Order order = items.get(rowIndex); 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 67c1311..1bf9c3f 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 @@ -15,11 +15,6 @@ public class TablesOverviewModel extends TableModel
{ TABLE_ID, STATUS, GROUP_ID }; private int idCounter = 1; - - public TablesOverviewModel(int numberOfTables) { - createFreeTables(numberOfTables); - } - @Override protected String[] getColumns() { @@ -39,23 +34,34 @@ public class TablesOverviewModel extends TableModel
{ } public int getNumberOfFreeTables() { - int i=0; - for(Table table : items) { - if(table.getStatus() == TableStatus.FREE) { - i = i+1; + return getIdsOfFreeTables().size(); + } + + public List getIdsOfFreeTables() { + List ids = new ArrayList<>(); + + synchronized(items) { + for(Table table : items) { + if(table.getStatus() == TableStatus.FREE) { + ids.add(table.getId()); + } } } - return i; + + return ids; } - - private void createFreeTables(int numberOfTables) { - List
tables = new ArrayList
(); - for(int i=0; i createFreeTables(int numberOfTables) { + synchronized(items) { + List
tables = new ArrayList
(); + for(int i=0; i + * + */ +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())); + } + + public void sendFreeTablesToSpace(List
tables) { + try { + List entries = new ArrayList<>(); + 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<>(); + try { + tables = capi.take(tablesContainer); + } catch (MzsCoreException e) { + log.error(e.getMessage()); + e.printStackTrace(); + System.exit(1); + } + return tables; + } + +} 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 new file mode 100644 index 0000000..f16e843 --- /dev/null +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/xvsm/waiter/Waiter.java @@ -0,0 +1,73 @@ +package at.ac.tuwien.sbc.valesriegler.xvsm.waiter; + +import java.io.Serializable; +import java.util.List; + +import org.mozartspaces.core.MzsCoreException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import at.ac.tuwien.sbc.valesriegler.pizzeria.gui.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) { + throw new IllegalArgumentException(USAGE); + } + + int parsedId = 0; + try { + parsedId = Integer.parseInt(args[0]); + } catch (NumberFormatException e) { + log.error(USAGE); + return; + } + + Waiter waiter = new Waiter(parsedId); + waiter.start(); + } + + private void start() { + initSpaceCommunication(); + + List
tables = xvsm.readTables(); + + log.info("Number of free tables received: {}", tables.size()); + + } + + private void initSpaceCommunication() { + try { + xvsm = new XVSMConnector(); + xvsm.initSpaceCommunication(); + } catch (MzsCoreException e) { + log.error(e.getMessage()); + 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) { + this.id = id; + log.info("I AM A WAITER WITH ID {}", id); + } + +} + diff --git a/src/main/resources/dummy b/src/main/resources/dummy deleted file mode 100644 index 2a51033..0000000 --- a/src/main/resources/dummy +++ /dev/null @@ -1 +0,0 @@ -just a dummy such that git can maintain the directory structure needed by maven \ No newline at end of file diff --git a/src/main/resources/log4j.properties b/src/main/resources/log4j.properties index dc58a1c..101a101 100644 --- a/src/main/resources/log4j.properties +++ b/src/main/resources/log4j.properties @@ -8,4 +8,5 @@ log4j.appender.A1=org.apache.log4j.ConsoleAppender log4j.appender.A1.layout=org.apache.log4j.PatternLayout log4j.appender.A1.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n -log4j.category.org.apache.wicket=WARN \ No newline at end of file +log4j.category.org.apache.wicket=WARN +log4j.category.org.mozartspaces=WARN \ No newline at end of file diff --git a/src/main/resources/logback.xml b/src/main/resources/logback.xml new file mode 100644 index 0000000..552fd62 --- /dev/null +++ b/src/main/resources/logback.xml @@ -0,0 +1,67 @@ + + + + + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/mozartspaces-client.xml b/src/main/resources/mozartspaces-client.xml new file mode 100644 index 0000000..36185f0 --- /dev/null +++ b/src/main/resources/mozartspaces-client.xml @@ -0,0 +1,12 @@ + + false + + + + 0 + + + + ${remoting.defaultScheme}://localhost:${remoting.transports.tcpsocket.receiverPort} + + -- 2.43.0