From 23ecbe80d0f775c85a3a4291dcd4c4ca74d02914 Mon Sep 17 00:00:00 2001 From: gtully Date: Fri, 24 Apr 2015 13:35:02 +0100 Subject: [PATCH] https://issues.apache.org/jira/browse/AMQ-5743 - confine logging to the jmx purge op --- .../java/org/apache/activemq/broker/jmx/QueueView.java | 8 ++++++++ .../java/org/apache/activemq/broker/region/Queue.java | 2 -- .../org/apache/activemq/broker/region/QueuePurgeTest.java | 4 ++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/QueueView.java b/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/QueueView.java index 076b4fc950..4ae081ed39 100644 --- a/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/QueueView.java +++ b/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/QueueView.java @@ -28,11 +28,15 @@ import org.apache.activemq.broker.region.QueueMessageReference; import org.apache.activemq.command.ActiveMQDestination; import org.apache.activemq.command.Message; import org.apache.activemq.util.BrokerSupport; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Provides a JMX Management view of a Queue. */ public class QueueView extends DestinationView implements QueueViewMBean { + private static final Logger LOG = LoggerFactory.getLogger(QueueView.class); + public QueueView(ManagedRegionBroker broker, Queue destination) { super(broker, destination); } @@ -53,7 +57,11 @@ public class QueueView extends DestinationView implements QueueViewMBean { } public void purge() throws Exception { + final long originalMessageCount = destination.getDestinationStatistics().getMessages().getCount(); + ((Queue)destination).purge(); + + LOG.info("{} purge of {} messages", destination.getActiveMQDestination().getQualifiedName(), originalMessageCount); } public boolean removeMessage(String messageId) throws Exception { diff --git a/activemq-broker/src/main/java/org/apache/activemq/broker/region/Queue.java b/activemq-broker/src/main/java/org/apache/activemq/broker/region/Queue.java index 8d12a8b641..232a7bae78 100755 --- a/activemq-broker/src/main/java/org/apache/activemq/broker/region/Queue.java +++ b/activemq-broker/src/main/java/org/apache/activemq/broker/region/Queue.java @@ -1233,8 +1233,6 @@ public class Queue extends BaseDestination implements Task, UsageListener, Index if (this.destinationStatistics.getMessages().getCount() > 0) { LOG.warn("{} after purge of {} messages, message count stats report: {}", getActiveMQDestination().getQualifiedName(), originalMessageCount, this.destinationStatistics.getMessages().getCount()); - } else { - LOG.info("{} purged of {} messages", getActiveMQDestination().getQualifiedName(), originalMessageCount); } gc(); this.destinationStatistics.getMessages().setCount(0); diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/broker/region/QueuePurgeTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/broker/region/QueuePurgeTest.java index 91209379ad..a121619d89 100644 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/broker/region/QueuePurgeTest.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/broker/region/QueuePurgeTest.java @@ -95,7 +95,7 @@ public class QueuePurgeTest extends CombinationTestSupport { QueueViewMBean proxy = getProxyToQueueViewMBean(); LOG.info("purging.."); - org.apache.log4j.Logger log4jLogger = org.apache.log4j.Logger.getLogger(org.apache.activemq.broker.region.Queue.class); + org.apache.log4j.Logger log4jLogger = org.apache.log4j.Logger.getLogger(org.apache.activemq.broker.jmx.QueueView.class); final AtomicBoolean gotPurgeLogMessage = new AtomicBoolean(false); Appender appender = new DefaultTestAppender() { @@ -103,7 +103,7 @@ public class QueuePurgeTest extends CombinationTestSupport { public void doAppend(LoggingEvent event) { if (event.getMessage() instanceof String) { String message = (String) event.getMessage(); - if (message.contains("purged of " + NUM_TO_SEND +" messages")) { + if (message.contains("purge of " + NUM_TO_SEND +" messages")) { LOG.info("Received a log message: {} ", event.getMessage()); gotPurgeLogMessage.set(true); }