From de2971be97487c287d99fabca868d9407e07b62b Mon Sep 17 00:00:00 2001 From: Gregor Riegler Date: Sun, 9 Jun 2013 19:08:53 +0200 Subject: [PATCH] [XVSM] Some simulation result display --- .../group/gui/DeliveryOverviewModel.java | 17 ++++++++++++++ .../sbc/valesriegler/xvsm/GroupAgentXVSM.java | 23 +++++++++++++------ 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/group/gui/DeliveryOverviewModel.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/group/gui/DeliveryOverviewModel.java index f793948..53613e0 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/group/gui/DeliveryOverviewModel.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/group/gui/DeliveryOverviewModel.java @@ -103,4 +103,21 @@ public class DeliveryOverviewModel extends TableModel { log.info("{} deliveries were ordered", size); log.info("{} were finished", finished); } + + public boolean hasFinished() { + int size; + int finished; + synchronized (items) { + final Collection 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; + } } diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/xvsm/GroupAgentXVSM.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/xvsm/GroupAgentXVSM.java index a227e06..c2a829f 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/xvsm/GroupAgentXVSM.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/xvsm/GroupAgentXVSM.java @@ -14,15 +14,15 @@ import org.slf4j.LoggerFactory; import javax.swing.*; import java.io.Serializable; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Set; +import java.util.*; +import java.util.concurrent.atomic.AtomicLong; import static java.lang.String.valueOf; public class GroupAgentXVSM extends AbstractXVSMConnector { private static final Logger log = LoggerFactory.getLogger(GroupAgentXVSM.class); + + private AtomicLong startTime = new AtomicLong(); public GroupAgentXVSM() { super(Util.GROUP_AGENT_PORT); @@ -78,6 +78,15 @@ public class GroupAgentXVSM extends AbstractXVSMConnector { GroupAgent.getInstance().getDeliveryModel().addDeliveries(groups); } }); + + if (Util.runSimulation) { + boolean finished = GroupAgent.getInstance().getDeliveryModel().hasFinished(); + if (finished) { + final long now = new Date().getTime(); + final long difference = startTime.get() - now; + log.info("Finished after {} seconds", difference / 1000); + } + } } }).createSpaceListenerImpl(); } @@ -113,13 +122,12 @@ public class GroupAgentXVSM extends AbstractXVSMConnector { new Thread(new Runnable() { @Override public void run() { - List newDeliveryGroups = new ArrayList<>(); List pizzaTypes1 = Arrays.asList(PizzaType.CARDINALE, PizzaType.SALAMI, PizzaType.MARGHERITA, PizzaType.MARGHERITA); List pizzaTypes2 = Arrays.asList(PizzaType.CARDINALE, PizzaType.SALAMI, PizzaType.MARGHERITA); List pizzaTypes3 = Arrays.asList(PizzaType.SALAMI, PizzaType.MARGHERITA); - final String pizzeria1 = "9874"; - final String pizzeria2 = "9875"; + final String pizzeria1 = "9875"; + final String pizzeria2 = "9874"; List groups1 = GroupAgent.getInstance().createGroups(pizzaTypes1, pizzeria1, 4); List groups2 = GroupAgent.getInstance().createGroups(pizzaTypes2, pizzeria2, 3); List groups3 = GroupAgent.getInstance().createGroups(pizzaTypes3, pizzeria2, 2); @@ -136,6 +144,7 @@ public class GroupAgentXVSM extends AbstractXVSMConnector { log.info("ATTENTION: Now let's wait 60 seconds!"); try { + startTime.set(new Date().getTime()); Thread.sleep(60000); } catch (InterruptedException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. -- 2.43.0