1 package at.ac.tuwien.sbc.valesriegler.group;
3 import at.ac.tuwien.sbc.valesriegler.common.HasId;
4 import at.ac.tuwien.sbc.valesriegler.group.actions.DeliveryOrderRequest;
5 import at.ac.tuwien.sbc.valesriegler.group.jms.JMSGroupConnector;
6 import at.ac.tuwien.sbc.valesriegler.types.DeliveryGroupData;
7 import at.ac.tuwien.sbc.valesriegler.types.DeliveryStatus;
8 import org.slf4j.Logger;
9 import org.slf4j.LoggerFactory;
11 public class DeliveryGroup implements Runnable, HasId {
12 private static final Logger log = LoggerFactory.getLogger(DeliveryGroup.class);
13 private static int idNext = 0;
15 private DeliveryGroupData deliveryGroupData;
17 public DeliveryGroup() {
18 deliveryGroupData = new DeliveryGroupData(++idNext);
21 public DeliveryGroup(int id) {
22 deliveryGroupData = new DeliveryGroupData(id);
25 public DeliveryGroupData getDeliveryGroupData() {
26 return deliveryGroupData;
31 return deliveryGroupData.getId();
34 public void setDeliveryGroupData(DeliveryGroupData deliveryGroupData) {
35 this.deliveryGroupData = deliveryGroupData;
40 log.debug("Thread started for:" + this);
42 Thread.sleep((long) (Math.random() * 10000));
43 switch (deliveryGroupData.getDeliveryStatus()) {
44 case START : // should not happen.
47 JMSGroupConnector conn = JMSGroupConnector.getConnector(deliveryGroupData.getPizzeriaId());
48 conn.send(new DeliveryOrderRequest(deliveryGroupData));
50 case IN_PROGRESS : // do nothing
52 case DELIVERED : // do nothing
54 case PAID : // do nothing
56 case IS_DELIVERED : // do nothing
58 case DELIVERY_FAILED : // do nothing
60 default : // do nothing
64 } catch (InterruptedException e) {
69 // lets order at the pizzaria.
70 public void orderSomeFood() {
71 log.debug("orderSomeFood(): " + this);
72 deliveryGroupData.setDeliveryStatus(DeliveryStatus.ORDER_PENDING);
73 GroupAgent.getInstance().getGroupModel().fireTableDataChanged();
74 new Thread(this).start();