Skip to content

Commit

Permalink
INT-3496: JMX Metrics: Int->Long for All count
Browse files Browse the repository at this point in the history
JIRA: https://jira.spring.io/browse/INT-3496

**Cherry-pick to 4.0.x & 3.0.x**

INT-3496: revert `int` methods and introduce `long` methods for `count` metrics
  • Loading branch information
artembilan authored and garyrussell committed Aug 18, 2014
1 parent 248c970 commit 59c7c0e
Show file tree
Hide file tree
Showing 20 changed files with 241 additions and 85 deletions.
Original file line number Diff line number Diff line change
@@ -1,33 +1,34 @@
/*
* Copyright 2009-2010 the original author or authors.
*
* Copyright 2009-2014 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;

import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;

import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import org.springframework.jmx.export.annotation.ManagedResource;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageChannel;
import org.springframework.jmx.export.annotation.ManagedResource;
import org.springframework.util.StopWatch;

/**
* Registers all message channels, and accumulates statistics about their performance. The statistics are then published
* locally for other components to consume and publish remotely.
*
*
* @author Dave Syer
* @author Helena Edelson
* @since 2.0
Expand Down Expand Up @@ -56,9 +57,9 @@ public class DirectChannelMetrics implements MethodInterceptor, MessageChannelMe
private final ExponentialMovingAverageRate sendRate = new ExponentialMovingAverageRate(
ONE_SECOND_SECONDS, ONE_MINUTE_SECONDS, DEFAULT_MOVING_AVERAGE_WINDOW);

private final AtomicInteger sendCount = new AtomicInteger();
private final AtomicLong sendCount = new AtomicLong();

private final AtomicInteger sendErrorCount = new AtomicInteger();
private final AtomicLong sendErrorCount = new AtomicLong();

private final String name;

Expand Down Expand Up @@ -136,7 +137,7 @@ private Object monitorSend(MethodInvocation invocation, MessageChannel channel,
}
}
}

public synchronized void reset() {
sendDuration.reset();
sendErrorRate.reset();
Expand All @@ -147,10 +148,18 @@ public synchronized void reset() {
}

public int getSendCount() {
return (int) sendCount.get();
}

public long getSendCountLong() {
return sendCount.get();
}

public int getSendErrorCount() {
return (int) sendErrorCount.get();
}

public long getSendErrorCountLong() {
return sendErrorCount.get();
}

Expand Down Expand Up @@ -185,11 +194,11 @@ public double getMaxSendDuration() {
public double getStandardDeviationSendDuration() {
return sendDuration.getStandardDeviation();
}

public Statistics getSendDuration() {
return sendDuration.getStatistics();
}

public Statistics getSendRate() {
return sendRate.getStatistics();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/*
* Copyright 2009-2010 the original author or authors.
*
* Copyright 2009-2014 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.
Expand All @@ -20,13 +20,13 @@
* weight, with a decay factor determined by a "window" size chosen by the caller. The result is a good approximation to
* the statistics of the series but with more weight given to recent measurements, so if the statistics change over time
* those trends can be approximately reflected.
*
*
* @author Dave Syer
* @since 2.0
*/
public class ExponentialMovingAverage {

private volatile int count;
private volatile long count;

private volatile double weight;

Expand All @@ -44,7 +44,7 @@ public class ExponentialMovingAverage {
/**
* Create a moving average accumulator with decay lapse window provided. Measurements older than this will have
* smaller weight than <code>1/e</code>.
*
*
* @param window the exponential lapse window (number of measurements)
*/
public ExponentialMovingAverage(int window) {
Expand All @@ -63,7 +63,7 @@ public synchronized void reset() {

/**
* Add a new measurement to the series.
*
*
* @param value the measurement to append
*/
public synchronized void append(double value) {
Expand All @@ -83,6 +83,13 @@ public synchronized void append(double value) {
* @return the number of measurements recorded
*/
public int getCount() {
return (int) count;
}

/**
* @return the number of measurements recorded
*/
public long getCountLong() {
return count;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2009-2013 the original author or authors.
* Copyright 2009-2014 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
Expand Down Expand Up @@ -96,6 +96,14 @@ public int getCount() {
return rates.getCount();
}

/**
* @return the number of measurements recorded
* @since 3.0
*/
public long getCountLong() {
return rates.getCountLong();
}

/**
* @return the time in seconds since the last measurement
*/
Expand All @@ -107,7 +115,7 @@ public double getTimeSinceLastMeasurement() {
* @return the mean value
*/
public double getMean() {
int count = rates.getCount();
long count = rates.getCountLong();
if (count == 0) {
return 0;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2009-2010 the original author or authors.
* Copyright 2009-2014 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
Expand Down Expand Up @@ -88,6 +88,13 @@ public int getCount() {
return cumulative.getCount();
}

/**
* @return the number of measurements recorded
*/
public long getCountLong() {
return cumulative.getCountLong();
}

/**
* @return the time in seconds since the last measurement
*/
Expand All @@ -99,7 +106,7 @@ public double getTimeSinceLastMeasurement() {
* @return the mean success rate
*/
public double getMean() {
int count = cumulative.getCount();
long count = cumulative.getCountLong();
if (count == 0) {
// Optimistic to start: success rate is 100%
return 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -631,9 +631,14 @@ public String[] getHandlerNames() {

@ManagedMetric(metricType = MetricType.GAUGE, displayName = "Active Handler Count")
public int getActiveHandlerCount() {
return (int) getActiveHandlerCountLong();
}

@ManagedMetric(metricType = MetricType.GAUGE, displayName = "Active Handler Count")
public long getActiveHandlerCountLong() {
int count = 0;
for (MessageHandlerMetrics monitor : handlers) {
count += monitor.getActiveCount();
count += monitor.getActiveCountLong();
}
return count;
}
Expand Down Expand Up @@ -663,17 +668,25 @@ public Statistics getHandlerDuration(String name) {
}

public int getSourceMessageCount(String name) {
return (int) getSourceMessageCountLong(name);
}

public long getSourceMessageCountLong(String name) {
if (sourcesByName.containsKey(name)) {
return sourcesByName.get(name).getMessageCount();
return sourcesByName.get(name).getMessageCountLong();
}
logger.debug("No source found for (" + name + ")");
return -1;
}

public int getChannelReceiveCount(String name) {
return (int) getChannelReceiveCountLong(name);
}

public long getChannelReceiveCountLong(String name) {
if (channelsByName.containsKey(name)) {
if (channelsByName.get(name) instanceof PollableChannelMetrics) {
return ((PollableChannelMetrics) channelsByName.get(name)).getReceiveCount();
return ((PollableChannelMetrics) channelsByName.get(name)).getReceiveCountLong();
}
}
logger.debug("No channel found for (" + name + ")");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 the original author or authors.
* Copyright 2002-2014 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.
Expand All @@ -24,7 +24,7 @@
/**
* A {@link MessageHandlerMetrics} that exposes in addition the {@link Lifecycle} interface. The lifecycle methods can
* be used to stop and start polling endpoints, for instance, in a live system.
*
*
* @author Dave Syer
* @since 2.0
*/
Expand All @@ -41,64 +41,92 @@ public LifecycleMessageHandlerMetrics(Lifecycle lifecycle, MessageHandlerMetrics
this.delegate = delegate;
}


@Override
@ManagedAttribute
public boolean isRunning() {
return this.lifecycle.isRunning();
}

@Override
@ManagedOperation
public void start() {
this.lifecycle.start();
}

@Override
@ManagedOperation
public void stop() {
this.lifecycle.stop();
}

@Override
public void reset() {
this.delegate.reset();
}

@Override
public int getErrorCount() {
return this.delegate.getErrorCount();
}

@Override
public int getHandleCount() {
return this.delegate.getHandleCount();
}

@Override
public double getMaxDuration() {
return this.delegate.getMaxDuration();
}

@Override
public double getMeanDuration() {
return this.delegate.getMeanDuration();
}

@Override
public double getMinDuration() {
return this.delegate.getMinDuration();
}

@Override
public double getStandardDeviationDuration() {
return this.delegate.getStandardDeviationDuration();
}

@Override
public Statistics getDuration() {
return this.delegate.getDuration();
}

@Override
public String getName() {
return this.delegate.getName();
}

@Override
public String getSource() {
return this.delegate.getSource();
}

@Override
public int getActiveCount() {
return this.delegate.getActiveCount();
}

@Override
public long getHandleCountLong() {
return this.delegate.getHandleCountLong();
}

@Override
public long getErrorCountLong() {
return this.delegate.getErrorCountLong();
}

@Override
public long getActiveCountLong() {
return this.delegate.getActiveCountLong();
}

}
Loading

0 comments on commit 59c7c0e

Please sign in to comment.