INT-3626: More Sonar Fixes

JIRA: https://jira.spring.io/browse/INT-3626

Remove Direct Array Usages.

With the increased use of java configuration and DSL, it
is no longer safe to directly use array arguments.

(Except in simple wrapper objects).

Avoid (or mark //NOSONAR) catch Throwable.

Remove unused field.
This commit is contained in:
Gary Russell
2015-02-11 10:34:29 -05:00
parent bc509da062
commit 632740d2cf
27 changed files with 225 additions and 102 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2009-2014 the original author or authors.
* Copyright 2009-2015 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
@@ -31,6 +31,7 @@ import org.springframework.util.StopWatch;
*
* @author Dave Syer
* @author Helena Edelson
* @author Gary Russell
* @since 2.0
*/
@ManagedResource
@@ -45,7 +46,7 @@ public class DirectChannelMetrics implements MethodInterceptor, MessageChannelMe
public static final int DEFAULT_MOVING_AVERAGE_WINDOW = 10;
private ExponentialMovingAverage sendDuration = new ExponentialMovingAverage(
private final ExponentialMovingAverage sendDuration = new ExponentialMovingAverage(
DEFAULT_MOVING_AVERAGE_WINDOW);
private final ExponentialMovingAverageRate sendErrorRate = new ExponentialMovingAverageRate(
@@ -86,6 +87,7 @@ public class DirectChannelMetrics implements MethodInterceptor, MessageChannelMe
return name;
}
@Override
public Object invoke(MethodInvocation invocation) throws Throwable {
String method = invocation.getMethod().getName();
MessageChannel channel = (MessageChannel) invocation.getThis();
@@ -125,7 +127,7 @@ public class DirectChannelMetrics implements MethodInterceptor, MessageChannelMe
}
return result;
}
catch (Throwable e) {
catch (Throwable e) {//NOSONAR - rethrown below
sendSuccessRatio.failure();
sendErrorCount.incrementAndGet();
sendErrorRate.increment();
@@ -138,6 +140,7 @@ public class DirectChannelMetrics implements MethodInterceptor, MessageChannelMe
}
}
@Override
public synchronized void reset() {
sendDuration.reset();
sendErrorRate.reset();
@@ -147,62 +150,77 @@ public class DirectChannelMetrics implements MethodInterceptor, MessageChannelMe
sendErrorCount.set(0);
}
@Override
public int getSendCount() {
return (int) sendCount.get();
}
@Override
public long getSendCountLong() {
return sendCount.get();
}
@Override
public int getSendErrorCount() {
return (int) sendErrorCount.get();
}
@Override
public long getSendErrorCountLong() {
return sendErrorCount.get();
}
@Override
public double getTimeSinceLastSend() {
return sendRate.getTimeSinceLastMeasurement();
}
@Override
public double getMeanSendRate() {
return sendRate.getMean();
}
@Override
public double getMeanErrorRate() {
return sendErrorRate.getMean();
}
@Override
public double getMeanErrorRatio() {
return 1 - sendSuccessRatio.getMean();
}
@Override
public double getMeanSendDuration() {
return sendDuration.getMean();
}
@Override
public double getMinSendDuration() {
return sendDuration.getMin();
}
@Override
public double getMaxSendDuration() {
return sendDuration.getMax();
}
@Override
public double getStandardDeviationSendDuration() {
return sendDuration.getStandardDeviation();
}
@Override
public Statistics getSendDuration() {
return sendDuration.getStatistics();
}
@Override
public Statistics getSendRate() {
return sendRate.getStatistics();
}
@Override
public Statistics getErrorRate() {
return sendErrorRate.getStatistics();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2015 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
@@ -14,6 +14,7 @@
package org.springframework.integration.monitor;
import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
@@ -210,7 +211,7 @@ public class IntegrationMBeanExporter extends MBeanExporter implements BeanPostP
public void setComponentNamePatterns(String[] componentNamePatterns) {
Assert.notEmpty(componentNamePatterns, "componentNamePatterns must not be empty");
this.componentNamePatterns = componentNamePatterns;
this.componentNamePatterns = Arrays.copyOf(componentNamePatterns, componentNamePatterns.length);
}
@Override

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2015 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.
@@ -27,6 +27,7 @@ import org.springframework.messaging.MessageChannel;
/**
* @author Dave Syer
* @author Gary Russell
* @since 2.0
*/
public class PollableChannelMetrics extends DirectChannelMetrics {
@@ -59,12 +60,13 @@ public class PollableChannelMetrics extends DirectChannelMetrics {
}
return object;
}
catch (Throwable e) {
catch (Throwable e) {//NOSONAR - rethrown below
this.receiveErrorCount.incrementAndGet();
throw e;
}
}
@Override
@ManagedOperation
public synchronized void reset() {
super.reset();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2015 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.
@@ -64,6 +64,7 @@ public class SimpleMessageHandlerMetrics implements MethodInterceptor, MessageHa
this.name = name;
}
@Override
public String getName() {
return this.name;
}
@@ -72,6 +73,7 @@ public class SimpleMessageHandlerMetrics implements MethodInterceptor, MessageHa
this.source = source;
}
@Override
public String getSource() {
return this.source;
}
@@ -80,6 +82,7 @@ public class SimpleMessageHandlerMetrics implements MethodInterceptor, MessageHa
return this.handler;
}
@Override
public Object invoke(MethodInvocation invocation) throws Throwable {
String method = invocation.getMethod().getName();
if ("handleMessage".equals(method)) {
@@ -109,7 +112,7 @@ public class SimpleMessageHandlerMetrics implements MethodInterceptor, MessageHa
timer.stop();
this.duration.append(timer.getTotalTimeMillis());
}
catch (Throwable e) {
catch (Throwable e) {//NOSONAR - rethrown below
this.errorCount.incrementAndGet();
throw e;
}
@@ -118,12 +121,14 @@ public class SimpleMessageHandlerMetrics implements MethodInterceptor, MessageHa
}
}
@Override
public synchronized void reset() {
this.duration.reset();
this.errorCount.set(0);
this.handleCount.set(0);
}
@Override
public long getHandleCountLong() {
if (logger.isTraceEnabled()) {
logger.trace("Getting Handle Count:" + this);
@@ -131,42 +136,52 @@ public class SimpleMessageHandlerMetrics implements MethodInterceptor, MessageHa
return this.handleCount.get();
}
@Override
public int getHandleCount() {
return (int) getHandleCountLong();
}
@Override
public int getErrorCount() {
return (int) this.errorCount.get();
}
@Override
public long getErrorCountLong() {
return this.errorCount.get();
}
@Override
public double getMeanDuration() {
return this.duration.getMean();
}
@Override
public double getMinDuration() {
return this.duration.getMin();
}
@Override
public double getMaxDuration() {
return this.duration.getMax();
}
@Override
public double getStandardDeviationDuration() {
return this.duration.getStandardDeviation();
}
@Override
public int getActiveCount() {
return (int) this.activeCount.get();
}
@Override
public long getActiveCountLong() {
return this.activeCount.get();
}
@Override
public Statistics getDuration() {
return this.duration.getStatistics();
}