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
This commit is contained in:
Marcin Grzejszczak
2016-07-28 11:04:28 +02:00
committed by GitHub
parent 3707c84043
commit f3cbfd93e1

View File

@@ -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.
* <p>
@@ -142,7 +144,7 @@ public class Span {
private boolean exportable = true;
private final Map<String, String> tags;
private final String processId;
private final List<Log> logs;
private final Collection<Log> 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<String, String> 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<Log> logs() {
return Collections.unmodifiableList(this.logs);
return Collections.unmodifiableList(new ArrayList<>(this.logs));
}
/**