From 6f89c96e88a8f437edc361b7c303a37f2683322e Mon Sep 17 00:00:00 2001 From: Someone Date: Mon, 10 Jun 2013 01:04:13 +0200 Subject: [PATCH] [JMS] debugging random behaviour --- .../sbc/valesriegler/group/GroupAgent.java | 8 ++-- .../sbc/valesriegler/group/GroupGUI.java | 5 +++ .../valesriegler/group/gui/GroupFrame.java | 37 ++++++++++--------- .../group/jms/GroupJMSNACMsgListener.java | 10 ++++- .../jms/nac/AbstractJMSNACMsgListener.java | 8 +++- 5 files changed, 43 insertions(+), 25 deletions(-) diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/group/GroupAgent.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/group/GroupAgent.java index a6998d4..ae4b9ca 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/group/GroupAgent.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/group/GroupAgent.java @@ -52,10 +52,10 @@ public class GroupAgent { public static void main(String[] args) { if (args.length != 1) { - // throw new IllegalArgumentException(USAGE); + throw new IllegalArgumentException(USAGE); } - String mw = "JMS";// args[0]; + String mw = args[0]; log.info("Middleware: " + mw); if ("JMS".equalsIgnoreCase(mw)) { @@ -67,7 +67,6 @@ public class GroupAgent { } groupAgent = new GroupAgent(); - if (!Util.runSimulation) { groupGui = new GroupGUI(); SwingUtilities.invokeLater(groupGui); @@ -78,7 +77,8 @@ public class GroupAgent { deliveryOverviewModel = new DeliveryOverviewModel(); groupModel = new GroupOverviewModel(); if (Util.useJMS) { - jmsnac = new JMSNAC(new GroupJMSNACMsgListener()); + GroupJMSNACMsgListener tmp = new GroupJMSNACMsgListener(); + jmsnac = new JMSNAC(tmp); } else { xvsm = new GroupAgentXVSM(); diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/group/GroupGUI.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/group/GroupGUI.java index 4ee4ec3..dae7a14 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/group/GroupGUI.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/group/GroupGUI.java @@ -1,11 +1,16 @@ package at.ac.tuwien.sbc.valesriegler.group; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import at.ac.tuwien.sbc.valesriegler.group.gui.GroupFrame; public class GroupGUI implements Runnable { + private static final Logger log = LoggerFactory.getLogger(GroupAgent.class); private GroupFrame frame; @Override public void run() { + log.debug("Starting GroupGUI."); frame = new GroupFrame(GroupAgent.getInstance().getGroupModel(), GroupAgent.getInstance().getDeliveryModel()); frame.pack(); frame.setVisible(true); diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/group/gui/GroupFrame.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/group/gui/GroupFrame.java index 34d5b0f..a32f12f 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/group/gui/GroupFrame.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/group/gui/GroupFrame.java @@ -5,10 +5,11 @@ import java.awt.GridLayout; import javax.swing.JFrame; import javax.swing.JPanel; -import at.ac.tuwien.sbc.valesriegler.common.Util; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import at.ac.tuwien.sbc.valesriegler.common.Util; + /** * Base Frame of the Group UI * @@ -18,40 +19,40 @@ import org.slf4j.LoggerFactory; @SuppressWarnings("serial") public class GroupFrame extends JFrame { private static final Logger log = LoggerFactory.getLogger(GroupFrame.class); - + public GroupFrame(GroupOverviewModel groupModel, DeliveryOverviewModel deliveryModel) { super("Groups"); + log.debug("GroupFrame()"); JPanel wrapper = new JPanel(); GridLayout wrapperLayout = new GridLayout(2, 2); wrapper.setLayout(wrapperLayout); // Create Wizard-like panel for the creation of groups - wrapper.add(new GroupCreationPanel(false)); + wrapper.add(new GroupCreationPanel(false)); - // Create Wizard-like panel for the creation of delivery groups - wrapper.add(new GroupCreationPanel(true)); + // Create Wizard-like panel for the creation of delivery groups + wrapper.add(new GroupCreationPanel(true)); // Create the panel for the group overview table initGroupOverview(wrapper, groupModel); - // Create the panel for the deliveries overview table - initDeliveriesOverview(wrapper, deliveryModel); + // Create the panel for the deliveries overview table + initDeliveriesOverview(wrapper, deliveryModel); - setContentPane(wrapper); + setContentPane(wrapper); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } - - private void initGroupOverview(JPanel wrapper, GroupOverviewModel groupModel) { - JPanel tablePanel = new JPanel(); - Util.createTableInTitledPanel(tablePanel, groupModel, "Group Overview"); - wrapper.add(tablePanel); + private void initGroupOverview(JPanel wrapper, GroupOverviewModel groupModel) { + JPanel tablePanel = new JPanel(); + Util.createTableInTitledPanel(tablePanel, groupModel, "Group Overview"); + wrapper.add(tablePanel); } - private void initDeliveriesOverview(JPanel wrapper, DeliveryOverviewModel deliveryModel) { - JPanel tablePanel = new JPanel(); - Util.createTableInTitledPanel(tablePanel, deliveryModel, "Deliveries Overview"); - wrapper.add(tablePanel); - } + private void initDeliveriesOverview(JPanel wrapper, DeliveryOverviewModel deliveryModel) { + JPanel tablePanel = new JPanel(); + Util.createTableInTitledPanel(tablePanel, deliveryModel, "Deliveries Overview"); + wrapper.add(tablePanel); + } } diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/group/jms/GroupJMSNACMsgListener.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/group/jms/GroupJMSNACMsgListener.java index 52fcb22..af51779 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/group/jms/GroupJMSNACMsgListener.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/group/jms/GroupJMSNACMsgListener.java @@ -24,7 +24,7 @@ public class GroupJMSNACMsgListener extends AbstractJMSNACMsgListener implements public GroupJMSNACMsgListener() { Thread th = new Thread(this); th.setDaemon(true); - th.run(); + th.start(); } @Override @@ -56,7 +56,15 @@ public class GroupJMSNACMsgListener extends AbstractJMSNACMsgListener implements while (true) { try { getJmsnac().sendNACMsg(new AddressInfoRequest()); + } catch (Exception e) { + log.warn("EXCEPTION!", e); + } + try { Thread.sleep(10000); + } catch (InterruptedException e) { + log.warn("EXCEPTION!", e); + } + try { GroupAgent.getInstance().getPizzeriaIdentifiers().clear(); } catch (Exception e) { log.warn("EXCEPTION!", e); diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/jms/nac/AbstractJMSNACMsgListener.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/jms/nac/AbstractJMSNACMsgListener.java index 4a90191..3a3ba3e 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/jms/nac/AbstractJMSNACMsgListener.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/jms/nac/AbstractJMSNACMsgListener.java @@ -2,6 +2,9 @@ package at.ac.tuwien.sbc.valesriegler.jms.nac; import javax.jms.MessageListener; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + /** * Abstract "Naming and Control"-msgListener. * @@ -9,12 +12,13 @@ import javax.jms.MessageListener; * */ public abstract class AbstractJMSNACMsgListener implements MessageListener { - // private static final Logger log = LoggerFactory.getLogger(AbstractJMSNACMsgListener.class); + private static final Logger log = LoggerFactory.getLogger(AbstractJMSNACMsgListener.class); private JMSNAC jmsnac = null; public AbstractJMSNACMsgListener() { } - protected void setJmsnac(JMSNAC jmsnac) { + public void setJmsnac(JMSNAC jmsnac) { + log.info("setJmsnac():" + jmsnac); this.jmsnac = jmsnac; } public JMSNAC getJmsnac() { -- 2.43.0