Merge branch 'master' of https://bitbucket.org/rgregor/sbc-ss-2013
authorGregor Riegler <gregor.riegler@gmail.com>
Mon, 10 Jun 2013 15:23:56 +0000 (17:23 +0200)
committerGregor Riegler <gregor.riegler@gmail.com>
Mon, 10 Jun 2013 15:23:56 +0000 (17:23 +0200)
Conflicts:
src/main/java/at/ac/tuwien/sbc/valesriegler/group/gui/DeliveryOverviewModel.java

src/main/java/at/ac/tuwien/sbc/valesriegler/group/GroupAgent.java
src/main/java/at/ac/tuwien/sbc/valesriegler/group/gui/DeliveryOverviewModel.java
src/main/java/at/ac/tuwien/sbc/valesriegler/group/gui/GroupOverviewModel.java
src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/PizzeriaAgent.java
src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/tablemodels/DeliveryOrdersModel.java
src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/tablemodels/GroupsOverviewModel.java
src/main/java/at/ac/tuwien/sbc/valesriegler/types/Order.java
src/main/java/at/ac/tuwien/sbc/valesriegler/xvsm/DriverXVSM.java
src/main/java/at/ac/tuwien/sbc/valesriegler/xvsm/GroupAgentXVSM.java

index fe89716420651a9ad3e41c5f767175a7ecf63eb9..2f8b153df719e927033267e87913e7e13c7029df 100644 (file)
@@ -1,16 +1,5 @@
 package at.ac.tuwien.sbc.valesriegler.group;
 
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-import javax.swing.SwingUtilities;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
 import at.ac.tuwien.sbc.valesriegler.common.Util;
 import at.ac.tuwien.sbc.valesriegler.group.gui.DeliveryOverviewModel;
 import at.ac.tuwien.sbc.valesriegler.group.gui.GroupCreationDetailsRequest;
@@ -22,6 +11,11 @@ import at.ac.tuwien.sbc.valesriegler.types.GroupData;
 import at.ac.tuwien.sbc.valesriegler.types.Order;
 import at.ac.tuwien.sbc.valesriegler.types.PizzaType;
 import at.ac.tuwien.sbc.valesriegler.xvsm.GroupAgentXVSM;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.swing.*;
