From aeaa4f885d6b73e3f05be6cbaf9fc64532d84324 Mon Sep 17 00:00:00 2001 From: Someone Date: Mon, 10 Jun 2013 02:01:41 +0200 Subject: [PATCH] [JMS] OLD workflow now works with dynamic pizzerias. --- .../tuwien/sbc/valesriegler/group/Group.java | 1 + .../group/jms/GroupJMSNACMsgListener.java | 17 ++++-------- .../jms/PizzeriaJMSNACMsgListener.java | 2 ++ .../tuwien/sbc/valesriegler/types/Order.java | 26 +++++++++++-------- 4 files changed, 23 insertions(+), 23 deletions(-) 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 4ab8fdf..13b2b83 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 @@ -49,6 +49,7 @@ public class Group implements Runnable, HasId { JMSGroupConnector.getConnector(groupData.getPizzeriaId()).send(new TableRequest(groupData)); break; case SITTING : + groupData.getOrder().genId(); JMSGroupConnector.getConnector(groupData.getPizzeriaId()).send(new OrderRequest(groupData)); order(); break; diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/group/jms/GroupJMSNACMsgListener.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/group/jms/GroupJMSNACMsgListener.java index af51779..5485fbe 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/group/jms/GroupJMSNACMsgListener.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/group/jms/GroupJMSNACMsgListener.java @@ -33,8 +33,9 @@ public class GroupJMSNACMsgListener extends AbstractJMSNACMsgListener implements if (msg instanceof ObjectMessage) { ObjectMessage objMsg = (ObjectMessage) msg; Object obj = objMsg.getObject(); - - if (obj instanceof AddressInfoResponse) { + if (obj instanceof AddressInfoRequest) { + // DO NOTHING. + } else if (obj instanceof AddressInfoResponse) { AddressInfoResponse response = (AddressInfoResponse) obj; GroupAgent.getInstance().getPizzeriaIdentifiers().add(response.getAddress()); if (!Util.runSimulation) { @@ -55,17 +56,9 @@ public class GroupJMSNACMsgListener extends AbstractJMSNACMsgListener implements public void run() { while (true) { try { - getJmsnac().sendNACMsg(new AddressInfoRequest()); - } catch (Exception e) { - log.warn("EXCEPTION!", e); - } - try { - Thread.sleep(10000); - } catch (InterruptedException e) { - log.warn("EXCEPTION!", e); - } - try { + Thread.sleep(15000); GroupAgent.getInstance().getPizzeriaIdentifiers().clear(); + getJmsnac().sendNACMsg(new AddressInfoRequest()); } catch (Exception e) { log.warn("EXCEPTION!", e); } diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/jms/PizzeriaJMSNACMsgListener.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/jms/PizzeriaJMSNACMsgListener.java index 3c2deb0..80271c1 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/jms/PizzeriaJMSNACMsgListener.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/jms/PizzeriaJMSNACMsgListener.java @@ -30,6 +30,8 @@ public class PizzeriaJMSNACMsgListener extends AbstractJMSNACMsgListener { if (obj instanceof AddressInfoRequest) { AddressInfoResponse air = new AddressInfoResponse(PizzeriaAgent.getInstance().getJmspc().getCONNECTSTRING()); PizzeriaAgent.getInstance().getJmsnac().sendNACMsg(air); + } else if (obj instanceof AddressInfoResponse) { + // DO NOTHING. } else { log.warn("Received unknown Object: " + obj); } diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/types/Order.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/types/Order.java index 215e666..687d84b 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/types/Order.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/types/Order.java @@ -1,13 +1,14 @@ package at.ac.tuwien.sbc.valesriegler.types; -import at.ac.tuwien.sbc.valesriegler.common.HasId; -import at.ac.tuwien.sbc.valesriegler.common.Util; -import org.mozartspaces.capi3.Queryable; - import java.io.Serializable; import java.util.ArrayList; import java.util.List; +import org.mozartspaces.capi3.Queryable; + +import at.ac.tuwien.sbc.valesriegler.common.HasId; +import at.ac.tuwien.sbc.valesriegler.common.Util; + /** * Object denotes a Group's interest in pizzas and the state of the pizzas * themselves. @@ -32,8 +33,8 @@ public class Order implements Serializable, HasId { } public Order(int groupId, List orderedPizzas) { - // TODO don't set the id here but let the waiter set it - id = ++idNext; + // TODO don't set the id here but let the waiter set it + // genId(); this.groupId = groupId; status = OrderStatus.NEW; this.orderedPizzas = orderedPizzas; @@ -41,17 +42,17 @@ public class Order implements Serializable, HasId { } public Order(HasId group, List orderedPizzas) { - // TODO don't set the id here but let the waiter set it - id = ++idNext; + // TODO don't set the id here but let the waiter set it + // genId(); groupId = group.getId(); status = OrderStatus.NEW; this.orderedPizzas = orderedPizzas; cookedPizzas = new ArrayList(); } - public void addCookedPizza(Pizza pizza) { - cookedPizzas.add(pizza); - } + public void addCookedPizza(Pizza pizza) { + cookedPizzas.add(pizza); + } public List getCookedPizzas() { return cookedPizzas; @@ -72,6 +73,9 @@ public class Order implements Serializable, HasId { public void setId(Integer id) { this.id = id; } + public void genId() { + id = ++idNext; + } @Override public int getId() { -- 2.43.0