Skip to content
This repository was archived by the owner on Jul 1, 2022. It is now read-only.

Commit 7839d9f

Browse files
felixbarnyvprithvi
authored andcommitted
Java 6 compatibility (#132)
jaeger-crossdock still requires Java 7 because it calls InetAddress#getLoopbackAddress() Add animal sniffer plugin (closes #129)
1 parent 1b13636 commit 7839d9f

File tree

33 files changed

+321
-104
lines changed

33 files changed

+321
-104
lines changed

build.gradle

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ plugins {
55
id 'com.github.sherter.google-java-format' version '0.3.2'
66
id "com.github.johnrengelman.shadow" version "1.2.3"
77
id "net.ltgt.errorprone" version "0.0.9"
8+
id 'ru.vyarus.animalsniffer' version '1.2.0'
89
}
910

1011

@@ -31,24 +32,32 @@ allprojects {
3132
mavenCentral()
3233
}
3334

34-
repositories {
35-
mavenCentral()
36-
}
37-
3835
task wrapper(type: Wrapper) {
3936
gradleVersion = '3.1.2' //version required
4037
}
4138
}
4239

4340

4441
subprojects {
42+
apply plugin: 'ru.vyarus.animalsniffer'
4543
apply plugin: 'com.github.hierynomus.license'
4644
apply plugin: 'java'
4745
apply plugin: 'maven'
4846
apply plugin: 'signing'
4947

50-
sourceCompatibility = 1.7
51-
targetCompatibility = 1.7
48+
compileJava {
49+
sourceCompatibility = 1.6
50+
targetCompatibility = 1.6
51+
}
52+
53+
compileTestJava {
54+
sourceCompatibility = 1.7
55+
targetCompatibility = 1.7
56+
}
57+
58+
animalsniffer {
59+
sourceSets = [sourceSets.main]
60+
}
5261

5362
[compileJava, compileTestJava, javadoc]*.options*.encoding = 'UTF-8'
5463

@@ -91,6 +100,7 @@ subprojects {
91100

92101
dependencies {
93102
compileOnly 'org.projectlombok:lombok:1.16.12'
103+
compileOnly 'org.codehaus.mojo:animal-sniffer-annotations:1.15'
94104
}
95105

96106
}

jaeger-apachehttpclient/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ dependencies {
1010
testCompile group: 'org.mock-server', name: 'mockserver-netty', version: '3.10.4'
1111
testCompile group: 'junit', name: 'junit', version: junitVersion
1212
testCompile group: 'org.mockito', name: 'mockito-core', version: mockitoVersion
13+
14+
signature 'org.codehaus.mojo.signature:java16:1.1@signature'
1315
}
1416

1517
sourceSets {

jaeger-context/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ dependencies {
66
// Testing Frameworks
77
testCompile group: 'junit', name: 'junit', version: junitVersion
88
testCompile group: 'org.mockito', name: 'mockito-core', version: mockitoVersion
9+
10+
signature 'org.codehaus.mojo.signature:java16:1.1@signature'
911
}
1012

1113
sourceSets {

jaeger-context/src/main/java/com/uber/jaeger/context/TracedExecutorService.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedE
6666

6767
@Override
6868
public <T> Future<T> submit(java.util.concurrent.Callable<T> task) {
69-
return delegate.submit(new Callable<>(task, traceContext));
69+
return delegate.submit(new Callable<T>(task, traceContext));
7070
}
7171

7272
@Override
@@ -113,9 +113,9 @@ public void execute(final java.lang.Runnable command) {
113113
private <T> Collection<? extends java.util.concurrent.Callable<T>> wrapJaegerCallableCollection(
114114
Collection<? extends java.util.concurrent.Callable<T>> originalCollection) {
115115
Collection<java.util.concurrent.Callable<T>> collection =
116-
new ArrayList<>(originalCollection.size());
116+
new ArrayList<java.util.concurrent.Callable<T>>(originalCollection.size());
117117
for (java.util.concurrent.Callable<T> c : originalCollection) {
118-
collection.add(new Callable<>(c, traceContext));
118+
collection.add(new Callable<T>(c, traceContext));
119119
}
120120
return collection;
121121
}

jaeger-core/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ dependencies {
1313
testCompile group: 'junit', name: 'junit', version: junitVersion
1414
testCompile group: 'org.mockito', name: 'mockito-core', version: mockitoVersion
1515
testCompile group: 'com.tngtech.java', name: 'junit-dataprovider', version: junitDataProviderVersion
16+
17+
signature 'org.codehaus.mojo.signature:java16:1.1@signature'
1618
}
1719

1820
sourceSets {

jaeger-core/src/main/java/com/uber/jaeger/Span.java

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,15 @@
2222
package com.uber.jaeger;
2323

2424
import com.twitter.zipkin.thriftjava.Endpoint;
25-
import io.opentracing.tag.Tags;
2625

2726
import java.util.ArrayList;
2827
import java.util.Collections;
2928
import java.util.HashMap;
3029
import java.util.List;
3130
import java.util.Map;
3231

32+
import io.opentracing.tag.Tags;
33+
3334
public class Span implements io.opentracing.Span {
3435
private final Tracer tracer;
3536
private final long startTimeMicroseconds;
@@ -59,7 +60,7 @@ public class Span implements io.opentracing.Span {
5960
this.startTimeMicroseconds = startTimeMicroseconds;
6061
this.startTimeNanoTicks = startTimeNanoTicks;
6162
this.computeDurationViaNanoTicks = computeDurationViaNanoTicks;
62-
this.tags = new HashMap<>();
63+
this.tags = new HashMap<String, Object>();
6364

6465
for (Map.Entry<String, Object> tag : tags.entrySet()) {
6566
setTagAsObject(tag.getKey(), tag.getValue());
@@ -205,6 +206,7 @@ public synchronized Span setTag(String key, Number value) {
205206

206207
/**
207208
* Sets various fields on the {@link Span} when certain {@link Tags} are encountered
209+
*
208210
* @return true iff a special tag is handled
209211
*/
210212
private boolean handleSpecialTag(String key, Object value) {
@@ -245,23 +247,23 @@ private boolean handleSpecialTag(String key, Object value) {
245247
* See {@link #handleSpecialTag(String, Object)}
246248
*/
247249
private Span setTagAsObject(String key, Object value) {
248-
if (key.equals(Tags.SAMPLING_PRIORITY.getKey()) && (value instanceof Number)) {
249-
int priority = ((Number) value).intValue();
250-
byte newFlags;
251-
if (priority > 0) {
252-
newFlags = (byte) (context.getFlags() | SpanContext.flagSampled | SpanContext.flagDebug);
253-
} else {
254-
newFlags = (byte) (context.getFlags() & (~SpanContext.flagSampled));
255-
}
256-
257-
context = context.withFlags(newFlags);
250+
if (key.equals(Tags.SAMPLING_PRIORITY.getKey()) && (value instanceof Number)) {
251+
int priority = ((Number) value).intValue();
252+
byte newFlags;
253+
if (priority > 0) {
254+
newFlags = (byte) (context.getFlags() | SpanContext.flagSampled | SpanContext.flagDebug);
255+
} else {
256+
newFlags = (byte) (context.getFlags() & (~SpanContext.flagSampled));
258257
}
259258

260-
if (context.isSampled()) {
261-
if (!handleSpecialTag(key, value)) {
262-
tags.put(key, value);
263-
}
259+
context = context.withFlags(newFlags);
260+
}
261+
262+
if (context.isSampled()) {
263+
if (!handleSpecialTag(key, value)) {
264+
tags.put(key, value);
264265
}
266+
}
265267

266268
return this;
267269
}

jaeger-core/src/main/java/com/uber/jaeger/SpanContext.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public static SpanContext contextFromString(String value)
132132
}
133133

134134
public SpanContext withBaggageItem(String key, String val) {
135-
Map<String, String> newBaggage = new HashMap<>(this.baggage);
135+
Map<String, String> newBaggage = new HashMap<String, String>(this.baggage);
136136
newBaggage.put(key, val);
137137
return new SpanContext(traceID, spanID, parentID, flags, newBaggage, debugID);
138138
}

jaeger-core/src/main/java/com/uber/jaeger/Tracer.java

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,6 @@
3535
import com.uber.jaeger.utils.Clock;
3636
import com.uber.jaeger.utils.SystemClock;
3737
import com.uber.jaeger.utils.Utils;
38-
import io.opentracing.References;
39-
import io.opentracing.propagation.Format;
40-
import io.opentracing.tag.Tags;
4138

4239
import java.io.InputStream;
4340
import java.net.Inet4Address;
@@ -46,8 +43,11 @@
4643
import java.util.Collections;
4744
import java.util.HashMap;
4845
import java.util.Map;
49-
import java.util.Objects;
5046
import java.util.Properties;
47+
48+
import io.opentracing.References;
49+
import io.opentracing.propagation.Format;
50+
import io.opentracing.tag.Tags;
5151
import lombok.ToString;
5252
import lombok.extern.slf4j.Slf4j;
5353

@@ -89,7 +89,7 @@ private Tracer(
8989

9090
this.version = loadVersion();
9191

92-
Map<String, Object> tags = new HashMap<>();
92+
Map<String, Object> tags = new HashMap<String, Object>();
9393
tags.put("jaeger.version", this.version);
9494
String hostname = getHostName();
9595
if (hostname != null) {
@@ -164,7 +164,7 @@ class SpanBuilder implements io.opentracing.Tracer.SpanBuilder {
164164
private String operationName = null;
165165
private long startTimeMicroseconds;
166166
private SpanContext parent;
167-
private final Map<String, Object> tags = new HashMap<>();
167+
private final Map<String, Object> tags = new HashMap<String, Object>();
168168

169169
SpanBuilder(String operationName) {
170170
this.operationName = operationName;
@@ -192,8 +192,8 @@ public io.opentracing.Tracer.SpanBuilder asChildOf(io.opentracing.Span parent) {
192192
public io.opentracing.Tracer.SpanBuilder addReference(
193193
String referenceType, io.opentracing.SpanContext referencedContext) {
194194
if (parent == null
195-
&& (Objects.equals(referenceType, References.CHILD_OF)
196-
|| Objects.equals(referenceType, References.FOLLOWS_FROM))) {
195+
&& (Utils.equals(referenceType, References.CHILD_OF)
196+
|| Utils.equals(referenceType, References.FOLLOWS_FROM))) {
197197
this.parent = (SpanContext) referencedContext;
198198
}
199199
return this;
@@ -376,8 +376,8 @@ public Tracer build() {
376376
}
377377

378378
private static class PropagationRegistry {
379-
private final Map<Format<?>, Injector<?>> injectors = new HashMap<>();
380-
private final Map<Format<?>, Extractor<?>> extractors = new HashMap<>();
379+
private final Map<Format<?>, Injector<?>> injectors = new HashMap<Format<?>, Injector<?>>();
380+
private final Map<Format<?>, Extractor<?>> extractors = new HashMap<Format<?>, Extractor<?>>();
381381

382382
@SuppressWarnings("unchecked")
383383
<T> Injector<T> getInjector(Format<T> format) {
@@ -401,10 +401,13 @@ public <T> void register(Format<T> format, Extractor<T> extractor) {
401401
private static String loadVersion() {
402402
String version;
403403
try {
404-
try (InputStream is = Tracer.class.getResourceAsStream("jaeger.properties")) {
404+
InputStream is = Tracer.class.getResourceAsStream("jaeger.properties");
405+
try {
405406
Properties prop = new Properties();
406407
prop.load(is);
407408
version = prop.getProperty("jaeger.version");
409+
} finally {
410+
is.close();
408411
}
409412
} catch (Exception e) {
410413
throw new RuntimeException("Cannot read jaeger.properties", e);

jaeger-core/src/main/java/com/uber/jaeger/metrics/InMemoryStatsReporter.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@
2525
import java.util.Map;
2626

2727
public class InMemoryStatsReporter implements StatsReporter {
28-
public Map<String, Long> counters = new HashMap<>();
29-
public Map<String, Long> gauges = new HashMap<>();
30-
public Map<String, Long> timers = new HashMap<>();
28+
public Map<String, Long> counters = new HashMap<String, Long>();
29+
public Map<String, Long> gauges = new HashMap<String, Long>();
30+
public Map<String, Long> timers = new HashMap<String, Long>();
3131

3232
void reset() {
33-
counters = new HashMap<>();
34-
gauges = new HashMap<>();
35-
timers = new HashMap<>();
33+
counters = new HashMap<String, Long>();
34+
gauges = new HashMap<String, Long>();
35+
timers = new HashMap<String, Long>();
3636
}
3737

3838
@Override

jaeger-core/src/main/java/com/uber/jaeger/metrics/Metrics.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public Metrics(StatsFactory factory) {
4040
}
4141

4242
String metricName = "jaeger.";
43-
HashMap<String, String> tags = new HashMap<>();
43+
HashMap<String, String> tags = new HashMap<String, String>();
4444

4545
Annotation[] annotations = field.getAnnotations();
4646
for (Annotation anno : annotations) {
@@ -66,7 +66,7 @@ public Metrics(StatsFactory factory) {
6666
throw new RuntimeException(
6767
"A field type that was neither Counter, Gauge, or Timer was parsed in reflection.");
6868
}
69-
} catch (ReflectiveOperationException e) {
69+
} catch (Exception e) {
7070
// This exception should only happen at the start of a program if the code below is not set up correctly.
7171
// As long as tests are run this code should never be thrown in production.
7272
throw new RuntimeException(
@@ -84,7 +84,7 @@ public static String addTagsToMetricName(String name, Map<String, String> tags)
8484
StringBuilder sb = new StringBuilder();
8585
sb.append(name);
8686

87-
SortedSet<String> sortedKeys = new TreeSet<>(tags.keySet());
87+
SortedSet<String> sortedKeys = new TreeSet<String>(tags.keySet());
8888
for (String key : sortedKeys) {
8989
sb.append(".");
9090
sb.append(key);

0 commit comments

Comments
 (0)