Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved abstractions + better object construction #96

Merged
merged 12 commits into from
Jan 29, 2020
8 changes: 6 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
dist: trusty
language: java
jdk:
- openjdk7
- oraclejdk8
- oraclejdk9
- oraclejdk11

install: mvn install -Dgpg.skip
jobs:
include:
- jdk: openjdk7
env: EXTRA_MVN="-Dcheckstyle.version=2.15 -Dcheckstyle.skip"

install: mvn clean install -Dgpg.skip $EXTRA_MVN
51 changes: 51 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.6</java.version>
<!-- Note: using project checkstyle with AOSP style
find the default google java checkstyle config here -
<checkstyle.config.location>google_checks.xml</checkstyle.config.location>
-->
<checkstyle.config.location>style.xml</checkstyle.config.location>
<checkstyle.consoleOutput>true</checkstyle.consoleOutput>
<jdk.module.illegalAccess>deny</jdk.module.illegalAccess>
<checkstyle.version>3.1.0</checkstyle.version>
</properties>

<licenses>
Expand Down Expand Up @@ -191,7 +199,50 @@
<autoReleaseAfterClose>true</autoReleaseAfterClose>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>${checkstyle.version}</version>
<executions>
<execution>
<id>checkstyle</id>
<phase>verify</phase>
<configuration>
<encoding>UTF-8</encoding>
<consoleOutput>true</consoleOutput>
<failsOnError>true</failsOnError>
<failOnViolation>true</failOnViolation>
<violationSeverity>warning</violationSeverity>
<linkXRef>false</linkXRef>
</configuration>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>${checkstyle.version}</version>
<reportSets>
<reportSet>
<reports>
<report>checkstyle</report>
</reports>
</reportSet>
</reportSets>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jxr-plugin</artifactId>
<version>3.0.0</version>
</plugin>
</plugins>
</reporting>
</project>
4 changes: 2 additions & 2 deletions src/main/java/com/timgroup/statsd/BufferPool.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import java.io.IOException;
import java.nio.ByteBuffer;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;

