Skip to content

Commit

Permalink
progress
Browse files Browse the repository at this point in the history
Signed-off-by: Adrian Cole <adrian@tetrate.io>
  • Loading branch information
Adrian Cole committed Dec 15, 2023
1 parent 14f8c1d commit bc7fc16
Show file tree
Hide file tree
Showing 37 changed files with 160 additions and 182 deletions.
36 changes: 0 additions & 36 deletions brave-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,40 +61,4 @@
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>release</id>
<properties>
<!-- The brave jar needs to be Java 1.6 bytecode -->
<main.java.version>1.6</main.java.version>
<main.signature.artifact>java16</main.signature.artifact>
</properties>
<build>
<plugins>
<plugin>
<artifactId>maven-enforcer-plugin</artifactId>
<version>${maven-enforcer-plugin.version}</version>
<executions>
<execution>
<id>enforce-java</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<!-- The only LTS JDK we support that can compile 1.6 bytecode is 11.
https://www.oracle.com/java/technologies/javase/12-relnote-issues.html -->
<requireJavaVersion>
<version>[11,12)</version>
</requireJavaVersion>
</rules>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
10 changes: 5 additions & 5 deletions brave/src/main/java/brave/Tracing.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2020 The OpenZipkin Authors
* Copyright 2013-2023 The OpenZipkin 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
Expand Down Expand Up @@ -50,7 +50,7 @@
* for example via spring or when mocking.
*/
public abstract class Tracing implements Closeable {
static final AtomicReference<Tracing> CURRENT = new AtomicReference<>();
static final AtomicReference<Tracing> CURRENT = new AtomicReference<Tracing>();

public static Builder newBuilder() {
return new Builder();
Expand Down Expand Up @@ -148,7 +148,7 @@ public static final class Builder {
boolean alwaysSampleLocal = false, alwaysReportSpans = false, trackOrphans = false;
Propagation.Factory propagationFactory = B3Propagation.FACTORY;
ErrorParser errorParser = new ErrorParser();
Set<SpanHandler> spanHandlers = new LinkedHashSet<>(); // dupes not ok
Set<SpanHandler> spanHandlers = new LinkedHashSet<SpanHandler>(); // dupes not ok

Builder() {
defaultSpan.localServiceName("unknown");
Expand All @@ -162,7 +162,7 @@ public static final class Builder {
* @since 5.12
*/
public Set<SpanHandler> spanHandlers() {
return Collections.unmodifiableSet(new LinkedHashSet<>(spanHandlers));
return Collections.unmodifiableSet(new LinkedHashSet<SpanHandler>(spanHandlers));
}

/**
Expand Down Expand Up @@ -480,7 +480,7 @@ static final class Default extends Tracing {
defaultSpan.localIp(Platform.get().linkLocalIp());
}

Set<SpanHandler> spanHandlers = new LinkedHashSet<>(builder.spanHandlers);
Set<SpanHandler> spanHandlers = new LinkedHashSet<SpanHandler>(builder.spanHandlers);
// When present, the Zipkin handler is invoked after the user-supplied ones.
if (builder.zipkinSpanReporter != null) {
spanHandlers.add(
Expand Down
22 changes: 11 additions & 11 deletions brave/src/main/java/brave/baggage/BaggagePropagation.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2020 The OpenZipkin Authors
* Copyright 2013-2023 The OpenZipkin 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
Expand Down Expand Up @@ -99,8 +99,8 @@ public static FactoryBuilder newFactoryBuilder(Propagation.Factory delegate) {

public static class FactoryBuilder { // not final to backport ExtraFieldPropagation
final Propagation.Factory delegate;
final List<String> extractKeyNames = new ArrayList<>();
final Set<BaggagePropagationConfig> configs = new LinkedHashSet<>();
final List<String> extractKeyNames = new ArrayList<String>();
final Set<BaggagePropagationConfig> configs = new LinkedHashSet<BaggagePropagationConfig>();

FactoryBuilder(Propagation.Factory delegate) {
if (delegate == null) throw new NullPointerException("delegate == null");
Expand All @@ -115,7 +115,7 @@ public static class FactoryBuilder { // not final to backport ExtraFieldPropagat
* @since 5.11
*/
public Set<BaggagePropagationConfig> configs() {
return Collections.unmodifiableSet(new LinkedHashSet<>(configs));
return Collections.unmodifiableSet(new LinkedHashSet<BaggagePropagationConfig>(configs));
}

/**
Expand Down Expand Up @@ -183,8 +183,8 @@ static final class Factory extends Propagation.Factory implements Propagation<St
// Associate baggage fields with any remote propagation keys
this.configs = factoryBuilder.configs.toArray(new BaggagePropagationConfig[0]);

List<BaggageField> fields = new ArrayList<>();
Set<String> localFieldNames = new LinkedHashSet<>();
List<BaggageField> fields = new ArrayList<BaggageField>();
Set<String> localFieldNames = new LinkedHashSet<String>();
int maxDynamicFields = 0;
for (BaggagePropagationConfig config : factoryBuilder.configs) {
maxDynamicFields += config.maxDynamicFields;
Expand All @@ -199,11 +199,11 @@ static final class Factory extends Propagation.Factory implements Propagation<St
}

@Deprecated @Override public <K1> BaggagePropagation<K1> create(KeyFactory<K1> keyFactory) {
return new BaggagePropagation<>(StringPropagationAdapter.create(get(), keyFactory));
return new BaggagePropagation<K1>(StringPropagationAdapter.create(get(), keyFactory));
}

@Override public BaggagePropagation<String> get() {
return new BaggagePropagation<>(this);
return new BaggagePropagation<String>(this);
}

@Override public TraceContext decorate(TraceContext context) {
Expand All @@ -224,11 +224,11 @@ static final class Factory extends Propagation.Factory implements Propagation<St
}

@Override public <R> Injector<R> injector(Setter<R, String> setter) {
return new BaggageInjector<>(this, setter);
return new BaggageInjector<R>(this, setter);
}

@Override public <R> Extractor<R> extractor(Getter<R, String> getter) {
return new BaggageExtractor<>(this, getter);
return new BaggageExtractor<R>(this, getter);
}
}

Expand Down Expand Up @@ -280,7 +280,7 @@ public static List<String> allKeyNames(Propagation<String> propagation) {
List<String> baggageKeyNames = getAllKeyNames(emptyExtraction);
if (baggageKeyNames.isEmpty()) return propagation.keys();

List<String> result = new ArrayList<>(propagation.keys().size() + baggageKeyNames.size());
List<String> result = new ArrayList<String>(propagation.keys().size() + baggageKeyNames.size());
result.addAll(propagation.keys());
result.addAll(baggageKeyNames);
return Collections.unmodifiableList(result);
Expand Down
11 changes: 7 additions & 4 deletions brave/src/main/java/brave/baggage/BaggagePropagationConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,15 @@ public Builder toBuilder() {
/** @since 5.11 */
public static final class Builder {
final BaggageField field;
List<String> keyNames = new ArrayList<>();
List<String> keyNames = new ArrayList<String>();

Builder(BaggageField field) {
this.field = field;
}

Builder(SingleBaggageField input) {
this.field = input.field;
this.keyNames = new ArrayList<>(input.keyNames());
this.keyNames = new ArrayList<String>(input.keyNames());
}

/**
Expand Down Expand Up @@ -137,8 +137,11 @@ public SingleBaggageField build() {
? BaggageCodec.NOOP
: SingleFieldBaggageCodec.single(builder.field, builder.keyNames), 0);
field = builder.field;
keyNames = builder.keyNames.isEmpty() ? Collections.emptySet()
: Collections.unmodifiableSet(new LinkedHashSet<>(builder.keyNames));
if (builder.keyNames.isEmpty()) {
keyNames = Collections.emptySet();
} else {
keyNames = Collections.<String>unmodifiableSet(new LinkedHashSet<String>(builder.keyNames));
}
}

public BaggageField field() {
Expand Down
9 changes: 5 additions & 4 deletions brave/src/main/java/brave/baggage/CorrelationFlushScope.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2020 The OpenZipkin Authors
* Copyright 2013-2023 The OpenZipkin 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
Expand Down Expand Up @@ -46,7 +46,7 @@ final class CorrelationFlushScope extends AtomicBoolean implements Scope {
* BaggageField#updateValue(String)}.
*/
static void flush(BaggageField field, String value) {
Set<CorrelationContext> syncedContexts = new LinkedHashSet<>();
Set<CorrelationContext> syncedContexts = new LinkedHashSet<CorrelationContext>();
for (Object o : updateScopeStack()) {
CorrelationUpdateScope next = ((CorrelationUpdateScope) o);
String name = next.name(field);
Expand All @@ -66,12 +66,13 @@ static void flush(BaggageField field, String value) {
}
}

static final ThreadLocal<ArrayDeque<Object>> updateScopeStack = new ThreadLocal<>();
static final ThreadLocal<ArrayDeque<Object>> updateScopeStack =
new ThreadLocal<ArrayDeque<Object>>();

static ArrayDeque<Object> updateScopeStack() {
ArrayDeque<Object> stack = updateScopeStack.get();
if (stack == null) {
stack = new ArrayDeque<>();
stack = new ArrayDeque<Object>();
updateScopeStack.set(stack);
}
return stack;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2020 The OpenZipkin Authors
* Copyright 2013-2023 The OpenZipkin 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
Expand Down Expand Up @@ -72,8 +72,8 @@ public abstract class CorrelationScopeDecorator implements ScopeDecorator {
public static abstract class Builder {
final CorrelationContext context;
// Don't allow mixed case of the same name!
final Set<String> allNames = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
final Set<SingleCorrelationField> fields = new LinkedHashSet<>();
final Set<String> allNames = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
final Set<SingleCorrelationField> fields = new LinkedHashSet<SingleCorrelationField>();

/** Internal constructor used by subtypes. */
protected Builder(CorrelationContext context) {
Expand All @@ -91,7 +91,7 @@ protected Builder(CorrelationContext context) {
* @since 5.11
*/
public Set<CorrelationScopeConfig> configs() {
return Collections.unmodifiableSet(new LinkedHashSet<>(fields));
return Collections.unmodifiableSet(new LinkedHashSet<CorrelationScopeConfig>(fields));
}

/**
Expand Down
8 changes: 4 additions & 4 deletions brave/src/main/java/brave/handler/MutableSpan.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2020 The OpenZipkin Authors
* Copyright 2013-2023 The OpenZipkin 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
Expand Down Expand Up @@ -609,7 +609,7 @@ public long annotationTimestampAt(int i) {
// IndexOutOfBoundsException(i) is Java 9+
if (i < 0) throw new IndexOutOfBoundsException("i < 0");
if (i >= annotationCount) throw new IndexOutOfBoundsException("i >= annotationCount");
return (long) annotations[i * 2];
return (Long) annotations[i * 2];
}

/**
Expand Down Expand Up @@ -658,7 +658,7 @@ public Collection<Map.Entry<Long, String>> annotations() {
*/
public <T> void forEachAnnotation(AnnotationConsumer<T> annotationConsumer, T target) {
for (int i = 0, length = annotationCount * 2; i < length; i += 2) {
long timestamp = (long) annotations[i];
long timestamp = (Long) annotations[i];
annotationConsumer.accept(target, timestamp, annotations[i + 1].toString());
}
}
Expand All @@ -682,7 +682,7 @@ public <T> void forEachAnnotation(AnnotationConsumer<T> annotationConsumer, T ta
public void forEachAnnotation(AnnotationUpdater annotationUpdater) {
for (int i = 0, length = annotationCount * 2; i < length; i += 2) {
String value = annotations[i + 1].toString();
String newValue = annotationUpdater.update((long) annotations[i], value);
String newValue = annotationUpdater.update((Long) annotations[i], value);
if (newValue != null) {
update(annotations, i, newValue);
} else {
Expand Down
4 changes: 2 additions & 2 deletions brave/src/main/java/brave/internal/RecyclableBuffers.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2020 The OpenZipkin Authors
* Copyright 2013-2023 The OpenZipkin 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
Expand All @@ -15,7 +15,7 @@

public final class RecyclableBuffers {

private static final ThreadLocal<char[]> PARSE_BUFFER = new ThreadLocal<>();
private static final ThreadLocal<char[]> PARSE_BUFFER = new ThreadLocal<char[]>();

/**
* Returns a {@link ThreadLocal} reused {@code char[]} for use when decoding bytes into an ID hex
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2020 The OpenZipkin Authors
* Copyright 2013-2023 The OpenZipkin 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
Expand Down Expand Up @@ -104,7 +104,7 @@ public <T> Future<T> submit(Runnable task, T result) {
}

<T> Collection<? extends Callable<T>> wrap(Collection<? extends Callable<T>> tasks) {
ArrayList<Callable<T>> result = new ArrayList<>(tasks.size());
ArrayList<Callable<T>> result = new ArrayList<Callable<T>>(tasks.size());
for (Callable<T> task : tasks) {
result.add(wrap(task));
}
Expand Down
4 changes: 2 additions & 2 deletions brave/src/main/java/brave/internal/baggage/BaggageFields.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2020 The OpenZipkin Authors
* Copyright 2013-2023 The OpenZipkin 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
Expand Down Expand Up @@ -88,7 +88,7 @@ Object[] state() {
* #isDynamic()}.
*/
public List<BaggageField> getAllFields() {
return Collections.unmodifiableList(new ArrayList<>(keySet()));
return Collections.unmodifiableList(new ArrayList<BaggageField>(keySet()));
}

/** Returns a read-only view of the non-null baggage field values */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2020 The OpenZipkin Authors
* Copyright 2013-2023 The OpenZipkin 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
Expand Down Expand Up @@ -33,7 +33,7 @@ public static SingleFieldBaggageCodec single(BaggageField field, Collection<Stri

SingleFieldBaggageCodec(BaggageField field, Collection<String> keyNames) {
this.field = field;
this.keyNamesList = Collections.unmodifiableList(new ArrayList<>(keyNames));
this.keyNamesList = Collections.unmodifiableList(new ArrayList<String>(keyNames));
}

@Override public List<String> extractKeyNames() {
Expand Down
8 changes: 4 additions & 4 deletions brave/src/main/java/brave/internal/collect/Lists.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2020 The OpenZipkin Authors
* Copyright 2013-2023 The OpenZipkin 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
Expand All @@ -23,7 +23,7 @@ public final class Lists {
public static <E> List<E> ensureMutable(List<E> list) {
if (list instanceof ArrayList) return list;
int size = list.size();
ArrayList<E> mutable = new ArrayList<>(size);
ArrayList<E> mutable = new ArrayList<E>(size);
for (int i = 0; i < size; i++) {
mutable.add(list.get(i));
}
Expand All @@ -36,12 +36,12 @@ public static <E> List<E> ensureImmutable(List<E> list) {
if (list.size() == 1) return Collections.singletonList(list.get(0));
if (isImmutable(list)) return list;

return Collections.unmodifiableList(new ArrayList<>(list));
return Collections.unmodifiableList(new ArrayList<E>(list));
}

static boolean isImmutable(List<?> extra) {
assert extra.size() > 1; // Handled by caller.
// avoid copying datastructure by trusting certain names.
// avoid copying data structure by trusting certain names.
String simpleName = extra.getClass().getSimpleName();
// We don't need to check EMPTY_LIST or SingletonList here since our only caller handles them
// without type-checking.
Expand Down
Loading

0 comments on commit bc7fc16

Please sign in to comment.