Skip to content

Commit

Permalink
Various cleanups, mostly related to checkstyle.
Browse files Browse the repository at this point in the history
Build changes:
 * Made the build task the default from the main directory.
 * Minor formatting changes for clarity.
 * Made findbugs work only on the main source set for the moment.
 * Enabled showWarnings for checkstyle for metrics3 so that people won't ignore it.

Checkstyle-related changes:
 * Made the project conform to the checkstyle format defined.
 * Modified the defined format to add warning suppression with comments.
 * Modified the defined format to remove the FinalClass check, since
it wasn't relevant for this project.

Other changes:
 * Project was double-reporting all IOExceptions at different warning levels. This has been corrected.
 * Silenced warnings when gauges aren't numbers. This fits with the standard by the Graphite reporter.
 * Added supported for BigInteger and BigDecimal.
 * Made the tests more permissive (they were testing that p95 was reported before p99, and really statsd
doesn't care at that level of detail). Now they are less implementation-specific.
 * Named the logger consistently between files.
 * Added a basic set of JSR305 annotations.
  • Loading branch information
David H. Clements committed Jun 15, 2013
1 parent 404d718 commit 8dbbe33
Show file tree
Hide file tree
Showing 8 changed files with 167 additions and 153 deletions.
17 changes: 9 additions & 8 deletions build.gradle
Expand Up @@ -7,6 +7,8 @@ buildscript {
}
}

defaultTasks 'build'

subprojects {

apply plugin: 'java'
Expand Down Expand Up @@ -48,21 +50,21 @@ subprojects {
}

dependencies {
compile ([
compile (
'org.slf4j:slf4j-api:1.7.5',
])
)

optional ([
optional (
'com.google.code.findbugs:jsr305:2.0.1',
'com.google.code.findbugs:annotations:2.0.1',
])
)

testCompile ([
testCompile (
'junit:junit:4.11',
'org.mockito:mockito-all:1.9.5',
'org.slf4j:slf4j-jdk14:1.7.5',
'org.easytesting:fest-assert-core:2.0M10',
])
)
}

tasks.withType(Compile) {
Expand All @@ -78,6 +80,7 @@ subprojects {

findbugs {
toolVersion = '2.0.1'
sourceSets = [sourceSets.main]
ignoreFailures = true
}

Expand All @@ -89,8 +92,6 @@ subprojects {
}
}

defaultTasks 'build'

jacocoTestReport.dependsOn(test)
build.dependsOn javadoc
build.dependsOn jacocoTestReport
Expand Down
6 changes: 5 additions & 1 deletion config/checkstyle/checkstyle.xml
Expand Up @@ -69,7 +69,6 @@
</module>
<module name="SimplifyBooleanExpression"/>
<module name="SimplifyBooleanReturn"/>
<module name="FinalClass"/>
<module name="HideUtilityClassConstructor"/>
<module name="InterfaceIsType"/>
<module name="VisibilityModifier"/>
Expand Down Expand Up @@ -102,4 +101,9 @@
<metadata name="net.sf.eclipsecs.core.lastEnabledSeverity" value="inherit"/>
</module>
<module name="SuppressWithNearbyCommentFilter"/>
<module name="SuppressionCommentFilter">
<property name="offCommentFormat" value="CHECKSTYLE.OFF\: ([\w\|]+)"/>
<property name="onCommentFormat" value="CHECKSTYLE.ON\: ([\w\|]+)"/>
<property name="checkFormat" value="$1"/>
</module>
</module>
8 changes: 7 additions & 1 deletion metrics3-statsd/build.gradle
@@ -1,5 +1,11 @@
version = '3.0.0-SNAPSHOT'

dependencies {
provided 'com.codahale.metrics:metrics-core:3.0.0'
provided (
'com.codahale.metrics:metrics-core:3.0.0'
)
}

checkstyle {
showViolations = true
}
Expand Up @@ -10,7 +10,8 @@ public DatagramSocket createSocket() throws SocketException {
return new DatagramSocket();
}

public DatagramPacket createPacket(byte[] bytes, int length, InetSocketAddress address) throws SocketException {
public DatagramPacket createPacket(final byte[] bytes, final int length, final InetSocketAddress address)
throws SocketException {
return new DatagramPacket(bytes, length, address);
}
}
18 changes: 8 additions & 10 deletions metrics3-statsd/src/main/java/com/readytalk/metrics/StatsD.java
@@ -1,5 +1,6 @@
package com.readytalk.metrics;

import javax.annotation.concurrent.NotThreadSafe;
import java.io.Closeable;
import java.io.IOException;
import java.net.DatagramSocket;
Expand All @@ -13,6 +14,7 @@
/**
* A client to a StatsD server.
*/
@NotThreadSafe
public class StatsD implements Closeable {

private static final Logger LOG = LoggerFactory.getLogger(StatsD.class);
Expand All @@ -33,7 +35,7 @@ public class StatsD implements Closeable {
*
* @param address the address of the StatsD server
*/
public StatsD(InetSocketAddress address) {
public StatsD(final InetSocketAddress address) {
this(address, new DatagramSocketFactory());
}

Expand All @@ -43,7 +45,7 @@ public StatsD(InetSocketAddress address) {
* @param address the address of the Carbon server
* @param socketFactory the socket factory
*/
public StatsD(InetSocketAddress address, DatagramSocketFactory socketFactory) {
public StatsD(final InetSocketAddress address, final DatagramSocketFactory socketFactory) {
this.address = address;
this.socketFactory = socketFactory;
}
Expand All @@ -54,7 +56,7 @@ public StatsD(InetSocketAddress address, DatagramSocketFactory socketFactory) {
* @throws IllegalStateException if the client is already connected
* @throws IOException if there is an error connecting
*/
public void connect() throws IllegalStateException, IOException {
public void connect() throws IOException {
if (socket != null) {
throw new IllegalStateException("Already connected");
}
Expand All @@ -63,14 +65,12 @@ public void connect() throws IllegalStateException, IOException {
}

/**
* Sends the given measurement to the server.
* Sends the given measurement to the server. Logs exceptions.
*
* @param name the name of the metric
* @param value the value of the metric
*
* @throws IOException if there was an error sending the metric
*/
public void send(String name, String value) throws IOException {
public void send(final String name, final String value) {
try {
String formatted = String.format("%s:%s|g", sanitize(name), sanitize(value));
byte[] bytes = formatted.getBytes(UTF_8);
Expand All @@ -84,8 +84,6 @@ public void send(String name, String value) throws IOException {
} else {
LOG.debug("unable to send packet to statsd at '{}:{}'", address.getHostName(), address.getPort());
}

throw e;
}
}

Expand All @@ -106,7 +104,7 @@ public void close() throws IOException {
this.socket = null;
}

protected String sanitize(String s) {
private String sanitize(final String s) {
return WHITESPACE.matcher(s).replaceAll("-");
}
}

0 comments on commit 8dbbe33

Please sign in to comment.