From e26430af9c2a1e0e891dfaa635656d124907c945 Mon Sep 17 00:00:00 2001 From: Jan Vales Date: Mon, 10 Jun 2013 17:15:54 +0200 Subject: [PATCH] [JMS] NEW WorkFlow works now. --- runJMS.sh | 2 +- .../common/AbstractDeliveryAction.java | 13 +++++++++--- .../DeliveryOrdersToCook.java | 4 ++-- .../driver/actions/OrderDeliveredInfo.java | 20 ++++++++++++------- .../valesriegler/driver/jms/JMSDriver.java | 2 +- .../CookedDeliveryOrders.java | 17 ++++++++-------- .../sbc/valesriegler/group/GroupAgent.java | 2 +- 7 files changed, 37 insertions(+), 23 deletions(-) diff --git a/runJMS.sh b/runJMS.sh index fad31d5..7bf81ca 100755 --- a/runJMS.sh +++ b/runJMS.sh @@ -25,7 +25,7 @@ echo "*** continuing launch process ***" # Run Groupgui -mvn exec:java -Dexec.mainClass="at.ac.tuwien.sbc.valesriegler.group.GroupAgent" -Dexec.args="JMS" & +mvn exec:java -Dexec.mainClass="at.ac.tuwien.sbc.valesriegler.group.GroupAgent" -Dexec.args="JMS tcp://localhost:61610?jms.prefetchPolicy.all=1" & #run pizzeria1 ./runJMSPizzaria.sh "tcp://localhost:61621?jms.prefetchPolicy.all=1" diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/common/AbstractDeliveryAction.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/common/AbstractDeliveryAction.java index 0764975..afb027e 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/common/AbstractDeliveryAction.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/common/AbstractDeliveryAction.java @@ -1,6 +1,7 @@ package at.ac.tuwien.sbc.valesriegler.common; import at.ac.tuwien.sbc.valesriegler.types.DeliveryGroupData; +import at.ac.tuwien.sbc.valesriegler.types.GroupData; /** * Abstract delivery action that can be performed in the DS. In almost all cases the @@ -16,9 +17,15 @@ public abstract class AbstractDeliveryAction extends AbstractAction { super(null); this.groupData = groupData; } - - public DeliveryGroupData getGroupData() { - return groupData; + /** + * do not use. + * + * @return + */ + @Deprecated + @Override + public GroupData getGroupdata() { + throw new IllegalArgumentException("use getDeliveryGroupData() instead!"); } public DeliveryGroupData getDeliveryGroupData() { diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/cook/jms/messageListeners/DeliveryOrdersToCook.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/cook/jms/messageListeners/DeliveryOrdersToCook.java index 973b778..e2a63cf 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/cook/jms/messageListeners/DeliveryOrdersToCook.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/cook/jms/messageListeners/DeliveryOrdersToCook.java @@ -68,9 +68,9 @@ public class DeliveryOrdersToCook implements MessageListener { Thread.sleep(po.getPizzaType().duration * 1000); po.setStatus(PizzaOrderStatus.DONE); Pizza p = Pizza.createPizzaFromPizzaOrder(po, cook.getId(), false); - dor.getGroupdata().getOrder().getCookedPizzas().add(p); + dor.getDeliveryGroupData().getOrder().getCookedPizzas().add(p); } - dor.getGroupdata().getOrder().setStatus(OrderStatus.DELIVERY_PENDING); + dor.getDeliveryGroupData().getOrder().setStatus(OrderStatus.DELIVERY_PENDING); // let pizzas be delivered. session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/driver/actions/OrderDeliveredInfo.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/driver/actions/OrderDeliveredInfo.java index 539ec5e..2b03449 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/driver/actions/OrderDeliveredInfo.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/driver/actions/OrderDeliveredInfo.java @@ -2,8 +2,8 @@ package at.ac.tuwien.sbc.valesriegler.driver.actions; import java.io.Serializable; -import at.ac.tuwien.sbc.valesriegler.common.AbstractAction; -import at.ac.tuwien.sbc.valesriegler.types.GroupData; +import at.ac.tuwien.sbc.valesriegler.common.AbstractDeliveryAction; +import at.ac.tuwien.sbc.valesriegler.types.DeliveryGroupData; /** * response to the group's interest in pizza. @@ -11,14 +11,20 @@ import at.ac.tuwien.sbc.valesriegler.types.GroupData; * @author jan * */ -public class OrderDeliveredInfo extends AbstractAction implements Serializable { - private final int cookId; +public class OrderDeliveredInfo extends AbstractDeliveryAction implements Serializable { + private final int driverId; - public OrderDeliveredInfo(GroupData groupdata, int cookId) { + public OrderDeliveredInfo(DeliveryGroupData groupdata, int driverId) { super(groupdata); - this.cookId = cookId; + this.driverId = driverId; } - // TODO + public int getDriverId() { + return driverId; + } + @Override + public String toString() { + return "OrderDeliveredInfo [driverId=" + driverId + ", getDeliveryGroupData()=" + getDeliveryGroupData() + "]"; + } } diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/driver/jms/JMSDriver.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/driver/jms/JMSDriver.java index 06318be..8742b41 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/driver/jms/JMSDriver.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/driver/jms/JMSDriver.java @@ -40,7 +40,7 @@ public class JMSDriver implements HasId { Session sessCookedDeliveryOrders = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE); MessageConsumer consCookedDeliveryOrders = sessCookedDeliveryOrders.createConsumer(sessCookedDeliveryOrders - .createQueue("OrdersToCook")); + .createQueue("CookedDeliveryOrders")); consCookedDeliveryOrders.setMessageListener(new CookedDeliveryOrders(this)); } catch (JMSException e) { log.error("EXCEPTION!", e); diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/driver/jms/messageListeners/CookedDeliveryOrders.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/driver/jms/messageListeners/CookedDeliveryOrders.java index 4d2d889..5013d4a 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/driver/jms/messageListeners/CookedDeliveryOrders.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/driver/jms/messageListeners/CookedDeliveryOrders.java @@ -15,8 +15,8 @@ import org.slf4j.LoggerFactory; import at.ac.tuwien.sbc.valesriegler.common.Util; import at.ac.tuwien.sbc.valesriegler.cook.actions.DeliveryOrderInfo; +import at.ac.tuwien.sbc.valesriegler.driver.actions.OrderDeliveredInfo; import at.ac.tuwien.sbc.valesriegler.driver.jms.JMSDriver; -import at.ac.tuwien.sbc.valesriegler.group.actions.DeliveryOrderResponse; /** * @@ -40,24 +40,25 @@ public class CookedDeliveryOrders implements MessageListener { ObjectMessage objMsg = (ObjectMessage) msg; Object obj = objMsg.getObject(); - if (obj instanceof DeliveryOrderResponse) { - DeliveryOrderResponse dor = (DeliveryOrderResponse) obj; - log.debug("Received: " + dor); + if (obj instanceof DeliveryOrderInfo) { + DeliveryOrderInfo doi = (DeliveryOrderInfo) obj; + log.debug("Received: " + doi); // generate random delay Thread.sleep((long) (Math.random() * 10000)); - String addr = dor.getDeliveryGroupData().getAddress(); + String addr = doi.getDeliveryGroupData().getAddress(); // Deliver to destination broker ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(Util.JMS_DELIVERY_DESTINATION); Connection connection = connectionFactory.createConnection(); connection.start(); + log.debug("CookedDelivery:ActiveMQConnectionFactory::" + connection); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageProducer prod = session.createProducer(session.createQueue(addr)); prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT); - DeliveryOrderInfo doi = new DeliveryOrderInfo(dor.getDeliveryGroupData(), driver.getId()); - prod.send(session.createObjectMessage(doi)); + OrderDeliveredInfo odi = new OrderDeliveredInfo(doi.getDeliveryGroupData(), driver.getId()); + prod.send(session.createObjectMessage(odi)); session.close(); connection.close(); @@ -69,7 +70,7 @@ public class CookedDeliveryOrders implements MessageListener { session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); prod = session.createProducer(session.createQueue("PizzeriaConnector")); prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT); - prod.send(session.createObjectMessage(doi)); + prod.send(session.createObjectMessage(odi)); session.close(); connection.close(); 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 ae4b9ca..fe89716 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 @@ -51,7 +51,7 @@ public class GroupAgent { public static GroupAgent groupAgent; public static void main(String[] args) { - if (args.length != 1) { + if (args.length < 1) { throw new IllegalArgumentException(USAGE); } -- 2.43.0