From f3cbfd93e1c2d471723d0e9f1a46483366283ffd Mon Sep 17 00:00:00 2001 From: Marcin Grzejszczak Date: Thu, 28 Jul 2016 11:04:28 +0200 Subject: [PATCH] Returning a copy instead of a view (#356) * Returning a copy instead of a view * Making logs and tags thread-safe fixed #355 * Changes following code review --- .../org/springframework/cloud/sleuth/Span.java | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/Span.java b/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/Span.java index 522493b76..37c41ab94 100644 --- a/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/Span.java +++ b/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/Span.java @@ -26,14 +26,16 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentLinkedQueue; + +import org.springframework.util.Assert; +import org.springframework.util.StringUtils; import com.fasterxml.jackson.annotation.JsonAutoDetect; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonInclude; -import org.springframework.util.Assert; -import org.springframework.util.StringUtils; - /** * Class for gathering and reporting statistics about a block of execution. *

@@ -142,7 +144,7 @@ public class Span { private boolean exportable = true; private final Map tags; private final String processId; - private final List logs; + private final Collection logs; private final Span savedSpan; // Null means we don't know the start tick, so fallback to time @@ -205,8 +207,8 @@ public class Span { this.exportable = exportable; this.processId = processId; this.savedSpan = savedSpan; - this.tags = new LinkedHashMap<>(); - this.logs = new ArrayList<>(); + this.tags = new ConcurrentHashMap<>(); + this.logs = new ConcurrentLinkedQueue<>(); } public static SpanBuilder builder() { @@ -305,7 +307,7 @@ public class Span { * Will never be null. */ public Map tags() { - return Collections.unmodifiableMap(this.tags); + return Collections.unmodifiableMap(new LinkedHashMap<>(this.tags)); } /** @@ -315,7 +317,7 @@ public class Span { * Will never be null. */ public List logs() { - return Collections.unmodifiableList(this.logs); + return Collections.unmodifiableList(new ArrayList<>(this.logs)); } /**