1 package at.ac.tuwien.sbc.valesriegler.group;
3 import org.slf4j.Logger;
4 import org.slf4j.LoggerFactory;
6 import at.ac.tuwien.sbc.valesriegler.common.HasId;
7 import at.ac.tuwien.sbc.valesriegler.common.Util;
8 import at.ac.tuwien.sbc.valesriegler.group.actions.DeliveryOrderRequest;
9 import at.ac.tuwien.sbc.valesriegler.group.jms.JMSGroupConnector;
10 import at.ac.tuwien.sbc.valesriegler.types.DeliveryGroupData;
11 import at.ac.tuwien.sbc.valesriegler.types.DeliveryStatus;
13 public class DeliveryGroup implements Runnable, HasId {
14 private static final Logger log = LoggerFactory.getLogger(DeliveryGroup.class);
15 private static int idNext = 0;
17 private DeliveryGroupData deliveryGroupData;
19 public DeliveryGroup() {
20 deliveryGroupData = new DeliveryGroupData(++idNext);
23 public DeliveryGroup(int id) {
24 deliveryGroupData = new DeliveryGroupData(id);
27 public DeliveryGroupData getDeliveryGroupData() {
28 return deliveryGroupData;
33 return deliveryGroupData.getId();
36 public void setDeliveryGroupData(DeliveryGroupData deliveryGroupData) {
37 this.deliveryGroupData = deliveryGroupData;
42 log.debug("Thread started for:" + this);
44 if (!Util.runSimulation) {
45 Thread.sleep((long) (Math.random() * 10000));
47 switch (deliveryGroupData.getDeliveryStatus()) {
48 case START : // should not happen.
51 getDeliveryGroupData().getOrder().genId();
52 JMSGroupConnector conn = JMSGroupConnector.getConnector(deliveryGroupData.getPizzeriaId());
53 conn.send(new DeliveryOrderRequest(deliveryGroupData));
55 case IN_PROGRESS : // do nothing
57 case DELIVERED : // do nothing
59 case PAID : // do nothing
61 case IS_DELIVERED : // do nothing
63 case DELIVERY_FAILED : // do nothing
65 default : // do nothing
69 } catch (InterruptedException e) {
74 // lets order at the pizzaria.
75 public void orderSomeFood() {
76 log.debug("orderSomeFood(): " + this);
77 deliveryGroupData.setDeliveryStatus(DeliveryStatus.ORDER_PENDING);
78 GroupAgent.getInstance().getGroupModel().fireTableDataChanged();
79 new Thread(this).start();