From db21f25017e82a40096d5c486a92c0843edd3fd8 Mon Sep 17 00:00:00 2001 From: Someone Date: Mon, 10 Jun 2013 14:28:12 +0200 Subject: [PATCH] [JMS] NEW Workflow: cook now gets the order. --- .../group/actions/DeliveryOrderResponse.java | 31 +++++++++++++++++++ .../valesriegler/waiter/jms/JMSWaiter.java | 6 ++++ .../jms/messageListeners/WantADelivery.java | 28 ++++++++++++++++- 3 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 src/main/java/at/ac/tuwien/sbc/valesriegler/group/actions/DeliveryOrderResponse.java diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/group/actions/DeliveryOrderResponse.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/group/actions/DeliveryOrderResponse.java new file mode 100644 index 0000000..ea0e830 --- /dev/null +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/group/actions/DeliveryOrderResponse.java @@ -0,0 +1,31 @@ +package at.ac.tuwien.sbc.valesriegler.group.actions; + +import java.io.Serializable; + +import at.ac.tuwien.sbc.valesriegler.common.AbstractDeliveryAction; +import at.ac.tuwien.sbc.valesriegler.types.DeliveryGroupData; + +/** + * This is the phonecall to a pizzeria. + * + * @author jan + * + */ +public class DeliveryOrderResponse extends AbstractDeliveryAction implements Serializable { + private final int waiterId; + + public DeliveryOrderResponse(DeliveryGroupData deliveryGroupData, int waiterId) { + super(deliveryGroupData); + this.waiterId = waiterId; + } + + @Override + public String toString() { + return "DeliveryOrderResponse [getDeliveryGroupData()=" + getDeliveryGroupData() + "]"; + } + + public int getWaiterId() { + return waiterId; + } + +} 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 ea22a61..8ba3124 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 @@ -10,6 +10,7 @@ import org.slf4j.LoggerFactory; 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.WantADelivery; import at.ac.tuwien.sbc.valesriegler.waiter.jms.messageListeners.WantToOrder; import at.ac.tuwien.sbc.valesriegler.waiter.jms.messageListeners.WantToPay; import at.ac.tuwien.sbc.valesriegler.waiter.jms.messageListeners.WantToSitAtTable; @@ -57,6 +58,11 @@ public class JMSWaiter implements HasId { MessageConsumer consWantToPay = sessWantToPay.createConsumer(sessWantToPay.createQueue("WantToPay")); consWantToPay.setMessageListener(new WantToPay(this)); + Session sessWantADelivery = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); + MessageConsumer consWantADelivery = sessWantADelivery.createConsumer(sessWantADelivery + .createQueue("WantADelivery")); + consWantADelivery.setMessageListener(new WantADelivery(this)); + } catch (Exception e) { log.error("Caught: ", e); } diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/waiter/jms/messageListeners/WantADelivery.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/waiter/jms/messageListeners/WantADelivery.java index 86ffdd0..e9d0f0d 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/waiter/jms/messageListeners/WantADelivery.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/waiter/jms/messageListeners/WantADelivery.java @@ -1,14 +1,20 @@ package at.ac.tuwien.sbc.valesriegler.waiter.jms.messageListeners; +import javax.jms.Connection; +import javax.jms.DeliveryMode; import javax.jms.JMSException; import javax.jms.Message; import javax.jms.MessageListener; +import javax.jms.MessageProducer; import javax.jms.ObjectMessage; +import javax.jms.Session; +import org.apache.activemq.ActiveMQConnectionFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import at.ac.tuwien.sbc.valesriegler.group.actions.DeliveryOrderRequest; +import at.ac.tuwien.sbc.valesriegler.group.actions.DeliveryOrderResponse; import at.ac.tuwien.sbc.valesriegler.waiter.jms.JMSWaiter; /** @@ -41,7 +47,27 @@ public class WantADelivery implements MessageListener { // generate random delay Thread.sleep((long) (Math.random() * 10000)); - // TODO + ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(waiter.getCONNECTSTRING()); + Connection connection = connectionFactory.createConnection(); + connection.start(); + Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); + DeliveryOrderResponse or = new DeliveryOrderResponse(dor.getDeliveryGroupData(), waiter.getId()); + + // Make cooks do their work + MessageProducer prodOP = session.createProducer(session.createQueue("DeliveryOrdersToCook")); + prodOP.setDeliveryMode(DeliveryMode.NON_PERSISTENT); + // TODO: hack + dor.getDeliveryGroupData().setWaiterIdOfOrder(waiter.getId()); + prodOP.send(session.createObjectMessage(dor)); + + // inform Group + Pizzeria + MessageProducer informGroup = session.createProducer(session.createQueue("GroupConnector")); + informGroup.setDeliveryMode(DeliveryMode.NON_PERSISTENT); + informGroup.send(session.createObjectMessage(or)); + + MessageProducer informPizzeria = session.createProducer(session.createQueue("PizzeriaConnector")); + informPizzeria.setDeliveryMode(DeliveryMode.NON_PERSISTENT); + informPizzeria.send(session.createObjectMessage(or)); } else { log.warn("Received unknown Object: " + obj); -- 2.43.0