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 JMSGroupConnector conn = JMSGroupConnector.getConnector(deliveryGroupData.getPizzeriaId());
49 conn.send(new DeliveryOrderRequest(deliveryGroupData));
51 case IN_PROGRESS : // do nothing
53 case DELIVERED : // do nothing
55 case PAID : // do nothing
57 case IS_DELIVERED : // do nothing
59 case DELIVERY_FAILED : // do nothing
61 default : // do nothing
65 } catch (InterruptedException e) {
70 // lets order at the pizzaria.
71 public void orderSomeFood() {
72 log.debug("orderSomeFood(): " + this);
73 deliveryGroupData.setDeliveryStatus(DeliveryStatus.ORDER_PENDING);
74 GroupAgent.getInstance().getGroupModel().fireTableDataChanged();
75 new Thread(this).start();