From 390af9d658b6c1d7d280f48c06fbdca090138855 Mon Sep 17 00:00:00 2001 From: Jan Vales Date: Mon, 10 Jun 2013 20:07:48 +0200 Subject: [PATCH] [JMS] GroupGui now receives DeliveryOrder info --- .../DeliveryOrdersToCook.java | 7 + .../CookedDeliveryOrders.java | 6 + .../group/actions/DeliveryOrderResponse.java | 2 +- .../group/gui/DeliveryOverviewModel.java | 191 ++++++++-------- .../group/jms/JMSGroupConnector.java | 32 ++- .../valesriegler/types/DeliveryGroupData.java | 211 +++++++++--------- 6 files changed, 248 insertions(+), 201 deletions(-) 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 2f68607..fa46d9b 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 @@ -88,6 +88,13 @@ public class DeliveryOrdersToCook implements MessageListener { // WTF: oi = new OrderInfo(orderrequest.getGroupdata(), cook.getId()); prod.send(session.createObjectMessage(doi)); session.close(); + + // inform GroupGUI + prod = session.createProducer(session.createQueue("GroupConnector")); + prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT); + // WTF: oi = new OrderInfo(orderrequest.getGroupdata(), cook.getId()); + prod.send(session.createObjectMessage(doi)); + session.close(); connection.close(); } else { log.warn("Received unknown Object: " + obj); 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 16e76fc..dfde528 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 @@ -86,6 +86,12 @@ public class CookedDeliveryOrders implements MessageListener { prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT); prod.send(session.createObjectMessage(odi)); session.close(); + + session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); + prod = session.createProducer(session.createQueue("GroupConnector")); + prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT); + prod.send(session.createObjectMessage(odi)); + session.close(); connection.close(); } else { 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 index ea0e830..7b8493f 100644 --- 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 @@ -21,7 +21,7 @@ public class DeliveryOrderResponse extends AbstractDeliveryAction implements Ser @Override public String toString() { - return "DeliveryOrderResponse [getDeliveryGroupData()=" + getDeliveryGroupData() + "]"; + return "DeliveryOrderResponse [waiterId=" + waiterId + ", getDeliveryGroupData()=" + getDeliveryGroupData() + "]"; } public int getWaiterId() { diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/group/gui/DeliveryOverviewModel.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/group/gui/DeliveryOverviewModel.java index eaf9545..562ab71 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/group/gui/DeliveryOverviewModel.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/group/gui/DeliveryOverviewModel.java @@ -1,114 +1,113 @@ package at.ac.tuwien.sbc.valesriegler.group.gui; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import at.ac.tuwien.sbc.valesriegler.common.TableModel; import at.ac.tuwien.sbc.valesriegler.common.Util; import at.ac.tuwien.sbc.valesriegler.group.DeliveryGroup; import at.ac.tuwien.sbc.valesriegler.types.DeliveryGroupData; import at.ac.tuwien.sbc.valesriegler.types.DeliveryStatus; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; public class DeliveryOverviewModel extends TableModel { - private static final Logger log = LoggerFactory.getLogger(GroupOverviewModel.class); - - private static final String STATE = "State"; - private static final String PIZZAS = "Pizzas"; - private static final String ADDRESS = "Address"; - private static final String ID = "ID"; - private static final String PIZZERIA = "Pizzeria"; - private static final String[] COLUMNS = new String[]{ID, ADDRESS, PIZZAS, STATE, PIZZERIA}; + private static final Logger log = LoggerFactory.getLogger(GroupOverviewModel.class); + private static final String STATE = "State"; + private static final String PIZZAS = "Pizzas"; + private static final String ADDRESS = "Address"; + private static final String ID = "ID"; + private static final String PIZZERIA = "Pizzeria"; + private static final String[] COLUMNS = new String[]{ID, ADDRESS, PIZZAS, STATE, PIZZERIA}; - @Override - protected String[] getColumns() { - return COLUMNS; - } + @Override + protected String[] getColumns() { + return COLUMNS; + } - @Override - public void addItems(List newItems) { - log.info("addItems()"); - super.addItems(newItems); - for (DeliveryGroup g : newItems) { - if (Util.useJMS) - g.orderSomeFood(); - } - } + @Override + public void addItems(List newItems) { + log.info("addItems()"); + super.addItems(newItems); + for (DeliveryGroup g : newItems) { + if (Util.useJMS) + g.orderSomeFood(); + } + } - @Override - public Object getValueAt(int rowIndex, int columnIndex) { - List values = new ArrayList<>(items.values()); - DeliveryGroup group = values.get(rowIndex); - String wantedColumn = COLUMNS[columnIndex]; - switch (wantedColumn) { - case ID: - int groupId = group.getId(); - return groupId; - case ADDRESS: - return group.getDeliveryGroupData().getAddress(); - case PIZZAS: - if (group.getDeliveryGroupData().getOrder() == null) - return "none"; - return Util.pizzaDisplay(group.getDeliveryGroupData().getOrder().getOrderedPizzas()); - case STATE: - return group.getDeliveryGroupData().getDeliveryStatus(); - case PIZZERIA: - return group.getDeliveryGroupData().getPizzeriaId(); - default: - throw new RuntimeException(UNHANDLEDCOLUMN); - } - } + @Override + public Object getValueAt(int rowIndex, int columnIndex) { + List values = new ArrayList<>(items.values()); + DeliveryGroup group = values.get(rowIndex); + String wantedColumn = COLUMNS[columnIndex]; + switch (wantedColumn) { + case ID : + int groupId = group.getId(); + return groupId; + case ADDRESS : + return group.getDeliveryGroupData().getAddress(); + case PIZZAS : + if (group.getDeliveryGroupData().getOrder() == null) + return "none"; + return Util.pizzaDisplay(group.getDeliveryGroupData().getOrder().getOrderedPizzas()); + case STATE : + return group.getDeliveryGroupData().getDeliveryStatus(); + case PIZZERIA : + return group.getDeliveryGroupData().getPizzeriaId(); + default : + throw new RuntimeException(UNHANDLEDCOLUMN); + } + } - public void addDeliveries(List groups) { - synchronized (items) { - for (DeliveryGroupData group : groups) { - final DeliveryGroup deliveryGroup = items.get(group.getId()); - if(deliveryGroup==null) { - log.error("Delivery group not found: {}", group.getId()); - } - else deliveryGroup.setDeliveryGroupData(group); - } - } - fireTableDataChanged(); - } + public void addDeliveries(List groups) { + synchronized (items) { + for (DeliveryGroupData group : groups) { + final DeliveryGroup deliveryGroup = items.get(group.getId()); + if (deliveryGroup == null) { + log.error("Delivery group not found: {}", group.getId()); + } else + deliveryGroup.setDeliveryGroupData(group); + } + } + fireTableDataChanged(); + } - public void createStatistics() { - int size; - int finished; - synchronized (items) { - final Collection values = items.values(); - size = values.size(); - finished = 0; - for (DeliveryGroup group : values) { - final DeliveryStatus status = group.getDeliveryGroupData().getDeliveryStatus(); - if (status == DeliveryStatus.DELIVERED || status == DeliveryStatus.DELIVERY_FAILED) { - finished++; - } - } - } - log.info("{} deliveries were ordered", size); - log.info("{} were finished", finished); - } + public void createStatistics() { + int size; + int finished; + synchronized (items) { + final Collection values = items.values(); + size = values.size(); + finished = 0; + for (DeliveryGroup group : values) { + final DeliveryStatus status = group.getDeliveryGroupData().getDeliveryStatus(); + if (status == DeliveryStatus.DELIVERED || status == DeliveryStatus.DELIVERY_FAILED) { + finished++; + } + } + } + log.warn("{} deliveries were ordered", size); + log.warn("{} were finished", finished); + } - public boolean hasFinished() { - int size; - int finished; - synchronized (items) { - final Collection values = items.values(); - size = values.size(); - finished = 0; - for (DeliveryGroup group : values) { - final DeliveryStatus status = group.getDeliveryGroupData().getDeliveryStatus(); - if (status == DeliveryStatus.DELIVERED || status == DeliveryStatus.DELIVERY_FAILED) { - finished++; - } - } - } - final boolean result = size == finished; - return result; - } + public boolean hasFinished() { + int size; + int finished; + synchronized (items) { + final Collection values = items.values(); + size = values.size(); + finished = 0; + for (DeliveryGroup group : values) { + final DeliveryStatus status = group.getDeliveryGroupData().getDeliveryStatus(); + if (status == DeliveryStatus.DELIVERED || status == DeliveryStatus.DELIVERY_FAILED) { + finished++; + } + } + } + final boolean result = size == finished; + return result; + } } 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 b15d33f..ddafe41 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 @@ -1,5 +1,6 @@ package at.ac.tuwien.sbc.valesriegler.group.jms; +import java.util.ArrayList; import java.util.HashMap; import javax.jms.Connection; @@ -17,10 +18,13 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import at.ac.tuwien.sbc.valesriegler.common.AbstractAction; +import at.ac.tuwien.sbc.valesriegler.cook.actions.DeliveryOrderInfo; +import at.ac.tuwien.sbc.valesriegler.driver.actions.OrderDeliveredInfo; import at.ac.tuwien.sbc.valesriegler.group.AbstractGroupConnector; import at.ac.tuwien.sbc.valesriegler.group.Group; import at.ac.tuwien.sbc.valesriegler.group.GroupAgent; import at.ac.tuwien.sbc.valesriegler.group.actions.DeliveryOrderRequest; +import at.ac.tuwien.sbc.valesriegler.group.actions.DeliveryOrderResponse; import at.ac.tuwien.sbc.valesriegler.group.actions.OrderRequest; import at.ac.tuwien.sbc.valesriegler.group.actions.OrderResponse; import at.ac.tuwien.sbc.valesriegler.group.actions.PayRequest; @@ -28,6 +32,7 @@ import at.ac.tuwien.sbc.valesriegler.group.actions.PayResponse; import at.ac.tuwien.sbc.valesriegler.group.actions.TableFree; import at.ac.tuwien.sbc.valesriegler.group.actions.TableRequest; import at.ac.tuwien.sbc.valesriegler.group.actions.TableResponse; +import at.ac.tuwien.sbc.valesriegler.types.DeliveryGroupData; import at.ac.tuwien.sbc.valesriegler.waiter.actions.DeliverOrder; /** @@ -95,10 +100,35 @@ public class JMSGroupConnector extends AbstractGroupConnector implements Message Group g = GroupAgent.getInstance().getGroupModel().getGroupByID(payresponse.getGroupdata().getId()); g.payForPizzas(payresponse.getWaiterId()); return; + + } else if (obj instanceof DeliveryOrderResponse) { + DeliveryOrderResponse deliveryOrderResponse = (DeliveryOrderResponse) obj; + log.warn("Received: " + deliveryOrderResponse); + deliveryOrderResponse.getDeliveryGroupData().setWaiterIdOfOrder(deliveryOrderResponse.getWaiterId()); + ArrayList gd = new ArrayList(); + gd.add(deliveryOrderResponse.getDeliveryGroupData()); + GroupAgent.getInstance().getDeliveryModel().addDeliveries(gd); + return; + + } else if (obj instanceof DeliveryOrderInfo) { + DeliveryOrderInfo deliveryOrderInfo = (DeliveryOrderInfo) obj; + log.warn("Received: " + deliveryOrderInfo); + ArrayList gd = new ArrayList(); + gd.add(deliveryOrderInfo.getDeliveryGroupData()); + GroupAgent.getInstance().getDeliveryModel().addDeliveries(gd); + return; + + } else if (obj instanceof OrderDeliveredInfo) { + OrderDeliveredInfo orderDeliveredInfo = (OrderDeliveredInfo) obj; + log.warn("Received: " + orderDeliveredInfo); + orderDeliveredInfo.getDeliveryGroupData().setDriverId(orderDeliveredInfo.getDriverId()); + ArrayList gd = new ArrayList(); + gd.add(orderDeliveredInfo.getDeliveryGroupData()); + GroupAgent.getInstance().getDeliveryModel().addDeliveries(gd); + return; } } - log.warn("Unknown messagetype received!"); } catch (JMSException e) { log.error("EXCEPTION!", e); diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/types/DeliveryGroupData.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/types/DeliveryGroupData.java index 9187c62..fbf81df 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/types/DeliveryGroupData.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/types/DeliveryGroupData.java @@ -1,113 +1,118 @@ package at.ac.tuwien.sbc.valesriegler.types; -import at.ac.tuwien.sbc.valesriegler.common.HasId; -import at.ac.tuwien.sbc.valesriegler.common.Util; +import java.io.Serializable; + import org.mozartspaces.capi3.Queryable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.Serializable; +import at.ac.tuwien.sbc.valesriegler.common.Util; @Queryable(autoindex = true) public class DeliveryGroupData implements Serializable, HasOrder { - private static final Logger log = LoggerFactory.getLogger(GroupData.class); - - private Integer id; - private Order order; - private String address; - private DeliveryStatus deliveryStatus = DeliveryStatus.START; - private String pizzeriaId; - - private Integer waiterIdOfOrder; - private Integer driverId; - - /** - * These fields are set only when the delivery order was shifted by a load balancer from one pizzeria to another - */ - private Integer loadBalancerId; - private String originalPizzeriaId; - - public DeliveryGroupData(int id) { - this.id = id; - } - - public DeliveryGroupData() { - //To change body of created methods use File | Settings | File Templates. - } - - public void setId(Integer id) { - this.id = id; - } - - public Order getOrder() { - return order; - } - - public void setOrder(Order order) { - this.order = order; - } - - public String getAddress() { - return address; - } - - public String getOriginalPizzeriaId() { - return originalPizzeriaId; - } - - public int getDriverId() { - return Util.getIntSafe(driverId); - } - - public void setDriverId(Integer driverId) { - this.driverId = driverId; - } - - public Integer getWaiterIdOfOrder() { - return waiterIdOfOrder; - } - - public void setWaiterIdOfOrder(Integer waiterIdOfOrder) { - this.waiterIdOfOrder = waiterIdOfOrder; - } - - - public void setOriginalPizzeriaId(String originalPizzeriaId) { - this.originalPizzeriaId = originalPizzeriaId; - } - - - public void setAddress(String address) { - this.address = address; - } - - public DeliveryStatus getDeliveryStatus() { - return deliveryStatus; - } - - public void setDeliveryStatus(DeliveryStatus deliveryStatus) { - this.deliveryStatus = deliveryStatus; - } - - public int getLoadBalancerId() { - return Util.getIntSafe(loadBalancerId); - } - - public void setLoadBalancerId(Integer loadBalancerId) { - this.loadBalancerId = loadBalancerId; - } - - - public String getPizzeriaId() { - return pizzeriaId; - } - - public void setPizzeriaId(String pizzeriaId) { - this.pizzeriaId = pizzeriaId; - } - - @Override - public int getId() { - return Util.getIntSafe(id); - } + private static final Logger log = LoggerFactory.getLogger(GroupData.class); + + private Integer id; + private Order order; + private String address; + private DeliveryStatus deliveryStatus = DeliveryStatus.START; + private String pizzeriaId; + + private Integer waiterIdOfOrder; + private Integer driverId; + + /** + * These fields are set only when the delivery order was shifted by a load balancer from one pizzeria to another + */ + private Integer loadBalancerId; + private String originalPizzeriaId; + + public DeliveryGroupData(int id) { + this.id = id; + } + + public DeliveryGroupData() { + // To change body of created methods use File | Settings | File Templates. + } + + public void setId(Integer id) { + this.id = id; + } + + @Override + public Order getOrder() { + return order; + } + + public void setOrder(Order order) { + this.order = order; + } + + public String getAddress() { + return address; + } + + public String getOriginalPizzeriaId() { + return originalPizzeriaId; + } + + public int getDriverId() { + return Util.getIntSafe(driverId); + } + + public void setDriverId(Integer driverId) { + this.driverId = driverId; + } + + public Integer getWaiterIdOfOrder() { + return waiterIdOfOrder; + } + + public void setWaiterIdOfOrder(Integer waiterIdOfOrder) { + this.waiterIdOfOrder = waiterIdOfOrder; + } + + public void setOriginalPizzeriaId(String originalPizzeriaId) { + this.originalPizzeriaId = originalPizzeriaId; + } + + public void setAddress(String address) { + this.address = address; + } + + public DeliveryStatus getDeliveryStatus() { + return deliveryStatus; + } + + public void setDeliveryStatus(DeliveryStatus deliveryStatus) { + this.deliveryStatus = deliveryStatus; + } + + public int getLoadBalancerId() { + return Util.getIntSafe(loadBalancerId); + } + + public void setLoadBalancerId(Integer loadBalancerId) { + this.loadBalancerId = loadBalancerId; + } + + public String getPizzeriaId() { + return pizzeriaId; + } + + public void setPizzeriaId(String pizzeriaId) { + this.pizzeriaId = pizzeriaId; + } + + @Override + public int getId() { + return Util.getIntSafe(id); + } + + @Override + public String toString() { + return "DeliveryGroupData [id=" + id + ", order=" + order + ", address=" + address + ", deliveryStatus=" + + deliveryStatus + ", pizzeriaId=" + pizzeriaId + ", waiterIdOfOrder=" + waiterIdOfOrder + ", driverId=" + + driverId + ", loadBalancerId=" + loadBalancerId + ", originalPizzeriaId=" + originalPizzeriaId + "]"; + } } -- 2.43.0