+import java.util.*;
 
 /**
  * The Main class of the Group component.
@@ -67,7 +61,7 @@ public class GroupAgent {
                }
 
                groupAgent = new GroupAgent();
-               if (!Util.runSimulation) {
+               if (! Util.runSimulation) {
                        groupGui = new GroupGUI();
                        SwingUtilities.invokeLater(groupGui);
                }
index e91b45fb7a1e725a733c7d0c27d3d6a7fb1f934e..8bce9d41682244c6525aa9bd5c705487d543614d 100644 (file)
 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;
 
-public class DeliveryOverviewModel extends TableModel<DeliveryGroup> {
-       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
-       public void addItems(List<DeliveryGroup> 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<DeliveryGroup> 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 setOrdersTaken(List<DeliveryGroupData> groups) {
-               for (DeliveryGroupData group : groups) {
-                       changeStateOfGroup(group.getId(), DeliveryStatus.ORDERED);
-               }
-
-               fireTableDataChanged();
-       }
-
-       private void changeStateOfGroup(int groupId, DeliveryStatus state) {
-               items.get(groupId).getDeliveryGroupData().setDeliveryStatus(state);
-       }
-
-       public void setOrdersDelivered(List<DeliveryGroupData> groups) {
-               for (DeliveryGroupData group : groups) {
-                       changeStateOfGroup(group.getId(), group.getDeliveryStatus());
-               }
-
-               fireTableDataChanged();
-       }
-
-       public void addDeliveries(List<DeliveryGroupData> groups) {
-               synchronized (items) {
-                       for (DeliveryGroupData group : groups) {
-                               final DeliveryGroup deliveryGroup = items.get(group.getId());
-                               if (deliveryGroup == null) {
-                                       log.error("Delivery group not found!!!");
-                               }
-                               deliveryGroup.setDeliveryGroupData(group);
-                       }
-               }
-               fireTableDataChanged();
-       }
-
-       public void createStatistics() {
-               int size;
-               int finished;
-               synchronized (items) {
-                       final Collection<DeliveryGroup> 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);
-       }
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
 
-       public boolean hasFinished() {
-               int size;
-               int finished;
-               synchronized (items) {
-                       final Collection<DeliveryGroup> 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++;
-                               }
-                       }
-               }
-               return size == finished;
-       }
+public class DeliveryOverviewModel extends TableModel<DeliveryGroup> {
+    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
+    public Object getValueAt(int rowIndex, int columnIndex) {
+        List<DeliveryGroup> 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<DeliveryGroupData> 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<DeliveryGroup> 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 boolean hasFinished() {
+        int size;
+        int finished;
+        synchronized (items) {
+            final Collection<DeliveryGroup> 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;
+    }
 }
index fcdfcc5c1aec0ec8732a4e5beba5a24c4eb2f263..a321dff92318248c25978732a570a60c5868a505 100644 (file)
@@ -47,7 +47,18 @@ public class GroupOverviewModel extends TableModel<Group> {
        @Override
        public Object getValueAt(int rowIndex, int columnIndex) {
                List<Group> values = new ArrayList<>(items.values());
-               Group group = values.get(rowIndex);
+        // TODO make sure this is necessary...
+//        Collections.sort(values, new Comparator<Group>() {
+//            @Override
+//            public int compare(Group o1, Group o2) {
+//                final int o1Id = o1.getId();
+//                final int o2Id = o2.getId();
+//                if(o1Id<o2Id) return -1;
+//                else if(o1Id>o2Id) return 1;
+//                else return 0;
+//            }
+//        });
+        Group group = values.get(rowIndex);
                String wantedColumn = COLUMNS[columnIndex];
                switch (wantedColumn) {
                case ID:
index 3e8c4d80acc995283b757021e019305dc6ecaf12..87a416c0b49349d9972487613fea46c062306f38 100644 (file)
@@ -1,27 +1,19 @@
 package at.ac.tuwien.sbc.valesriegler.pizzeria;
 
-import java.util.List;
-
-import javax.swing.SwingUtilities;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
 import at.ac.tuwien.sbc.valesriegler.common.Util;
 import at.ac.tuwien.sbc.valesriegler.jms.nac.JMSNAC;
 import at.ac.tuwien.sbc.valesriegler.pizzeria.actions.TableNew;
 import at.ac.tuwien.sbc.valesriegler.pizzeria.gui.PizzeriaFrame;
-import at.ac.tuwien.sbc.valesriegler.pizzeria.gui.tablemodels.DeliveryDetailsModel;
-import at.ac.tuwien.sbc.valesriegler.pizzeria.gui.tablemodels.DeliveryOrdersModel;
-import at.ac.tuwien.sbc.valesriegler.pizzeria.gui.tablemodels.GroupsOverviewModel;
-import at.ac.tuwien.sbc.valesriegler.pizzeria.gui.tablemodels.OrdersOverviewModel;
-import at.ac.tuwien.sbc.valesriegler.pizzeria.gui.tablemodels.PizzasOfOrderModel;
-import at.ac.tuwien.sbc.valesriegler.pizzeria.gui.tablemodels.TablesOverviewModel;
-import at.ac.tuwien.sbc.valesriegler.pizzeria.gui.tablemodels.WaitersOfOrderModel;
+import at.ac.tuwien.sbc.valesriegler.pizzeria.gui.tablemodels.*;
 import at.ac.tuwien.sbc.valesriegler.pizzeria.jms.JMSPizzeriaConnector;
 import at.ac.tuwien.sbc.valesriegler.pizzeria.jms.PizzeriaJMSNACMsgListener;
 import at.ac.tuwien.sbc.valesriegler.types.Table;
 import at.ac.tuwien.sbc.valesriegler.xvsm.PizzeriaAgentXVSM;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.swing.*;
+import java.util.List;
 
 /**
  * The Main class of the Pizzeria compoment.
@@ -61,7 +53,7 @@ public class PizzeriaAgent {
                        case "XVSM" :
                                pizzeriaAgent.createModels();
                                pizzeriaAgent.initXVSM(args[1]);
-                               if (!Util.runSimulation) {
+                               if (! Util.runSimulation) {
                                        pizzeriaAgent.initGUI();
                                }
                                Util.useJMS = false;
index c6bed848eec46c7c8db55cfb11fa83e624c5e94f..336bfd33167d1a16444126087018cdd5e49866d6 100644 (file)
@@ -6,6 +6,8 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
 import java.util.List;
 
 public class DeliveryOrdersModel extends AbstractOrdersModel<DeliveryGroupData> {
@@ -28,6 +30,23 @@ public class DeliveryOrdersModel extends AbstractOrdersModel<DeliveryGroupData>
     @Override
     public Object getValueAt(int rowIndex, int columnIndex) {
         List<DeliveryGroupData> values = new ArrayList<>(items.values());
+        // TODO: make sure that is necessary
+        Collections.sort(values, new Comparator<DeliveryGroupData>() {
+            @Override
+            public int compare(DeliveryGroupData o1, DeliveryGroupData o2) {
+                final int o1Id = o1.getOrder().getId();
+                final int o2Id = o2.getOrder().getId();
+                if(o1Id==0) {
+                   if(o2Id>0) return 1;
+                }
+                if(o2Id==0) {
+                    if(o1Id>0) return 1;
+                }
+                if (o1Id < o2Id) return -1;
+                else if (o1Id > o2Id) return 1;
+                else return 0;
+            }
+        });
         DeliveryGroupData group = values.get(rowIndex);
         Order order = group.getOrder();
         String wantedColumn = COLUMNS[columnIndex];
index 26b2ef4a57cb8d2610a1bb2475be9c7a79331785..142e14fd60c3b7a5e0fe42745128a34748068492 100644 (file)
@@ -7,6 +7,8 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
 import java.util.List;
 
 public class GroupsOverviewModel extends TableModel<GroupData> {
@@ -26,6 +28,23 @@ public class GroupsOverviewModel extends TableModel<GroupData> {
        public Object getValueAt(int rowIndex, int columnIndex) {
                List<GroupData> values = new ArrayList<>(items.values());
 
+        // TODO: make sure that is necessary
+        Collections.sort(values, new Comparator<GroupData>() {
+            @Override
+            public int compare(GroupData o1, GroupData o2) {
+                final int o1Id = o1.getOrder().getId();
+                final int o2Id = o2.getOrder().getId();
+                if (o1Id == 0) {
+                    if (o2Id > 0) return 1;
+                }
+                if (o2Id == 0) {
+                    if (o1Id > 0) return 1;
+                }
+                if (o1Id < o2Id) return -1;
+                else if (o1Id > o2Id) return 1;
+                else return 0;
+            }
+        });
                GroupData group = values.get(rowIndex);
                String wantedColumn = COLUMNS[columnIndex];
                switch (wantedColumn) {
index 687d84b9d41d86d7daa43e1d629d7d50c4698931..a463957369b2c4dabebb078fa502c37365b25968 100644 (file)
@@ -1,14 +1,13 @@
 package at.ac.tuwien.sbc.valesriegler.types;
 
+import at.ac.tuwien.sbc.valesriegler.common.HasId;
+import at.ac.tuwien.sbc.valesriegler.common.Util;
+import org.mozartspaces.capi3.Queryable;
+
 import java.io.Serializable;
 import java.util.ArrayList;
 import java.util.List;
 
-import org.mozartspaces.capi3.Queryable;
-
-import at.ac.tuwien.sbc.valesriegler.common.HasId;
-import at.ac.tuwien.sbc.valesriegler.common.Util;
-
 /**
  * Object denotes a Group's interest in pizzas and the state of the pizzas
  * themselves.
@@ -79,7 +78,7 @@ public class Order implements Serializable, HasId {
 
        @Override
        public int getId() {
-               return id;
+               return Util.getIntSafe(id);
        }
 
        public List<PizzaOrder> getOrderedPizzas() {
index 343b2789e284963f0c0bd53dcc0b8138606cb972..349b0595d52c9057c57c0bd4ffc8e48176550e3e 100644 (file)
@@ -10,6 +10,7 @@ import at.ac.tuwien.sbc.valesriegler.types.Pizza;
 import at.ac.tuwien.sbc.valesriegler.xvsm.spacehelpers.SpaceAction;
 import org.mozartspaces.core.ContainerReference;
 import org.mozartspaces.core.MzsConstants;
+import org.mozartspaces.core.MzsCoreException;
 import org.mozartspaces.core.TransactionReference;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -42,64 +43,68 @@ public class DriverXVSM extends AbstractXVSMConnector {
 
             @Override
             public void onEntriesWritten(List<? extends Serializable> entries) throws Exception {
-                final List<DeliveryGroupData> deliveries = castEntries(entries);
+                handleDeliveries(entries);
 
-                for (DeliveryGroupData delivery : deliveries) {
-                    DeliveryGroupData template = new DeliveryGroupData(delivery.getId());
-                    template.setDeliveryStatus(DeliveryStatus.ORDERED);
+            }
+        }).createSpaceListenerImpl();
+    }
 
-                    final TransactionReference tx = capi.createTransaction(
-                            7000,
-                            URI.create(String.format(Util.SERVER_ADDR, port)));
-                    final String error = "Another driver wants to deliver this order!";
+    private void handleDeliveries(List<? extends Serializable> entries) throws MzsCoreException {
+        final List<DeliveryGroupData> deliveries = castEntries(entries);
 
-                    try {
-                        // Get lock for delivering this delivery order
-                        final DeliveryGroupData deliveryGroup = takeMatchingEntity(template, deliverDeliveryOrderContainer, tx, MzsConstants.RequestTimeout.DEFAULT, error);
-                        final DeliveryGroupData group = takeMatchingEntity(template, pizzeriaDeliveryContainer, tx, MzsConstants.RequestTimeout.INFINITE, "Cannot get the delivery order!");
-                        group.setDriverId(driverId);
-                        group.setDeliveryStatus(DeliveryStatus.IN_PROGRESS);
+        for (DeliveryGroupData delivery : deliveries) {
+            DeliveryGroupData template = new DeliveryGroupData(delivery.getId());
+            template.setDeliveryStatus(DeliveryStatus.ORDERED);
 
-                        final List<DeliveryGroupData> groups = Arrays.asList(group);
-//                        sendItemsToContainer(groups,
-//                                pizzeriaDeliveryContainer, MzsConstants.RequestTimeout.ZERO, null);
+            final TransactionReference tx = capi.createTransaction(
+                    7000,
+                    URI.create(String.format(Util.SERVER_ADDR, port)));
+            final String error = "Another driver wants to deliver this order!";
 
-                        if (!Util.runSimulation) {
-                            Thread.sleep(3000);
-                        }
+            try {
+                // Get lock for delivering this delivery order
+                final DeliveryGroupData deliveryGroup = takeMatchingEntity(template, deliverDeliveryOrderContainer, tx, MzsConstants.RequestTimeout.DEFAULT, error);
+                final DeliveryGroupData group = takeMatchingEntity(template, pizzeriaDeliveryContainer, tx, MzsConstants.RequestTimeout.INFINITE, "Cannot get the delivery order!");
+                group.setDriverId(driverId);
+                group.setDeliveryStatus(DeliveryStatus.IN_PROGRESS);
 
-                        final String address = String.format(Util.SERVER_ADDR, Util.DELIVERY_CUSTOMERS_PORT);
-                        ContainerReference cref = null;
-                        boolean success = false;
-                        try {
-                            cref = capi.lookupContainer(group.getAddress(), URI.create(address), MzsConstants.RequestTimeout.ZERO, null);
-                            log.debug("Looked up container {} successfully!", address);
-                            success = true;
+                final List<DeliveryGroupData> groups = Arrays.asList(group);
+//                        sendItemsToContainer(groups,
+//                                pizzeriaDeliveryContainer, MzsConstants.RequestTimeout.ZERO, null);
 
-                        } catch (Exception ex) {
-                            log.info("Could not find container {}", address);
-                        }
-                        if (success) {
-                            group.setDeliveryStatus(DeliveryStatus.DELIVERED);
-                            if (!Util.runSimulation) {
-                                sendItemsToContainer(Arrays.asList(new Bill(1000, group.getId())), cref, MzsConstants.RequestTimeout.DEFAULT, null);
-                            }
-                        } else {
-                            group.setDeliveryStatus(DeliveryStatus.DELIVERY_FAILED);
-                        }
-                        sendItemsToContainer(groups, pizzeriaDeliveryContainer, MzsConstants.RequestTimeout.DEFAULT, tx);
-                        capi.commitTransaction(tx);
+                if (!Util.runSimulation) {
+                    Thread.sleep(3000);
+                }
 
+                final String address = String.format(Util.SERVER_ADDR, Util.DELIVERY_CUSTOMERS_PORT);
+                ContainerReference cref = null;
+                boolean success = false;
+                try {
+                    cref = capi.lookupContainer(group.getAddress(), URI.create(address), MzsConstants.RequestTimeout.ZERO, null);
+                    log.debug("Looked up container {} successfully!", address);
+                    success = true;
 
-                    } catch (Exception e) {
-                        log.info("DRiverXVSM exception");
-                        log.info(e.getMessage());
-                        e.printStackTrace();
+                } catch (Exception ex) {
+                    log.info("Could not find container {}", address);
+                }
+                if (success) {
+                    group.setDeliveryStatus(DeliveryStatus.DELIVERED);
+                    if (!Util.runSimulation) {
+                        sendItemsToContainer(Arrays.asList(new Bill(1000, group.getId())), cref, MzsConstants.RequestTimeout.DEFAULT, null);
                     }
+                } else {
+                    group.setDeliveryStatus(DeliveryStatus.DELIVERY_FAILED);
                 }
+                sendItemsToContainer(groups, pizzeriaDeliveryContainer, MzsConstants.RequestTimeout.DEFAULT, tx);
+                capi.commitTransaction(tx);
 
+
+            } catch (Exception e) {
+                log.info("DRiverXVSM exception");
+                log.info(e.getMessage());
+                e.printStackTrace();
             }
-        }).createSpaceListenerImpl();
+        }
     }
 
     public void listenForPreparedDeliveryPizzas() {
@@ -143,6 +148,7 @@ public class DriverXVSM extends AbstractXVSMConnector {
                                     tx);
 
                             capi.commitTransaction(tx);
+                            handleDeliveries(groupsWithCompleteOrder);
                         } else {
                             log.info("Not yet all pizzas prepared! Order with id "
                                     + orderId + " has " + numberOfPizzas
index c2a829fc851648d7dc0e30b017150f4086e19794..c42b0a26865cbab3be4d35257de38a677685d742 100644 (file)
@@ -83,7 +83,7 @@ public class GroupAgentXVSM extends AbstractXVSMConnector {
                     boolean finished = GroupAgent.getInstance().getDeliveryModel().hasFinished();
                     if (finished) {
                         final long now = new Date().getTime();
-                        final long difference = startTime.get() - now;
+                        final long difference = now - startTime.get();
                         log.info("Finished after {} seconds", difference / 1000);
                     }
                 }
@@ -126,20 +126,20 @@ public class GroupAgentXVSM extends AbstractXVSMConnector {
                 List<PizzaType> pizzaTypes2 = Arrays.asList(PizzaType.CARDINALE, PizzaType.SALAMI, PizzaType.MARGHERITA);
                 List<PizzaType> pizzaTypes3 = Arrays.asList(PizzaType.SALAMI, PizzaType.MARGHERITA);
 
-                final String pizzeria1 = "9875";
-                final String pizzeria2 = "9874";
+                final String pizzeria1 = "9874";
+                final String pizzeria2 = "9875";
                 List<DeliveryGroup> groups1 = GroupAgent.getInstance().createGroups(pizzaTypes1, pizzeria1, 4);
                 List<DeliveryGroup> groups2 = GroupAgent.getInstance().createGroups(pizzaTypes2, pizzeria2, 3);
                 List<DeliveryGroup> groups3 = GroupAgent.getInstance().createGroups(pizzaTypes3, pizzeria2, 2);
 
                 final DeliveryOverviewModel deliveryModel = GroupAgent.getInstance().getDeliveryModel();
-                deliveryModel.addItems(groups1);
+//                deliveryModel.addItems(groups1);
                 deliveryModel.addItems(groups2);
                 deliveryModel.addItems(groups3);
 
                 GroupAgent.getInstance().onDeliveryGroupsCreated(groups2);
                 GroupAgent.getInstance().onDeliveryGroupsCreated(groups3);
-                GroupAgent.getInstance().onDeliveryGroupsCreated(groups1);
+//                GroupAgent.getInstance().onDeliveryGroupsCreated(groups1);
 
                 log.info("ATTENTION: Now let's wait 60 seconds!");