Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@ sudo: required

language: java

# This project is aimed to be JRE7-compatible. However, there
# are issues testing against oraclejdk7 in Travis:
# https://github.com/travis-ci/travis-ci/issues/7884
# This project is JRE8-compatible.
jdk:
- openjdk7
- openjdk8
- oraclejdk8

Expand Down
2 changes: 1 addition & 1 deletion DEVELOPER.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ This document summarizes information relevant to Java tally contributors.

### Prerequisites
In order to build this project, you must have:
- JDK-7 or later
- JDK-8 or later
- Apache Thrift 0.9.x -- only if you plan to make changes to Thrift files and recompile (regenerate) source files

### Building and testing
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ allprojects {
apply plugin: 'signing'
apply plugin: 'jacoco'

sourceCompatibility = 1.7
targetCompatibility = 1.7
sourceCompatibility = 1.8
targetCompatibility = 1.8

repositories {
mavenCentral()
Expand Down
34 changes: 17 additions & 17 deletions core/src/main/java/com/uber/m3/tally/AbstractBuckets.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@
/**
* Abstract {@link Buckets} implementation for common functionality.
*/
public abstract class AbstractBuckets<T> implements Buckets<T> {
protected List<T> buckets;
public abstract class AbstractBuckets<E> implements Buckets<E> {
protected List<E> buckets;

AbstractBuckets(T[] buckets) {
AbstractBuckets(E[] buckets) {
if (buckets == null) {
this.buckets = new ArrayList<>();
} else {
Expand Down Expand Up @@ -74,7 +74,7 @@ public boolean contains(Object o) {
}

@Override
public Iterator<T> iterator() {
public Iterator<E> iterator() {
return buckets.iterator();
}

Expand All @@ -84,7 +84,7 @@ public Object[] toArray() {
}

@Override
public boolean add(T o) {
public boolean add(E o) {
return buckets.add(o);
}

Expand All @@ -94,12 +94,12 @@ public boolean remove(Object o) {
}

@Override
public boolean addAll(Collection c) {
public boolean addAll(Collection<? extends E> c) {
return buckets.addAll(c);
}

@Override
public boolean addAll(int index, Collection c) {
public boolean addAll(int index, Collection<? extends E> c) {
return buckets.addAll(index, c);
}

Expand All @@ -109,22 +109,22 @@ public void clear() {
}

@Override
public T get(int index) {
public E get(int index) {
return buckets.get(index);
}

@Override
public T set(int index, T element) {
public E set(int index, E element) {
return buckets.set(index, element);
}

@Override
public void add(int index, T element) {
public void add(int index, E element) {
buckets.add(index, element);
}

@Override
public T remove(int index) {
public E remove(int index) {
return buckets.remove(index);
}

Expand All @@ -139,27 +139,27 @@ public int lastIndexOf(Object o) {
}

@Override
public ListIterator<T> listIterator() {
public ListIterator<E> listIterator() {
return buckets.listIterator();
}

@Override
public ListIterator<T> listIterator(int index) {
public ListIterator<E> listIterator(int index) {
return buckets.listIterator(index);
}

@Override
public List<T> subList(int fromIndex, int toIndex) {
public List<E> subList(int fromIndex, int toIndex) {
return buckets.subList(fromIndex, toIndex);
}

@Override
public boolean retainAll(Collection c) {
public boolean retainAll(Collection<?> c) {
return buckets.retainAll(c);
}

@Override
public boolean removeAll(Collection c) {
public boolean removeAll(Collection<?> c) {
return buckets.removeAll(c);
}

Expand All @@ -169,7 +169,7 @@ public boolean containsAll(Collection c) {
}

@Override
public Object[] toArray(Object[] a) {
public <T> T[] toArray(T[] a) {
return buckets.toArray(a);
}

Expand Down
55 changes: 55 additions & 0 deletions core/src/main/java/com/uber/m3/tally/BucketPair.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,66 @@

import com.uber.m3.util.Duration;

import java.util.Collections;

/**
* A BucketPair describes the lower and upper bounds
* for a derived bucket from a buckets set.
*/
public interface BucketPair {

static BucketPair[] create(Buckets buckets) {
if (buckets == null || buckets.size() < 1) {
return new BucketPair[]{
new BucketPairImpl(
-Double.MAX_VALUE,
Double.MAX_VALUE,
Duration.MIN_VALUE,
Duration.MAX_VALUE
)
};
}

Collections.sort(buckets);

Double[] asValueBuckets = buckets.asValues();
Duration[] asDurationBuckets = buckets.asDurations();
BucketPair[] pairs = new BucketPair[buckets.size() + 1];

// Add lower bound
pairs[0] = new BucketPairImpl(
-Double.MAX_VALUE,
asValueBuckets[0],
Duration.MIN_VALUE,
asDurationBuckets[0]
);

double prevValueBucket = asValueBuckets[0];
Duration prevDurationBucket = asDurationBuckets[0];

for (int i = 1; i < buckets.size(); i++) {
pairs[i] = new BucketPairImpl(
prevValueBucket,
asValueBuckets[i],
prevDurationBucket,
asDurationBuckets[i]
);

prevValueBucket = asValueBuckets[i];
prevDurationBucket = asDurationBuckets[i];
}

// Add upper bound
pairs[pairs.length - 1] = new BucketPairImpl(
prevValueBucket,
Double.MAX_VALUE,
prevDurationBucket,
Duration.MAX_VALUE
);

return pairs;
}

/**
* Returns the lower bound as a {@code double}
* @return the lower bound as a {@code double}
Expand Down
58 changes: 2 additions & 56 deletions core/src/main/java/com/uber/m3/tally/BucketPairImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,16 @@

import com.uber.m3.util.Duration;

import java.util.Collections;

/**
* Default implementation of a {@link BucketPair}
*/
public class BucketPairImpl implements BucketPair {
class BucketPairImpl implements BucketPair {
private double lowerBoundValue;
private double upperBoundValue;
private Duration lowerBoundDuration;
private Duration upperBoundDuration;

public BucketPairImpl(
BucketPairImpl(
double lowerBoundValue,
double upperBoundValue,
Duration lowerBoundDuration,
Expand All @@ -45,58 +43,6 @@ public BucketPairImpl(
this.upperBoundDuration = upperBoundDuration;
}

public static BucketPair[] bucketPairs(Buckets buckets) {
if (buckets == null || buckets.size() < 1) {
return new BucketPair[]{
new BucketPairImpl(
-Double.MAX_VALUE,
Double.MAX_VALUE,
Duration.MIN_VALUE,
Duration.MAX_VALUE
)
};
}

Collections.sort(buckets);

Double[] asValueBuckets = buckets.asValues();
Duration[] asDurationBuckets = buckets.asDurations();
BucketPair[] pairs = new BucketPair[buckets.size() + 1];

// Add lower bound
pairs[0] = new BucketPairImpl(
-Double.MAX_VALUE,
asValueBuckets[0],
Duration.MIN_VALUE,
asDurationBuckets[0]
);

double prevValueBucket = asValueBuckets[0];
Duration prevDurationBucket = asDurationBuckets[0];

for (int i = 1; i < buckets.size(); i++) {
pairs[i] = new BucketPairImpl(
prevValueBucket,
asValueBuckets[i],
prevDurationBucket,
asDurationBuckets[i]
);

prevValueBucket = asValueBuckets[i];
prevDurationBucket = asDurationBuckets[i];
}

// Add upper bound
pairs[pairs.length - 1] = new BucketPairImpl(
prevValueBucket,
Double.MAX_VALUE,
prevDurationBucket,
Duration.MAX_VALUE
);

return pairs;
}

@Override
public double lowerBoundValue() {
return lowerBoundValue;
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/com/uber/m3/tally/CapableOf.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ public boolean equals(Object other) {
public int hashCode() {
int code = 0;

code = 31 * code + new Boolean(reporting).hashCode();
code = 31 * code + new Boolean(tagging).hashCode();
code = 31 * code + Boolean.valueOf(reporting).hashCode();
code = 31 * code + Boolean.valueOf(tagging).hashCode();

return code;
}
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/com/uber/m3/tally/HistogramImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class HistogramImpl implements Histogram, StopwatchRecorder {
type = Type.VALUE;
}

BucketPair[] pairs = BucketPairImpl.bucketPairs(buckets);
BucketPair[] pairs = BucketPair.create(buckets);
int pairsLen = pairs.length;

this.name = name;
Expand Down Expand Up @@ -174,7 +174,7 @@ public void recordStopwatch(long stopwatchStart) {
recordDuration(Duration.between(stopwatchStart, System.nanoTime()));
}

class HistogramBucket {
static class HistogramBucket {
CounterImpl samples;
double valueLowerBound;
double valueUpperBound;
Expand Down
38 changes: 38 additions & 0 deletions core/src/main/java/com/uber/m3/tally/NoopScope.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright (c) 2017 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

package com.uber.m3.tally;

import com.uber.m3.util.Duration;

/**
* NoopScope is scope that does not report stats.
*/
public class NoopScope {

/**
* Creates a new NoopScope.
*/
public static Scope create() {
return new RootScopeBuilder()
.reporter(new NullStatsReporter())
.reportEvery(Duration.ZERO);
}
}
Loading