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.group.actions.DeliveryOrderRequest;
8 import at.ac.tuwien.sbc.valesriegler.group.jms.JMSGroupConnector;
9 import at.ac.tuwien.sbc.valesriegler.types.DeliveryGroupData;
10 import at.ac.tuwien.sbc.valesriegler.types.DeliveryStatus;
12 public class DeliveryGroup implements Runnable, HasId {
13 private static final Logger log = LoggerFactory.getLogger(DeliveryGroup.class);
14 private static int idNext = 0;
16 private DeliveryGroupData deliveryGroupData;
18 public DeliveryGroup() {
19 deliveryGroupData = new DeliveryGroupData(++idNext);
22 public DeliveryGroup(int id) {
23 deliveryGroupData = new DeliveryGroupData(id);
26 public DeliveryGroupData getDeliveryGroupData() {
27 return deliveryGroupData;
32 return deliveryGroupData.getId();
35 public void setDeliveryGroupData(DeliveryGroupData deliveryGroupData) {
36 this.deliveryGroupData = deliveryGroupData;
41 log.debug("Thread started for:" + this);
43 Thread.sleep((long) (Math.random() * 10000));
44 switch (deliveryGroupData.getDeliveryStatus()) {
45 case START : // should not happen.
48 getDeliveryGroupData().getOrder().genId();
49 JMSGroupConnector conn = JMSGroupConnector.getConnector(deliveryGroupData.getPizzeriaId());
50 conn.send(new DeliveryOrderRequest(deliveryGroupData));
52 case IN_PROGRESS : // do nothing
54 case DELIVERED : // do nothing
56 case PAID : // do nothing
58 case IS_DELIVERED : // do nothing
60 case DELIVERY_FAILED : // do nothing
62 default : // do nothing
66 } catch (InterruptedException e) {
71 // lets order at the pizzaria.
72 public void orderSomeFood() {
73 log.debug("orderSomeFood(): " + this);
74 deliveryGroupData.setDeliveryStatus(DeliveryStatus.ORDER_PENDING);
75 GroupAgent.getInstance().getGroupModel().fireTableDataChanged();
76 new Thread(this).start();