public class BufferPool {
private final BlockingQueue<ByteBuffer> pool;
Expand All @@ -15,7 +15,7 @@ public class BufferPool {

size = poolSize;
pool = new ArrayBlockingQueue<ByteBuffer>(poolSize);
for (int i=0; i<size ; i++) {
for (int i = 0; i < size ; i++) {
if (direct) {
pool.put(ByteBuffer.allocateDirect(bufferSize));
} else {
Expand Down
29 changes: 27 additions & 2 deletions src/main/java/com/timgroup/statsd/Event.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import java.util.Date;

/**
* An event to send
* An event to send.
* @see <a href="http://docs.datadoghq.com/guides/dogstatsd/#events">http://docs.datadoghq.com/guides/dogstatsd/#events</a>
*/
public class Event {
Expand All @@ -25,6 +25,7 @@ public String getText() {
}

/**
* Get number of milliseconds since epoch started.
* @return -1 if not set
*/
public long getMillisSinceEpoch() {
Expand Down Expand Up @@ -65,11 +66,17 @@ public enum AlertType {
ERROR, WARNING, INFO, SUCCESS
}

@SuppressWarnings({"AccessingNonPublicFieldOfAnotherObject", "PrivateMemberAccessBetweenOuterAndInnerClass", "ParameterHidesMemberVariable"})
@SuppressWarnings({"AccessingNonPublicFieldOfAnotherObject",
"PrivateMemberAccessBetweenOuterAndInnerClass", "ParameterHidesMemberVariable"})
public static class Builder {
private final Event event = new Event();

private Builder() {}

/**
* Build factory method for the event.
* @return Event built following specified options.
*/
public Event build() {
if ((event.title == null) || event.title.isEmpty()) {
throw new IllegalStateException("event title must be set");
Expand All @@ -81,62 +88,76 @@ public Event build() {
}

/**
* Title for the event.
* @param title
* Event title ; mandatory
* @return Builder object being used.
*/
public Builder withTitle(final String title) {
event.title = title;
return this;
}

/**
* Text for the event.
* @param text
* Event text ; supports line breaks ; mandatory
* @return Builder object being used.
*/
public Builder withText(final String text) {
event.text = text;
return this;
}

/**
* Date for the event.
* @param date
* Assign a timestamp to the event ; Default: none (Default is the current Unix epoch timestamp when not sent)
* @return Builder object being used.
*/
public Builder withDate(final Date date) {
event.millisSinceEpoch = date.getTime();
return this;
}

/**
* Date for the event.
* @param millisSinceEpoch
* Assign a timestamp to the event ; Default: none (Default is the current Unix epoch timestamp when not sent)
* @return Builder object being used.
*/
public Builder withDate(final long millisSinceEpoch) {
event.millisSinceEpoch = millisSinceEpoch;
return this;
}

/**
* Source hostname for the event.
* @param hostname
* Assign a hostname to the event ; Default: none
* @return Builder object being used.
*/
public Builder withHostname(final String hostname) {
event.hostname = hostname;
return this;
}

/**
* Aggregation key for the event.
* @param aggregationKey
* Assign an aggregation key to the event, to group it with some others ; Default: none
* @return Builder object being used.
*/
public Builder withAggregationKey(final String aggregationKey) {
event.aggregationKey = aggregationKey;
return this;
}

/**
* Priority for the event.
* @param priority
* Can be "normal" or "low" ; Default: "normal"
* @return Builder object being used.
*/
public Builder withPriority(final Priority priority) {
//noinspection StringToUpperCaseOrToLowerCaseWithoutLocale
Expand All @@ -145,17 +166,21 @@ public Builder withPriority(final Priority priority) {
}

/**
* Source Type name for the event.
* @param sourceTypeName
* Assign a source type to the event ; Default: none
* @return Builder object being used.
*/
public Builder withSourceTypeName(final String sourceTypeName) {
event.sourceTypeName = sourceTypeName;
return this;
}

/**
* Alert type for the event.
* @param alertType
* Can be "error", "warning", "info" or "success" ; Default: "info"
* @return Builder object being used.
*/
public Builder withAlertType(final AlertType alertType) {
//noinspection StringToUpperCaseOrToLowerCaseWithoutLocale
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.timgroup.statsd;

/**
* Signals that we've been passed a message that's invalid and won't be sent
* Signals that we've been passed a message that's invalid and won't be sent.
*
* @author Taylor Schilling
*/
Expand All @@ -11,7 +11,7 @@ public class InvalidMessageException extends RuntimeException {
private final String invalidMessage;

/**
* Creates an InvalidMessageException with a specified detail message and the invalid message itself
* Creates an InvalidMessageException with a specified detail message and the invalid message itself.
*
* @param detailMessage a message that details why the invalid message is considered so
* @param invalidMessage the message deemed invalid
Expand Down
59 changes: 52 additions & 7 deletions src/main/java/com/timgroup/statsd/NoOpStatsDClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,50 +8,95 @@
*
*/
public final class NoOpStatsDClient implements StatsDClient {
@Override public void stop() { }
@Override public void stop() { }

@Override public void close() { }

@Override public void count(String aspect, long delta, String... tags) { }

@Override public void count(String aspect, long delta, double sampleRate, String... tags) { }

@Override public void count(String aspect, double delta, String... tags) { }

@Override public void count(String aspect, double delta, double sampleRate, String... tags) { }

@Override public void incrementCounter(String aspect, String... tags) { }

@Override public void incrementCounter(String aspect, double sampleRate, String... tags) { }

@Override public void increment(String aspect, String... tags) { }

@Override public void increment(String aspect, double sampleRate, String...tags) { }

@Override public void decrementCounter(String aspect, String... tags) { }

@Override public void decrementCounter(String aspect, double sampleRate, String... tags) { }

@Override public void decrement(String aspect, String... tags) { }

@Override public void decrement(String aspect, double sampleRate, String... tags) { }

@Override public void recordGaugeValue(String aspect, double value, String... tags) { }

@Override public void recordGaugeValue(String aspect, double value, double sampleRate, String... tags) { }
@Override public void gauge(String aspect, double value, String... tags) { }
@Override public void gauge(String aspect, double value, double sampleRate, String... tags) { }

@Override public void recordGaugeValue(String aspect, long value, String... tags) { }

@Override public void recordGaugeValue(String aspect, long value, double sampleRate, String... tags) { }

@Override public void gauge(String aspect, double value, String... tags) { }

@Override public void gauge(String aspect, double value, double sampleRate, String... tags) { }

@Override public void gauge(String aspect, long value, String... tags) { }

@Override public void gauge(String aspect, long value, double sampleRate, String... tags) { }

@Override public void recordExecutionTime(String aspect, long timeInMs, String... tags) { }

@Override public void recordExecutionTime(String aspect, long timeInMs, double sampleRate, String... tags) { }

@Override public void time(String aspect, long value, String... tags) { }

@Override public void time(String aspect, long value, double sampleRate, String... tags) { }

@Override public void recordHistogramValue(String aspect, double value, String... tags) { }

@Override public void recordHistogramValue(String aspect, double value, double sampleRate, String... tags) { }
@Override public void histogram(String aspect, double value, String... tags) { }
@Override public void histogram(String aspect, double value, double sampleRate, String... tags) { }

@Override public void recordHistogramValue(String aspect, long value, String... tags) { }

@Override public void recordHistogramValue(String aspect, long value, double sampleRate, String... tags) { }

@Override public void histogram(String aspect, double value, String... tags) { }

@Override public void histogram(String aspect, double value, double sampleRate, String... tags) { }

@Override public void histogram(String aspect, long value, String... tags) { }

@Override public void histogram(String aspect, long value, double sampleRate, String... tags) { }

@Override public void recordDistributionValue(String aspect, double value, String... tags) { }

@Override public void recordDistributionValue(String aspect, double value, double sampleRate, String... tags) { }
@Override public void distribution(String aspect, double value, String... tags) { }
@Override public void distribution(String aspect, double value, double sampleRate, String... tags) { }

@Override public void recordDistributionValue(String aspect, long value, String... tags) { }

@Override public void recordDistributionValue(String aspect, long value, double sampleRate, String... tags) { }

@Override public void distribution(String aspect, double value, String... tags) { }

@Override public void distribution(String aspect, double value, double sampleRate, String... tags) { }

@Override public void distribution(String aspect, long value, String... tags) { }

@Override public void distribution(String aspect, long value, double sampleRate, String... tags) { }

@Override public void recordEvent(final Event event, final String... tags) { }

@Override public void recordServiceCheckRun(ServiceCheck sc) { }

@Override public void serviceCheck(ServiceCheck sc) { }

@Override public void recordSetValue(String aspect, String value, String... tags) { }
}
Loading