From 196fc2a3bcd569d2dd6a100a457447c9433a284e Mon Sep 17 00:00:00 2001 From: Jan Vales Date: Mon, 10 Jun 2013 21:01:46 +0200 Subject: [PATCH] [JMS] corrected benchmarking. --- .../CookedDeliveryOrders.java | 52 ++++++++++--------- .../sbc/valesriegler/group/GroupAgent.java | 5 +- .../group/jms/GroupJMSNACMsgListener.java | 3 +- .../sbc/valesriegler/jms/nac/JMSNAC.java | 8 +++ src/main/resources/logback.xml | 4 +- 5 files changed, 44 insertions(+), 28 deletions(-) diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/driver/jms/messageListeners/CookedDeliveryOrders.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/driver/jms/messageListeners/CookedDeliveryOrders.java index dfde528..10c09df 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/driver/jms/messageListeners/CookedDeliveryOrders.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/driver/jms/messageListeners/CookedDeliveryOrders.java @@ -54,22 +54,25 @@ public class CookedDeliveryOrders implements MessageListener { OrderDeliveredInfo odi = new OrderDeliveredInfo(doi.getDeliveryGroupData(), driver.getId()); // Deliver to destination broker - try { - ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(Util.JMS_DELIVERY_DESTINATION); - Connection connection = connectionFactory.createConnection(); - connection.start(); - log.debug("CookedDelivery:ActiveMQConnectionFactory::" + connection); - - Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); - MessageProducer prod = session.createProducer(session.createQueue(addr)); - prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT); - odi.getDeliveryGroupData().setDeliveryStatus(DeliveryStatus.DELIVERED); - prod.send(session.createObjectMessage(odi)); - session.close(); - connection.close(); - delivered = true; - } catch (JMSException e) { - log.error("EXCEPTION!", e); + if (!Util.runSimulation) { + try { + ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory( + Util.JMS_DELIVERY_DESTINATION); + Connection connection = connectionFactory.createConnection(); + connection.start(); + log.debug("CookedDelivery:ActiveMQConnectionFactory::" + connection); + + Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); + MessageProducer prod = session.createProducer(session.createQueue(addr)); + prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT); + odi.getDeliveryGroupData().setDeliveryStatus(DeliveryStatus.DELIVERED); + prod.send(session.createObjectMessage(odi)); + session.close(); + connection.close(); + delivered = true; + } catch (JMSException e) { + log.error("EXCEPTION!", e); + } } if (!delivered) { @@ -82,18 +85,19 @@ public class CookedDeliveryOrders implements MessageListener { connection.start(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); - MessageProducer prod = session.createProducer(session.createQueue("PizzeriaConnector")); - prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT); - prod.send(session.createObjectMessage(odi)); - session.close(); - - session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); - prod = session.createProducer(session.createQueue("GroupConnector")); + MessageProducer prod = session.createProducer(session.createQueue("GroupConnector")); prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT); prod.send(session.createObjectMessage(odi)); session.close(); - connection.close(); + if (!Util.runSimulation) { + session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); + prod = session.createProducer(session.createQueue("PizzeriaConnector")); + prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT); + prod.send(session.createObjectMessage(odi)); + session.close(); + connection.close(); + } } else { log.warn("Received unknown Object: " + obj); } 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 096ed93..5e6c2fc 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 @@ -1,5 +1,6 @@ package at.ac.tuwien.sbc.valesriegler.group; +import java.lang.management.ManagementFactory; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -61,7 +62,9 @@ public class GroupAgent { } String mw = args[0]; - log.info("Middleware: " + mw); + log.warn("Middleware: " + mw); + log.warn("JVM: " + ManagementFactory.getRuntimeMXBean().getName()); + log.warn("THREAD: " + Thread.currentThread().getName()); if ("JMS".equalsIgnoreCase(mw)) { Util.useJMS = true; 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 0d45921..61235bb 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 @@ -51,11 +51,12 @@ public class GroupJMSNACMsgListener extends AbstractJMSNACMsgListener implements return; } else if (obj instanceof BenchmarkStop) { - log.debug("Received: " + obj); + log.warn("Received: " + obj); for (String keys : JMSGroupConnector.getConnectors().keySet()) { JMSGroupConnector c = JMSGroupConnector.getConnector(keys); c.getConnection().close(); GroupAgent.getInstance().getDeliveryModel().createStatistics(); + GroupAgent.getJmsnac().stop(); } return; diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/jms/nac/JMSNAC.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/jms/nac/JMSNAC.java index 4605d65..02f403d 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/jms/nac/JMSNAC.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/jms/nac/JMSNAC.java @@ -49,4 +49,12 @@ public class JMSNAC { prod.send(session.createObjectMessage(msg)); session.close(); } + + public void stop() { + try { + connection.close(); + } catch (JMSException e) { + log.error("EXCEPTION!", e); + } + } } diff --git a/src/main/resources/logback.xml b/src/main/resources/logback.xml index 21d6cda..17889f6 100644 --- a/src/main/resources/logback.xml +++ b/src/main/resources/logback.xml @@ -7,12 +7,12 @@ - %-30(%d{HH:mm:ss.SSS} [%thread]) %-5level %logger{32} - %msg%n + %-30(%d{HH:mm:ss.SSS} [%thread]) %-5level %logger{32} -.- %msg%n - + -- 2.43.0