diff --git a/spring-integration-jmx/src/main/java/org/springframework/integration/monitor/SimpleMessageChannelMonitor.java b/spring-integration-jmx/src/main/java/org/springframework/integration/monitor/DirectChannelMonitor.java similarity index 83% rename from spring-integration-jmx/src/main/java/org/springframework/integration/monitor/SimpleMessageChannelMonitor.java rename to spring-integration-jmx/src/main/java/org/springframework/integration/monitor/DirectChannelMonitor.java index e17e830d44..eb4f549a66 100644 --- a/spring-integration-jmx/src/main/java/org/springframework/integration/monitor/SimpleMessageChannelMonitor.java +++ b/spring-integration-jmx/src/main/java/org/springframework/integration/monitor/DirectChannelMonitor.java @@ -33,7 +33,7 @@ import org.springframework.util.StopWatch; * @author Helena Edelson */ @ManagedResource -public class SimpleMessageChannelMonitor implements MethodInterceptor, MessageChannelMonitor { +public class DirectChannelMonitor implements MethodInterceptor, MessageChannelMonitor { protected final Log logger = LogFactory.getLog(getClass()); @@ -43,16 +43,16 @@ public class SimpleMessageChannelMonitor implements MethodInterceptor, MessageCh public static final int DEFAULT_MOVING_AVERAGE_WINDOW = 10; - private ExponentialMovingAverageCumulativeHistory sendDuration = new ExponentialMovingAverageCumulativeHistory( + private ExponentialMovingAverage sendDuration = new ExponentialMovingAverage( DEFAULT_MOVING_AVERAGE_WINDOW); - private final ExponentialMovingAverageRateCumulativeHistory sendErrorRate = new ExponentialMovingAverageRateCumulativeHistory( + private final ExponentialMovingAverageRate sendErrorRate = new ExponentialMovingAverageRate( ONE_SECOND_SECONDS, ONE_MINUTE_SECONDS, DEFAULT_MOVING_AVERAGE_WINDOW); - private final ExponentialMovingAverageRatioCumulativeHistory sendSuccessRatio = new ExponentialMovingAverageRatioCumulativeHistory( + private final ExponentialMovingAverageRatio sendSuccessRatio = new ExponentialMovingAverageRatio( ONE_MINUTE_SECONDS, DEFAULT_MOVING_AVERAGE_WINDOW); - private final ExponentialMovingAverageRateCumulativeHistory sendRate = new ExponentialMovingAverageRateCumulativeHistory( + private final ExponentialMovingAverageRate sendRate = new ExponentialMovingAverageRate( ONE_SECOND_SECONDS, ONE_MINUTE_SECONDS, DEFAULT_MOVING_AVERAGE_WINDOW); private final AtomicInteger sendCount = new AtomicInteger(); @@ -61,7 +61,7 @@ public class SimpleMessageChannelMonitor implements MethodInterceptor, MessageCh private final String name; - public SimpleMessageChannelMonitor(String name) { + public DirectChannelMonitor(String name) { this.name = name; } @@ -107,14 +107,20 @@ public class SimpleMessageChannelMonitor implements MethodInterceptor, MessageCh Object result = invocation.proceed(); timer.stop(); - sendSuccessRatio.success(); - sendDuration.append(timer.getTotalTimeSeconds()); + if ((Boolean)result) { + sendSuccessRatio.success(); + sendDuration.append(timer.getTotalTimeSeconds()); + } else { + sendSuccessRatio.failure(); + sendErrorCount.incrementAndGet(); + sendErrorRate.increment(); + } return result; } catch (Throwable e) { - sendErrorCount.incrementAndGet(); sendSuccessRatio.failure(); + sendErrorCount.incrementAndGet(); sendErrorRate.increment(); throw e; } @@ -141,17 +147,17 @@ public class SimpleMessageChannelMonitor implements MethodInterceptor, MessageCh } @ManagedMetric(metricType = MetricType.GAUGE, displayName = "Channel Send Rate per Second") - public double getSendRate() { + public double getMeanSendRate() { return sendRate.getMean(); } @ManagedMetric(metricType = MetricType.GAUGE, displayName = "Channel Error Rate per Second") - public double getErrorRate() { + public double getMeanErrorRate() { return sendErrorRate.getMean(); } @ManagedMetric(metricType = MetricType.GAUGE, displayName = "Mean Channel Error Ratio per Minute") - public double getErrorRatio() { + public double getMeanErrorRatio() { return 1 - sendSuccessRatio.getMean(); } @@ -174,6 +180,18 @@ public class SimpleMessageChannelMonitor implements MethodInterceptor, MessageCh public double getStandardDeviationSendDuration() { return sendDuration.getStandardDeviation(); } + + public Statistics getSendDuration() { + return sendDuration.getStatistics(); + } + + public Statistics getSendRate() { + return sendRate.getStatistics(); + } + + public Statistics getErrorRate() { + return sendErrorRate.getStatistics(); + } @Override public String toString() { diff --git a/spring-integration-jmx/src/main/java/org/springframework/integration/monitor/ExponentialMovingAverageCumulativeHistory.java b/spring-integration-jmx/src/main/java/org/springframework/integration/monitor/ExponentialMovingAverage.java similarity index 88% rename from spring-integration-jmx/src/main/java/org/springframework/integration/monitor/ExponentialMovingAverageCumulativeHistory.java rename to spring-integration-jmx/src/main/java/org/springframework/integration/monitor/ExponentialMovingAverage.java index a6e117ec9b..bf47c86a0c 100644 --- a/spring-integration-jmx/src/main/java/org/springframework/integration/monitor/ExponentialMovingAverageCumulativeHistory.java +++ b/spring-integration-jmx/src/main/java/org/springframework/integration/monitor/ExponentialMovingAverage.java @@ -20,7 +20,7 @@ package org.springframework.integration.monitor; * @author Dave Syer * */ -public class ExponentialMovingAverageCumulativeHistory { +public class ExponentialMovingAverage { private int count; @@ -39,7 +39,7 @@ public class ExponentialMovingAverageCumulativeHistory { /** * @param window the exponential lapse window (number of measurements) */ - public ExponentialMovingAverageCumulativeHistory(int window) { + public ExponentialMovingAverage(int window) { this.decay = 1 - 1. / window; } @@ -76,10 +76,13 @@ public class ExponentialMovingAverageCumulativeHistory { return min; } + public Statistics getStatistics() { + return new Statistics(count, min, max, getMean(), getStandardDeviation()); + } + @Override public String toString() { - return String.format("[N=%d, min=%f, max=%f, mean=%f, sigma=%f]", count, min, max, getMean(), - getStandardDeviation()); + return getStatistics().toString(); } } diff --git a/spring-integration-jmx/src/main/java/org/springframework/integration/monitor/ExponentialMovingAverageRateCumulativeHistory.java b/spring-integration-jmx/src/main/java/org/springframework/integration/monitor/ExponentialMovingAverageRate.java similarity index 84% rename from spring-integration-jmx/src/main/java/org/springframework/integration/monitor/ExponentialMovingAverageRateCumulativeHistory.java rename to spring-integration-jmx/src/main/java/org/springframework/integration/monitor/ExponentialMovingAverageRate.java index 99bf8b41e5..bae74a915c 100644 --- a/spring-integration-jmx/src/main/java/org/springframework/integration/monitor/ExponentialMovingAverageRateCumulativeHistory.java +++ b/spring-integration-jmx/src/main/java/org/springframework/integration/monitor/ExponentialMovingAverageRate.java @@ -19,9 +19,9 @@ package org.springframework.integration.monitor; * @author Dave Syer * */ -public class ExponentialMovingAverageRateCumulativeHistory { +public class ExponentialMovingAverageRate { - private final ExponentialMovingAverageCumulativeHistory rates; + private final ExponentialMovingAverage rates; private double weight; @@ -42,8 +42,8 @@ public class ExponentialMovingAverageRateCumulativeHistory { * @param lapsePeriod the exponential lapse rate for the rate average (in seconds) * @param window the exponential lapse window (number of measurements) */ - public ExponentialMovingAverageRateCumulativeHistory(double period, double lapsePeriod, int window) { - rates = new ExponentialMovingAverageCumulativeHistory(10); + public ExponentialMovingAverageRate(double period, double lapsePeriod, int window) { + rates = new ExponentialMovingAverage(10); this.lapse = lapsePeriod > 0 ? 0.001 / lapsePeriod : 0; // convert to millisecs this.period = period * 1000; // convert to millisecs } @@ -99,10 +99,13 @@ public class ExponentialMovingAverageRateCumulativeHistory { return max > 0 ? 1 / max : 0; } + public Statistics getStatistics() { + return new Statistics(getCount(), min, max, getMean(), getStandardDeviation()); + } + @Override public String toString() { - return String.format("[N=%d, min=%f, max=%f, mean=%f, sigma=%f, timeSinceLast=%f]", getCount(), getMin(), - getMax(), getMean(), getStandardDeviation(), getTimeSinceLastMeasurement()); + return String.format("[%s, timeSinceLast=%f]", getStatistics(), getTimeSinceLastMeasurement()); } } diff --git a/spring-integration-jmx/src/main/java/org/springframework/integration/monitor/ExponentialMovingAverageRatioCumulativeHistory.java b/spring-integration-jmx/src/main/java/org/springframework/integration/monitor/ExponentialMovingAverageRatio.java similarity index 83% rename from spring-integration-jmx/src/main/java/org/springframework/integration/monitor/ExponentialMovingAverageRatioCumulativeHistory.java rename to spring-integration-jmx/src/main/java/org/springframework/integration/monitor/ExponentialMovingAverageRatio.java index 20b3db4135..2e2ca1a0e0 100644 --- a/spring-integration-jmx/src/main/java/org/springframework/integration/monitor/ExponentialMovingAverageRatioCumulativeHistory.java +++ b/spring-integration-jmx/src/main/java/org/springframework/integration/monitor/ExponentialMovingAverageRatio.java @@ -20,7 +20,7 @@ package org.springframework.integration.monitor; * @author Dave Syer * */ -public class ExponentialMovingAverageRatioCumulativeHistory { +public class ExponentialMovingAverageRatio { private double weight; @@ -30,14 +30,14 @@ public class ExponentialMovingAverageRatioCumulativeHistory { private final double lapse; - private final ExponentialMovingAverageCumulativeHistory cumulative; + private final ExponentialMovingAverage cumulative; /** * @param lapsePeriod the exponential lapse rate for the rate average (in seconds) * @param window the exponential lapse window (number of measurements) */ - public ExponentialMovingAverageRatioCumulativeHistory(double lapsePeriod, int window) { - this.cumulative = new ExponentialMovingAverageCumulativeHistory(window); + public ExponentialMovingAverageRatio(double lapsePeriod, int window) { + this.cumulative = new ExponentialMovingAverage(window); this.lapse = lapsePeriod > 0 ? 0.001 / lapsePeriod : 0; // convert to millisecs } @@ -93,10 +93,13 @@ public class ExponentialMovingAverageRatioCumulativeHistory { return cumulative.getMin(); } + public Statistics getStatistics() { + return new Statistics(getCount(), getMin(), getMax(), getMean(), getStandardDeviation()); + } + @Override public String toString() { - return String.format("[N=%d, min=%f, max=%f, mean=%f, sigma=%f, timeSinceLast=%f]", getCount(), getMin(), - getMax(), getMean(), getStandardDeviation(), getTimeSinceLastMeasurement()); + return String.format("[%s, timeSinceLast=%f]", getStatistics(), getTimeSinceLastMeasurement()); } } 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 0e527a37f2..e0a54cb357 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 @@ -81,9 +81,9 @@ public class IntegrationMBeanExporter extends MBeanExporter implements BeanPostP private Set handlers = new HashSet(); - private Set channels = new HashSet(); + private Set channels = new HashSet(); - private Map channelsByName = new HashMap(); + private Map channelsByName = new HashMap(); private Map handlersByName = new HashMap(); @@ -149,7 +149,7 @@ public class IntegrationMBeanExporter extends MBeanExporter implements BeanPostP return monitor; } if (bean instanceof MessageChannel) { - SimpleMessageChannelMonitor monitor; + DirectChannelMonitor monitor; if (bean instanceof PollableChannel) { Object target = extractTarget(bean); if (target instanceof QueueChannel) { @@ -160,7 +160,7 @@ public class IntegrationMBeanExporter extends MBeanExporter implements BeanPostP } } else { - monitor = new SimpleMessageChannelMonitor(beanName); + monitor = new DirectChannelMonitor(beanName); } Object advised = applyChannelInterceptor(bean, monitor, beanClassLoader); channels.add(monitor); @@ -288,32 +288,16 @@ public class IntegrationMBeanExporter extends MBeanExporter implements BeanPostP public Map getObjectNames() { return Collections.unmodifiableMap(objectNamesByName); } - - public double getHandlerMeanDuration(String name) { + + public Statistics getHandlerDuration(String name) { if (handlersByName.containsKey(name)) { - return handlersByName.get(name).getMeanDuration(); + return handlersByName.get(name).getDuration(); } logger.debug("No handler found for (" + name + ")"); - return -1; + return null; } - public long getChannelSendCount(String name) { - if (channelsByName.containsKey(name)) { - return channelsByName.get(name).getSendCount(); - } - logger.debug("No channel found for (" + name + ")"); - return -1; - } - - public long getChannelSendErrorCount(String name) { - if (channelsByName.containsKey(name)) { - return channelsByName.get(name).getSendErrorCount(); - } - logger.debug("No channel found for (" + name + ")"); - return -1; - } - - public long getChannelReceiveCount(String name) { + public int getChannelReceiveCount(String name) { if (channelsByName.containsKey(name)) { if (channelsByName.get(name) instanceof PollableChannelMonitor) { return ((PollableChannelMonitor) channelsByName.get(name)).getReceiveCount(); @@ -323,32 +307,24 @@ public class IntegrationMBeanExporter extends MBeanExporter implements BeanPostP return -1; } - public double getChannelSendRate(String name) { + public Statistics getChannelSendRate(String name) { if (channelsByName.containsKey(name)) { return channelsByName.get(name).getSendRate(); } logger.debug("No channel found for (" + name + ")"); - return -1; + return null; } - public double getChannelErrorRate(String name) { + public Statistics getChannelErrorRate(String name) { if (channelsByName.containsKey(name)) { return channelsByName.get(name).getErrorRate(); } logger.debug("No channel found for (" + name + ")"); - return -1; - } - - public double getChannelMeanSendDuration(String name) { - if (channelsByName.containsKey(name)) { - return channelsByName.get(name).getMeanSendDuration(); - } - logger.debug("No channel found for (" + name + ")"); - return -1; + return null; } private void registerChannels() { - for (SimpleMessageChannelMonitor monitor : channels) { + for (DirectChannelMonitor monitor : channels) { String name = monitor.getName(); // Only register once... if (!channelsByName.containsKey(name)) { @@ -379,7 +355,7 @@ public class IntegrationMBeanExporter extends MBeanExporter implements BeanPostP } } - private Object applyChannelInterceptor(Object bean, SimpleMessageChannelMonitor interceptor, + private Object applyChannelInterceptor(Object bean, DirectChannelMonitor interceptor, ClassLoader beanClassLoader) { NameMatchMethodPointcutAdvisor channelsAdvice = new NameMatchMethodPointcutAdvisor(interceptor); channelsAdvice.addMethodName("send"); diff --git a/spring-integration-jmx/src/main/java/org/springframework/integration/monitor/LifecycleMessageHandlerMonitor.java b/spring-integration-jmx/src/main/java/org/springframework/integration/monitor/LifecycleMessageHandlerMonitor.java index c0e3fba937..50cfa71bd6 100644 --- a/spring-integration-jmx/src/main/java/org/springframework/integration/monitor/LifecycleMessageHandlerMonitor.java +++ b/spring-integration-jmx/src/main/java/org/springframework/integration/monitor/LifecycleMessageHandlerMonitor.java @@ -76,6 +76,10 @@ public class LifecycleMessageHandlerMonitor implements MessageHandlerMonitor { return delegate.getStandardDeviationDuration(); } + public Statistics getDuration() { + return delegate.getDuration(); + } + public String getName() { return delegate.getName(); } diff --git a/spring-integration-jmx/src/main/java/org/springframework/integration/monitor/MessageChannelMonitor.java b/spring-integration-jmx/src/main/java/org/springframework/integration/monitor/MessageChannelMonitor.java index 54866688ec..149fb87f12 100644 --- a/spring-integration-jmx/src/main/java/org/springframework/integration/monitor/MessageChannelMonitor.java +++ b/spring-integration-jmx/src/main/java/org/springframework/integration/monitor/MessageChannelMonitor.java @@ -34,13 +34,13 @@ public interface MessageChannelMonitor { double getTimeSinceLastSend(); @ManagedMetric(metricType = MetricType.GAUGE, displayName = "Channel Send Rate per Second") - double getSendRate(); + double getMeanSendRate(); @ManagedMetric(metricType = MetricType.GAUGE, displayName = "Channel Error Rate per Second") - double getErrorRate(); + double getMeanErrorRate(); @ManagedMetric(metricType = MetricType.GAUGE, displayName = "Mean Channel Error Ratio per Minute") - double getErrorRatio(); + double getMeanErrorRatio(); @ManagedMetric(metricType = MetricType.GAUGE, displayName = "Channel Send Mean Duration") double getMeanSendDuration(); @@ -54,4 +54,10 @@ public interface MessageChannelMonitor { @ManagedMetric(metricType = MetricType.GAUGE, displayName = "Channel Send Standard Deviation Duration") double getStandardDeviationSendDuration(); + Statistics getSendDuration(); + + Statistics getSendRate(); + + Statistics getErrorRate(); + } \ No newline at end of file diff --git a/spring-integration-jmx/src/main/java/org/springframework/integration/monitor/MessageHandlerMonitor.java b/spring-integration-jmx/src/main/java/org/springframework/integration/monitor/MessageHandlerMonitor.java index afce109a8b..6c29af162f 100644 --- a/spring-integration-jmx/src/main/java/org/springframework/integration/monitor/MessageHandlerMonitor.java +++ b/spring-integration-jmx/src/main/java/org/springframework/integration/monitor/MessageHandlerMonitor.java @@ -42,6 +42,8 @@ public interface MessageHandlerMonitor { @ManagedMetric(metricType = MetricType.GAUGE, displayName = "Handler Standard Deviation Duration") double getStandardDeviationDuration(); + + Statistics getDuration(); String getName(); diff --git a/spring-integration-jmx/src/main/java/org/springframework/integration/monitor/PollableChannelMonitor.java b/spring-integration-jmx/src/main/java/org/springframework/integration/monitor/PollableChannelMonitor.java index 6fc6c8c89e..9bcb444d4b 100644 --- a/spring-integration-jmx/src/main/java/org/springframework/integration/monitor/PollableChannelMonitor.java +++ b/spring-integration-jmx/src/main/java/org/springframework/integration/monitor/PollableChannelMonitor.java @@ -15,7 +15,7 @@ */ package org.springframework.integration.monitor; -import java.util.concurrent.atomic.AtomicLong; +import java.util.concurrent.atomic.AtomicInteger; import org.aopalliance.intercept.MethodInvocation; import org.springframework.integration.MessageChannel; @@ -28,11 +28,11 @@ import org.springframework.jmx.support.MetricType; * @since 2.0 * */ -public class PollableChannelMonitor extends SimpleMessageChannelMonitor { +public class PollableChannelMonitor extends DirectChannelMonitor { - private final AtomicLong receiveCount = new AtomicLong(); + private final AtomicInteger receiveCount = new AtomicInteger(); - private final AtomicLong receiveErrorCount = new AtomicLong(); + private final AtomicInteger receiveErrorCount = new AtomicInteger(); /** * @param name @@ -68,12 +68,12 @@ public class PollableChannelMonitor extends SimpleMessageChannelMonitor { } @ManagedMetric(metricType = MetricType.COUNTER, displayName = "MessageChannel Receives") - public long getReceiveCount() { + public int getReceiveCount() { return receiveCount.get(); } @ManagedMetric(metricType = MetricType.COUNTER, displayName = "MessageChannel Receive Errors") - public long getReceiveErrorCount() { + public int getReceiveErrorCount() { return receiveErrorCount.get(); } diff --git a/spring-integration-jmx/src/main/java/org/springframework/integration/monitor/SimpleMessageHandlerMonitor.java b/spring-integration-jmx/src/main/java/org/springframework/integration/monitor/SimpleMessageHandlerMonitor.java index 793da869f3..485243bf2a 100644 --- a/spring-integration-jmx/src/main/java/org/springframework/integration/monitor/SimpleMessageHandlerMonitor.java +++ b/spring-integration-jmx/src/main/java/org/springframework/integration/monitor/SimpleMessageHandlerMonitor.java @@ -36,7 +36,7 @@ public class SimpleMessageHandlerMonitor implements MessageHandler, MessageHandl private final AtomicInteger errorCount = new AtomicInteger(); - private final ExponentialMovingAverageCumulativeHistory duration = new ExponentialMovingAverageCumulativeHistory( + private final ExponentialMovingAverage duration = new ExponentialMovingAverage( DEFAULT_MOVING_AVERAGE_WINDOW); private String name; @@ -128,6 +128,10 @@ public class SimpleMessageHandlerMonitor implements MessageHandler, MessageHandl public double getStandardDeviationDuration() { return duration.getStandardDeviation(); } + + public Statistics getDuration() { + return duration.getStatistics(); + } @Override public String toString() { diff --git a/spring-integration-jmx/src/main/java/org/springframework/integration/monitor/Statistics.java b/spring-integration-jmx/src/main/java/org/springframework/integration/monitor/Statistics.java new file mode 100644 index 0000000000..19dcd86003 --- /dev/null +++ b/spring-integration-jmx/src/main/java/org/springframework/integration/monitor/Statistics.java @@ -0,0 +1,69 @@ +/* + * Copyright 2002-2010 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.integration.monitor; + +/** + * @author Dave Syer + * + * @since 2.0 + * + */ +public class Statistics { + + private final int count; + private final double min; + private final double max; + private final double mean; + private final double standardDeviation; + + /** + * + */ + public Statistics(int count, double min, double max, double mean, double standardDeviation) { + this.count = count; + this.min = min; + this.max = max; + this.mean = mean; + this.standardDeviation = standardDeviation; + } + + public int getCount() { + return count; + } + + public double getMin() { + return min; + } + + public double getMax() { + return max; + } + + public double getMean() { + return mean; + } + + public double getStandardDeviation() { + return standardDeviation; + } + + @Override + public String toString() { + return String.format("[N=%d, min=%f, max=%f, mean=%f, sigma=%f]", count, min, max, getMean(), + getStandardDeviation()); + } + +} diff --git a/spring-integration-jmx/src/test/java/org/springframework/integration/IgnoredTestSuite.java b/spring-integration-jmx/src/test/java/org/springframework/integration/IgnoredTestSuite.java index a66e09a61a..b6061b93dc 100644 --- a/spring-integration-jmx/src/test/java/org/springframework/integration/IgnoredTestSuite.java +++ b/spring-integration-jmx/src/test/java/org/springframework/integration/IgnoredTestSuite.java @@ -12,8 +12,8 @@ import org.springframework.integration.jmx.OperationInvokingMessageHandlerTests; import org.springframework.integration.jmx.config.NotificationListeningChannelAdapterParserTests; import org.springframework.integration.jmx.config.OperationInvokingChannelAdapterParserTests; import org.springframework.integration.jmx.config.OperationInvokingOutboundGatewayTests; -import org.springframework.integration.monitor.ExponentialMovingAverageCumulativeHistoryTests; -import org.springframework.integration.monitor.ExponentialMovingAverageRatioCumulativeHistoryTests; +import org.springframework.integration.monitor.ExponentialMovingAverageTests; +import org.springframework.integration.monitor.ExponentialMovingAverageRatioTests; import org.springframework.integration.monitor.HandlerMonitoringIntegrationTests; import org.springframework.integration.monitor.MessageChannelsMonitorIntegrationTests; @@ -41,10 +41,10 @@ import org.springframework.integration.monitor.MessageChannelsMonitorIntegration */ @RunWith(Suite.class) @SuiteClasses(value = { OperationInvokingMessageHandlerTests.class, - ExponentialMovingAverageCumulativeHistoryTests.class, OperationInvokingChannelAdapterParserTests.class, + ExponentialMovingAverageTests.class, OperationInvokingChannelAdapterParserTests.class, HandlerMonitoringIntegrationTests.class, NotificationListeningMessageProducerTests.class, OperationInvokingOutboundGatewayTests.class, NotificationListeningChannelAdapterParserTests.class, - ControlBusXmlTests.class, ExponentialMovingAverageRatioCumulativeHistoryTests.class, + ControlBusXmlTests.class, ExponentialMovingAverageRatioTests.class, AttributePollingMessageSourceTests.class, ControlBusTests.class, MessageChannelsMonitorIntegrationTests.class }) @Ignore public class IgnoredTestSuite { diff --git a/spring-integration-jmx/src/test/java/org/springframework/integration/control/ControlBusTests.java b/spring-integration-jmx/src/test/java/org/springframework/integration/control/ControlBusTests.java index 0d911cf0d8..df2253b3c0 100644 --- a/spring-integration-jmx/src/test/java/org/springframework/integration/control/ControlBusTests.java +++ b/spring-integration-jmx/src/test/java/org/springframework/integration/control/ControlBusTests.java @@ -44,7 +44,7 @@ import org.springframework.integration.handler.BridgeHandler; import org.springframework.integration.monitor.IntegrationMBeanExporter; import org.springframework.integration.monitor.LifecycleMessageHandlerMonitor; import org.springframework.integration.monitor.QueueChannelMonitor; -import org.springframework.integration.monitor.SimpleMessageChannelMonitor; +import org.springframework.integration.monitor.DirectChannelMonitor; import org.springframework.jmx.support.MBeanServerFactoryBean; import org.springframework.jmx.support.ObjectNameManager; import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; @@ -86,7 +86,7 @@ public class ControlBusTests { MBeanServer mbeanServer = context.getBean("mbeanServer", MBeanServer.class); ObjectInstance instance = mbeanServer.getObjectInstance(ObjectNameManager .getInstance("domain.test1:type=MessageChannel,name=directChannel")); - assertEquals(SimpleMessageChannelMonitor.class.getName(), instance.getClassName()); + assertEquals(DirectChannelMonitor.class.getName(), instance.getClassName()); } @Test @@ -99,7 +99,7 @@ public class ControlBusTests { ObjectInstance instance = mbeanServer .getObjectInstance(ObjectNameManager .getInstance("domain.test1b:type=MessageChannel,name=org.springframework.integration.generated#0,source=anonymous")); - assertEquals(SimpleMessageChannelMonitor.class.getName(), instance.getClassName()); + assertEquals(DirectChannelMonitor.class.getName(), instance.getClassName()); } @Test @@ -111,7 +111,7 @@ public class ControlBusTests { MBeanServer mbeanServer = context.getBean("mbeanServer", MBeanServer.class); ObjectInstance instance = mbeanServer.getObjectInstance(ObjectNameManager .getInstance("domain.test1a:type=MessageChannel,name=directChannel,foo=bar")); - assertEquals(SimpleMessageChannelMonitor.class.getName(), instance.getClassName()); + assertEquals(DirectChannelMonitor.class.getName(), instance.getClassName()); } @Test diff --git a/spring-integration-jmx/src/test/java/org/springframework/integration/control/ControlBusXmlTests.java b/spring-integration-jmx/src/test/java/org/springframework/integration/control/ControlBusXmlTests.java index b43003d698..af5487c67b 100644 --- a/spring-integration-jmx/src/test/java/org/springframework/integration/control/ControlBusXmlTests.java +++ b/spring-integration-jmx/src/test/java/org/springframework/integration/control/ControlBusXmlTests.java @@ -28,7 +28,7 @@ import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.integration.monitor.LifecycleMessageHandlerMonitor; import org.springframework.integration.monitor.QueueChannelMonitor; -import org.springframework.integration.monitor.SimpleMessageChannelMonitor; +import org.springframework.integration.monitor.DirectChannelMonitor; import org.springframework.jmx.support.ObjectNameManager; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -51,7 +51,7 @@ public class ControlBusXmlTests { public void directChannelRegistered() throws Exception { ObjectInstance instance = mbeanServer.getObjectInstance( ObjectNameManager.getInstance(DOMAIN + ":type=MessageChannel,name=testDirectChannel")); - assertEquals(SimpleMessageChannelMonitor.class.getName(), instance.getClassName()); + assertEquals(DirectChannelMonitor.class.getName(), instance.getClassName()); } @Test 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 4aac751379..72133ba6c9 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 @@ -42,11 +42,11 @@ public class ChannelIntegrationTests { requests.send(new GenericMessage("foo")); - double duration = messageChannelsMonitor.getChannelMeanSendDuration("" + requests); - assertTrue("No statistics for requests channel", duration >= 0); + double rate = messageChannelsMonitor.getChannelSendRate("" + requests).getMean(); + assertTrue("No statistics for requests channel", rate >= 0); - duration = messageChannelsMonitor.getChannelMeanSendDuration("" + intermediate); - assertTrue("No statistics for intermediate channel", duration >= 0); + rate = messageChannelsMonitor.getChannelSendRate("" + intermediate).getMean(); + assertTrue("No statistics for intermediate channel", rate >= 0); assertNotNull(intermediate.receive(100L)); double count = messageChannelsMonitor.getChannelReceiveCount("" + intermediate); diff --git a/spring-integration-jmx/src/test/java/org/springframework/integration/monitor/ExponentialMovingAverageRateCumulativeHistoryTests.java b/spring-integration-jmx/src/test/java/org/springframework/integration/monitor/ExponentialMovingAverageRateTests.java similarity index 91% rename from spring-integration-jmx/src/test/java/org/springframework/integration/monitor/ExponentialMovingAverageRateCumulativeHistoryTests.java rename to spring-integration-jmx/src/test/java/org/springframework/integration/monitor/ExponentialMovingAverageRateTests.java index c2401800e6..9f6979719b 100644 --- a/spring-integration-jmx/src/test/java/org/springframework/integration/monitor/ExponentialMovingAverageRateCumulativeHistoryTests.java +++ b/spring-integration-jmx/src/test/java/org/springframework/integration/monitor/ExponentialMovingAverageRateTests.java @@ -24,9 +24,9 @@ import org.junit.Test; * @author Dave Syer * */ -public class ExponentialMovingAverageRateCumulativeHistoryTests { +public class ExponentialMovingAverageRateTests { - private ExponentialMovingAverageRateCumulativeHistory history = new ExponentialMovingAverageRateCumulativeHistory( + private ExponentialMovingAverageRate history = new ExponentialMovingAverageRate( 1., 10., 10); @Test diff --git a/spring-integration-jmx/src/test/java/org/springframework/integration/monitor/ExponentialMovingAverageRatioCumulativeHistoryTests.java b/spring-integration-jmx/src/test/java/org/springframework/integration/monitor/ExponentialMovingAverageRatioTests.java similarity index 94% rename from spring-integration-jmx/src/test/java/org/springframework/integration/monitor/ExponentialMovingAverageRatioCumulativeHistoryTests.java rename to spring-integration-jmx/src/test/java/org/springframework/integration/monitor/ExponentialMovingAverageRatioTests.java index f0602e4e0e..acbb8e7e67 100644 --- a/spring-integration-jmx/src/test/java/org/springframework/integration/monitor/ExponentialMovingAverageRatioCumulativeHistoryTests.java +++ b/spring-integration-jmx/src/test/java/org/springframework/integration/monitor/ExponentialMovingAverageRatioTests.java @@ -24,9 +24,9 @@ import org.junit.Test; * @author Dave Syer * */ -public class ExponentialMovingAverageRatioCumulativeHistoryTests { +public class ExponentialMovingAverageRatioTests { - private ExponentialMovingAverageRatioCumulativeHistory history = new ExponentialMovingAverageRatioCumulativeHistory( + private ExponentialMovingAverageRatio history = new ExponentialMovingAverageRatio( 0.5, 10); @Test diff --git a/spring-integration-jmx/src/test/java/org/springframework/integration/monitor/ExponentialMovingAverageCumulativeHistoryTests.java b/spring-integration-jmx/src/test/java/org/springframework/integration/monitor/ExponentialMovingAverageTests.java similarity index 88% rename from spring-integration-jmx/src/test/java/org/springframework/integration/monitor/ExponentialMovingAverageCumulativeHistoryTests.java rename to spring-integration-jmx/src/test/java/org/springframework/integration/monitor/ExponentialMovingAverageTests.java index b53c2f47fd..eafff4aae1 100644 --- a/spring-integration-jmx/src/test/java/org/springframework/integration/monitor/ExponentialMovingAverageCumulativeHistoryTests.java +++ b/spring-integration-jmx/src/test/java/org/springframework/integration/monitor/ExponentialMovingAverageTests.java @@ -23,9 +23,9 @@ import org.junit.Test; * @author Dave Syer * */ -public class ExponentialMovingAverageCumulativeHistoryTests { +public class ExponentialMovingAverageTests { - private ExponentialMovingAverageCumulativeHistory history = new ExponentialMovingAverageCumulativeHistory(10); + private ExponentialMovingAverage history = new ExponentialMovingAverage(10); @Test public void testGetCount() { diff --git a/spring-integration-jmx/src/test/java/org/springframework/integration/monitor/HandlerMonitoringIntegrationTests.java b/spring-integration-jmx/src/test/java/org/springframework/integration/monitor/HandlerMonitoringIntegrationTests.java index 82e2fe6f35..25c968185c 100644 --- a/spring-integration-jmx/src/test/java/org/springframework/integration/monitor/HandlerMonitoringIntegrationTests.java +++ b/spring-integration-jmx/src/test/java/org/springframework/integration/monitor/HandlerMonitoringIntegrationTests.java @@ -82,8 +82,8 @@ public class HandlerMonitoringIntegrationTests { channel.send(new GenericMessage("bar")); assertEquals(before + 1, service.getCounter()); - double duration = messageHandlersMonitor.getHandlerMeanDuration(monitor); - assertTrue("No statistics for input channel", duration > 0); + int count = messageHandlersMonitor.getHandlerDuration(monitor).getCount(); + assertTrue("No statistics for input channel", count > 0); } finally { context.close(); diff --git a/spring-integration-jmx/src/test/java/org/springframework/integration/monitor/MessageChannelsMonitorIntegrationTests.java b/spring-integration-jmx/src/test/java/org/springframework/integration/monitor/MessageChannelsMonitorIntegrationTests.java index 5e93db558c..61d04e6837 100644 --- a/spring-integration-jmx/src/test/java/org/springframework/integration/monitor/MessageChannelsMonitorIntegrationTests.java +++ b/spring-integration-jmx/src/test/java/org/springframework/integration/monitor/MessageChannelsMonitorIntegrationTests.java @@ -13,7 +13,6 @@ package org.springframework.integration.monitor; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -70,11 +69,8 @@ public class MessageChannelsMonitorIntegrationTests { assertEquals(before + 50, service.getCounter()); // The handler monitor is registered under the endpoint id (since it is explicit) - double sends = messageChannelsMonitor.getChannelSendCount("" + channel); + int sends = messageChannelsMonitor.getChannelSendRate("" + channel).getCount(); assertEquals("No send statistics for input channel", 50, sends, 0.01); - double rate = messageChannelsMonitor.getChannelSendRate("" + channel); - assertTrue(String.format("Unexpected rate statistics for input channel %f %f", 60000. / 20L, rate), - 60000. / 20L > rate && rate > 0); } finally { @@ -106,13 +102,10 @@ public class MessageChannelsMonitorIntegrationTests { assertEquals(before + 10, service.getCounter()); // The handler monitor is registered under the endpoint id (since it is explicit) - double sends = messageChannelsMonitor.getChannelSendCount("" + channel); + int sends = messageChannelsMonitor.getChannelSendRate("" + channel).getCount(); assertEquals("No send statistics for input channel", 11, sends, 0.01); - double errors = messageChannelsMonitor.getChannelSendErrorCount("" + channel); + int errors = messageChannelsMonitor.getChannelErrorRate("" + channel).getCount(); assertEquals("No error statistics for input channel", 1, errors, 0.01); - double rate = messageChannelsMonitor.getChannelErrorRate("" + channel); - assertTrue(String.format("Unexpected error statistics for input channel %f %f", 60000. / 20L, rate), - 60000. / 20L > rate && rate > 0); } finally { context.close(); @@ -143,11 +136,11 @@ public class MessageChannelsMonitorIntegrationTests { assertEquals(before + 10, service.getCounter()); // The handler monitor is registered under the endpoint id (since it is explicit) - long sends = messageChannelsMonitor.getChannelSendCount("" + channel); + int sends = messageChannelsMonitor.getChannelSendRate("" + channel).getCount(); assertEquals("No send statistics for input channel", 11, sends); - long receives = messageChannelsMonitor.getChannelReceiveCount("" + channel); + int receives = messageChannelsMonitor.getChannelReceiveCount("" + channel); assertEquals("No send statistics for input channel", 11, receives); - long errors = messageChannelsMonitor.getChannelSendErrorCount("" + channel); + int errors = messageChannelsMonitor.getChannelErrorRate("" + channel).getCount(); assertEquals("Expect no errors for input channel (handler fails)", 0, errors); } finally { @@ -167,7 +160,7 @@ public class MessageChannelsMonitorIntegrationTests { assertEquals(before + 1, service.getCounter()); // The handler monitor is registered under the endpoint id (since it is explicit) - double sends = messageChannelsMonitor.getChannelSendCount("" + channel); + int sends = messageChannelsMonitor.getChannelSendRate("" + channel).getCount(); assertEquals("No statistics for input channel", 1, sends, 0.01); }