diff --git a/spring-integration-jmx/src/main/java/org/springframework/integration/monitor/IntegrationMBeanExporter.java b/spring-integration-jmx/src/main/java/org/springframework/integration/monitor/IntegrationMBeanExporter.java
index 4d301e808e..40c720a3c3 100644
--- a/spring-integration-jmx/src/main/java/org/springframework/integration/monitor/IntegrationMBeanExporter.java
+++ b/spring-integration-jmx/src/main/java/org/springframework/integration/monitor/IntegrationMBeanExporter.java
@@ -610,6 +610,14 @@ public class IntegrationMBeanExporter extends MBeanExporter implements Applicati
return channelsByName.keySet().toArray(new String[channelsByName.size()]);
}
+ public MessageHandlerMetrics getHandlerMetrics(String name) {
+ if (handlersByName.containsKey(name)) {
+ return handlersByName.get(name);
+ }
+ logger.debug("No handler found for (" + name + ")");
+ return null;
+ }
+
public Statistics getHandlerDuration(String name) {
if (handlersByName.containsKey(name)) {
return handlersByName.get(name).getDuration();
@@ -618,6 +626,14 @@ public class IntegrationMBeanExporter extends MBeanExporter implements Applicati
return null;
}
+ public MessageSourceMetrics getSourceMetrics(String name) {
+ if (sourcesByName.containsKey(name)) {
+ return sourcesByName.get(name);
+ }
+ logger.debug("No source found for (" + name + ")");
+ return null;
+ }
+
public int getSourceMessageCount(String name) {
return (int) getSourceMessageCountLong(name);
}
@@ -630,6 +646,38 @@ public class IntegrationMBeanExporter extends MBeanExporter implements Applicati
return -1;
}
+ public MessageChannelMetrics getChannelMetrics(String name) {
+ if (channelsByName.containsKey(name)) {
+ return channelsByName.get(name);
+ }
+ logger.debug("No channel found for (" + name + ")");
+ return null;
+ }
+
+ public int getChannelSendCount(String name) {
+ return (int) getChannelSendCountLong(name);
+ }
+
+ public long getChannelSendCountLong(String name) {
+ if (channelsByName.containsKey(name)) {
+ return channelsByName.get(name).getSendCountLong();
+ }
+ logger.debug("No channel found for (" + name + ")");
+ return -1;
+ }
+
+ public int getChannelSendErrorCount(String name) {
+ return (int) getChannelSendErrorCountLong(name);
+ }
+
+ public long getChannelSendErrorCountLong(String name) {
+ if (channelsByName.containsKey(name)) {
+ return channelsByName.get(name).getSendErrorCountLong();
+ }
+ logger.debug("No channel found for (" + name + ")");
+ return -1;
+ }
+
public int getChannelReceiveCount(String name) {
return (int) getChannelReceiveCountLong(name);
}
diff --git a/spring-integration-jmx/src/test/java/org/springframework/integration/monitor/ChannelIntegrationTests-context.xml b/spring-integration-jmx/src/test/java/org/springframework/integration/monitor/ChannelIntegrationTests-context.xml
index 1263451ade..b2bb2d3f14 100644
--- a/spring-integration-jmx/src/test/java/org/springframework/integration/monitor/ChannelIntegrationTests-context.xml
+++ b/spring-integration-jmx/src/test/java/org/springframework/integration/monitor/ChannelIntegrationTests-context.xml
@@ -8,10 +8,11 @@
-
+
-
+
@@ -22,4 +23,8 @@
+
+
+
+
diff --git a/spring-integration-jmx/src/test/java/org/springframework/integration/monitor/ChannelIntegrationTests.java b/spring-integration-jmx/src/test/java/org/springframework/integration/monitor/ChannelIntegrationTests.java
index faaa6919a6..10c7ec64f1 100644
--- a/spring-integration-jmx/src/test/java/org/springframework/integration/monitor/ChannelIntegrationTests.java
+++ b/spring-integration-jmx/src/test/java/org/springframework/integration/monitor/ChannelIntegrationTests.java
@@ -12,14 +12,18 @@
*/
package org.springframework.integration.monitor;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.integration.handler.management.MessageHandlerMetrics;
import org.springframework.messaging.MessageChannel;
+import org.springframework.messaging.MessageDeliveryException;
import org.springframework.messaging.PollableChannel;
import org.springframework.messaging.support.GenericMessage;
import org.springframework.test.annotation.DirtiesContext;
@@ -50,15 +54,41 @@ public class ChannelIntegrationTests {
requests.send(new GenericMessage("foo"));
+ String intermediateChannelName = "" + intermediate;
+
+ assertEquals(1, messageChannelsMonitor.getChannelSendCount(intermediateChannelName));
+
double rate = messageChannelsMonitor.getChannelSendRate("" + requests).getMean();
assertTrue("No statistics for requests channel", rate >= 0);
- rate = messageChannelsMonitor.getChannelSendRate("" + intermediate).getMean();
+ rate = messageChannelsMonitor.getChannelSendRate(intermediateChannelName).getMean();
assertTrue("No statistics for intermediate channel", rate >= 0);
assertNotNull(intermediate.receive(100L));
- double count = messageChannelsMonitor.getChannelReceiveCount("" + intermediate);
- assertTrue("No statistics for intermediate channel", count >= 0);
+ assertEquals(1, messageChannelsMonitor.getChannelReceiveCount(intermediateChannelName));
+
+ requests.send(new GenericMessage("foo"));
+ try {
+ requests.send(new GenericMessage("foo"));
+ }
+ catch (MessageDeliveryException e) {
+ }
+
+ assertEquals(3, messageChannelsMonitor.getChannelSendCount(intermediateChannelName));
+
+ assertEquals(1, messageChannelsMonitor.getChannelSendErrorCount(intermediateChannelName));
+
+ assertSame(intermediate, messageChannelsMonitor.getChannelMetrics(intermediateChannelName));
+
+ MessageHandlerMetrics handlerMetrics = messageChannelsMonitor.getHandlerMetrics("bridge");
+
+ assertEquals(3, handlerMetrics.getHandleCount());
+ assertEquals(1, handlerMetrics.getErrorCount());
+
+ Thread.sleep(50);
+
+ assertTrue(messageChannelsMonitor.getSourceMessageCount("source") > 0);
+ assertTrue(messageChannelsMonitor.getSourceMetrics("source").getMessageCount() > 0);
}