From 60cb77efecad38c6da261608b5588807cb5ea42c Mon Sep 17 00:00:00 2001 From: Jan Vales Date: Mon, 6 May 2013 00:42:22 +0200 Subject: [PATCH] =?utf8?q?added=20info=20to=20pizzeria=20when=20a=20p?= =?utf8?q?=C3=BCizza=20is=20done.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../valesriegler/cook/actions/PizzaInfo.java | 32 +++++++++++++++++++ .../messageListeners/CookRequestedPizza.java | 11 +++++-- .../group/jms/JMSGroupConnector.java | 4 +-- 3 files changed, 43 insertions(+), 4 deletions(-) create mode 100644 src/main/java/at/ac/tuwien/sbc/valesriegler/cook/actions/PizzaInfo.java diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/cook/actions/PizzaInfo.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/cook/actions/PizzaInfo.java new file mode 100644 index 0000000..6248827 --- /dev/null +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/cook/actions/PizzaInfo.java @@ -0,0 +1,32 @@ +package at.ac.tuwien.sbc.valesriegler.cook.actions; + +import java.io.Serializable; + +import at.ac.tuwien.sbc.valesriegler.group.actions.AbstractAction; +import at.ac.tuwien.sbc.valesriegler.types.PizzaOrderStatus; + +public class PizzaInfo extends AbstractAction implements Serializable { + private final int pizzaId; + private final PizzaOrderStatus status; + private final int cookId; + + public PizzaInfo(int pizzaId, PizzaOrderStatus status, int cookId) { + super(null); + this.pizzaId = pizzaId; + this.status = status; + this.cookId = cookId; + } + + public int getPizzaId() { + return pizzaId; + } + + public PizzaOrderStatus getStatus() { + return status; + } + + public int getCookId() { + return cookId; + } + +} diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/cook/jms/messageListeners/CookRequestedPizza.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/cook/jms/messageListeners/CookRequestedPizza.java index dfd6baf..a689b61 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/cook/jms/messageListeners/CookRequestedPizza.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/cook/jms/messageListeners/CookRequestedPizza.java @@ -14,8 +14,10 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import at.ac.tuwien.sbc.valesriegler.cook.JMSCook; +import at.ac.tuwien.sbc.valesriegler.cook.actions.PizzaInfo; import at.ac.tuwien.sbc.valesriegler.types.Pizza; import at.ac.tuwien.sbc.valesriegler.types.PizzaOrder; +import at.ac.tuwien.sbc.valesriegler.types.PizzaOrderStatus; public class CookRequestedPizza implements MessageListener { private static final Logger log = LoggerFactory.getLogger(CookRequestedPizza.class); @@ -39,18 +41,23 @@ public class CookRequestedPizza implements MessageListener { // generate random delay Thread.sleep((long) (pizzaorder.getPizzaType().duration * 1000)); + pizzaorder.setStatus(PizzaOrderStatus.DONE); ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://localhost:61616"); Connection connection = connectionFactory.createConnection(); connection.start(); - Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); + Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageProducer prodCP = session.createProducer(session.createQueue("CookedPizzas")); prodCP.setDeliveryMode(DeliveryMode.NON_PERSISTENT); - prodCP.send(session.createObjectMessage(Pizza.createPizzaFromPizzaOrder(pizzaorder, cook))); + MessageProducer wantToSitAtTable = session.createProducer(session.createQueue("PizzeriaConnector")); + wantToSitAtTable.setDeliveryMode(DeliveryMode.NON_PERSISTENT); + PizzaInfo pi = new PizzaInfo(pizzaorder.getId(), pizzaorder.getStatus(), cook.getId()); + wantToSitAtTable.send(session.createObjectMessage(pi)); session.close(); + connection.close(); } else { log.warn("Received unknown Object: " + obj); 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 58784ce..ab6c479 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 @@ -88,7 +88,7 @@ public class JMSGroupConnector extends AbstractGroupConnector implements Message session.close(); session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); - MessageProducer informPizzariaGui = session.createProducer(session.createQueue("PizzariaConnector")); + MessageProducer informPizzariaGui = session.createProducer(session.createQueue("PizzeriaConnector")); informPizzariaGui.setDeliveryMode(DeliveryMode.NON_PERSISTENT); informPizzariaGui.send(session.createObjectMessage(request)); session.close(); @@ -101,7 +101,7 @@ public class JMSGroupConnector extends AbstractGroupConnector implements Message session.close(); session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); - MessageProducer informPizzariaGui = session.createProducer(session.createQueue("PizzariaConnector")); + MessageProducer informPizzariaGui = session.createProducer(session.createQueue("PizzeriaConnector")); informPizzariaGui.setDeliveryMode(DeliveryMode.NON_PERSISTENT); informPizzariaGui.send(session.createObjectMessage(request)); session.close(); -- 2.43.0